Testing Framework & Strategy
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The testing framework for the flext-target-ldif project is built upon pytest, leveraging a modular architecture to validate Singer-compatible LDIF target operations. The strategy prioritizes unit testing of core components—specifically settings validation and the LDIF writer mechanism—while ensuring compliance with the FLEXT ecosystem's engineering laws regarding root cause analysis and zero-debt code.
The scope of testing covers configuration immutability, schema validation, Distinguished Name (DN) generation, and LDIF format compliance, including base64 encoding and line-wrapping rules. The framework utilizes pytest markers to categorize tests into units, integration, and performance, ensuring a high-quality gate for the LDIF export functionality.
Sources: pyproject.toml:442-454, AGENTS.md:16-30, tests/unit/test_target.py:12-25
Test Configuration & Infrastructure
The project utilizes pyproject.toml as the central configuration for the testing environment. It defines mandatory coverage thresholds, execution environments, and a robust list of development dependencies required for static analysis and dynamic testing.
Test Environment Layout
The test suite is organized into unit tests that map directly to the source modules. Lazy loading is implemented in tests/__init__.py to optimize import times and prevent circular dependencies during test collection.
The diagram above illustrates the logical breakdown of the testing suite into specific component validation areas.
Sources: tests/init.py:42-75, pyproject.toml:455-458
Key Quality Gates
The testing strategy enforces several automated quality gates defined in the project configuration:
| Category | Tool | Requirement / Threshold |
|---|---|---|
| Unit Testing | pytest | Coverage >= 20% (strictly enforced) |
| Linting | ruff | Zero violations (select: ALL) |
| Type Checking | mypy / pyright | Strict mode; no Any or object |
| Security | bandit | Scan for common vulnerabilities |
| Dependency | deptry | Validation of unused/missing dependencies |
| Sources: pyproject.toml:139-141, pyproject.toml:474-486, AGENTS.md:95-99 |
Testing Components
Settings & Configuration Testing
Tests in tests/unit/test_target.py validate the FlextTargetLdifSettings class, ensuring that the target configuration is immutable and that domain-specific rules are strictly followed.
- Default Values: Verification that
line_lengthdefaults to 78 andschema_validationis enabled by default. - Immutability: Confirmation that attempting to modify a frozen Pydantic model raises a
ValidationError. - Domain Rules: Validation of constraints such as non-empty
output_fileand validdn_template.
Sources: tests/unit/test_target.py:28-100, src/flext_target_ldif/settings.py:18-30
Writer Mechanism Testing
The FlextTargetLdifWriter is tested for its ability to transform Singer records into RFC-compliant LDIF entries. This includes complex logic for base64 encoding of non-ASCII characters or values starting with unsafe characters (space, colon, etc.).
The sequence shows the lifecycle of the writer during a unit test, from opening the handle to verifying the final file content.
Sources: tests/unit/test_writer.py:133-160, src/flext_target_ldif/writer.py:100-115
Mocking and Isolation Strategy
The framework extensively uses unittest.mock to isolate components from side effects:
- File I/O:
patch("pathlib.Path.open")is used to simulate file system failures and verify error handling in theclose()method. - CLI Verification: The
@patch("flext_target_ldif.target.FlextTargetLdif.__init__")decorator verifies that the target initialization correctly chains to parent classes without requiring full configuration.
Sources: tests/unit/test_target.py:105-115, tests/unit/test_writer.py:117-130
Testing Lifecycle (Universal Agent Law)
The project adheres to the "Zero-Tolerance / Strict-Total" engineering law. A test failure is considered a blocker for all related work, and developers (or AI agents) must fix the root cause immediately rather than using stubs or TODO flags.
- Zero Dead Code: Tests must ensure that superseded code is removed.
- Fix-Forward: Reverting shared work is forbidden; tests must validate the current state and move it toward the fix.
- Strict Typing: Type errors surfaced during testing or linting must be fixed at the source, not suppressed with
# type: ignore.
Sources: AGENTS.md:17-48
Summary
The testing strategy for flext-target-ldif provides a robust safety net by combining strict configuration validation, detailed writer formatting checks, and mandatory static analysis gates. By enforcing a "Root Cause Only" policy, the framework ensures that every test passing contributes to a stable and predictable LDIF export tool within the Singer ecosystem.
Sources: AGENTS.md:49-55, tests/unit/test_target.py:270-285