Files
code-privacy-shield/tests/test_config.py
7000pctAUTO e4f31373b4
Some checks failed
CI / test (push) Has been cancelled
Initial upload: Code Privacy Shield v0.1.0
2026-02-02 20:51:00 +00:00

119 lines
3.7 KiB
Python

import pytest
from pathlib import Path
import tempfile
import os
from code_privacy_shield.config import Config
class TestConfig:
def test_default_config_exists(self):
config = Config()
assert config.config is not None
assert "general" in config.config
assert "redaction" in config.config
def test_get_redaction_categories(self):
config = Config()
categories = config.get_redaction_categories()
assert "api_keys" in categories
assert "pii" in categories
def test_get_exclude_patterns(self):
config = Config()
patterns = config.get_exclude_patterns()
assert isinstance(patterns, list)
assert "*.pyc" in patterns
def test_get_custom_patterns(self):
config = Config()
patterns = config.get_custom_patterns()
assert isinstance(patterns, list)
def test_is_category_enabled(self):
config = Config()
assert config.is_category_enabled("api_keys")
assert config.is_category_enabled("nonexistent") # Defaults to True
def test_is_preview_mode(self):
config = Config()
config.reset_to_default()
assert not config.is_preview_mode()
def test_get_with_dot_notation(self):
config = Config()
config.reset_to_default()
value = config.get("general.preview_mode")
assert value is False
def test_reset_to_default(self):
config = Config()
config.set("general.preview_mode", True)
config.reset_to_default()
config2 = Config()
config2.reset_to_default()
assert not config2.is_preview_mode()
config.set("general.preview_mode", True)
assert config.is_preview_mode()
def test_is_quiet_mode(self):
config = Config()
assert not config.is_quiet_mode()
config.set("general.quiet_mode", True)
assert config.is_quiet_mode()
def test_should_preserve_structure(self):
config = Config()
assert config.should_preserve_structure()
def test_should_recursive(self):
config = Config()
assert config.should_recursive()
def test_get_output_format(self):
config = Config()
assert config.get_output_format() == "text"
def test_get_with_dot_notation(self):
config = Config()
config.reset_to_default()
value = config.get("general.preview_mode")
assert value is False
def test_reset_to_default(self):
config = Config()
config.set("general.preview_mode", True)
config.reset_to_default()
assert not config.is_preview_mode()
def test_save_config(self, tmp_path):
config = Config()
config.set("test.value", "test_data")
save_path = tmp_path / "saved.toml"
saved = config.save(str(save_path))
assert saved
assert save_path.exists()
def test_merge_configs(self):
config = Config()
config._merge_config(config.config, {"new_section": {"key": "value"}})
assert config.get("new_section.key") == "value"
def test_get_project_config_path(self):
path = Config.get_project_config_path()
assert path == Path(".cps.toml")
def test_get_default_config_path(self):
path = Config.get_default_config_path()
assert ".config" in str(path)
assert "cps" in str(path)
def test_create_example_config(self, tmp_path):
example_path = tmp_path / "example.toml"
created = Config.create_example_config(str(example_path))
assert created
assert example_path.exists()
content = example_path.read_text()
assert "general" in content
assert "redaction" in content