# All tests
pytest
# With verbose output
pytest -v
# With coverage
pytest --cov=locale_sync --cov-report=term-missing
# Specific test file
pytest tests/unit/domain/test_models.py
# Specific test class
pytest tests/unit/domain/test_models.py::TestLocaleKey
# Run only integration tests
pytest tests/integration/tests/
├── conftest.py # Shared fixtures
├── unit/
│ ├── domain/
│ │ ├── test_models.py # LocaleKey, LocaleData, result models
│ │ ├── test_comparator.py # Key comparison logic
│ │ ├── test_placeholder.py # Placeholder detection/protection
│ │ └── test_policies.py # Update strategy policies
│ ├── infrastructure/
│ │ ├── test_discovery.py # File discovery
│ │ ├── test_json_parser.py # JSON parsing
│ │ ├── test_json_writer.py # Safe JSON writing
│ │ ├── test_translators.py # Translator implementations
│ │ └── test_reporters.py # Report formatting
│ └── application/
│ ├── test_scan_use_case.py # Scan orchestration
│ ├── test_check_use_case.py # Check orchestration
│ └── test_sync_use_case.py # Sync/translate orchestration
└── integration/
└── test_cli.py # Full CLI command tests
All tests follow GIVEN / WHEN / THEN structure with explicit docstring markers:
def test_detects_missing_keys(self) -> None:
"""GIVEN source with more keys than target"""
source = LocaleData.from_nested_dict({"a": "1", "b": "2"})
target = LocaleData.from_nested_dict({"a": "x"})
"""WHEN finding missing keys"""
missing = comparator.find_missing_keys(source, target)
"""THEN the missing key is detected"""
assert len(missing) == 1
assert missing[0].dotted == "b"The triple-quoted string markers ("""GIVEN ...""", """WHEN ...""", """THEN ...""") make the structure immediately visible when reading test code.
| Category | What's Tested |
|---|---|
| Models | Value object creation, equality, immutability, serialization |
| Comparator | Missing/extra/empty key detection, nested structures |
| Placeholder | Detection, protection, restoration, validation for all patterns |
| Policies | Strategy-specific update decisions |
| Discovery | File finding, auto-discovery, locale code validation, edge cases |
| Parser | Valid/invalid/malformed JSON, nested structures, Unicode |
| Writer | Atomic writes, backups, sorting, indentation, stability |
| Translators | Noop behavior, placeholder wrapping, error handling |
| Reporters | Console and JSON output formatting |
| Use Cases | Full orchestration with real infrastructure |
| CLI | End-to-end command execution via Typer's test runner |
- Use
tmp_path(pytest fixture) for filesystem tests - Use fixtures from
conftest.pyfor common locale data - Mock translators with simple classes implementing the protocol
- Use
typer.testing.CliRunnerfor CLI integration tests