Test Fixtures & Base Classes
Relevant source files
The following files were used as context for generating this wiki page:
The flext-tap-ldif test suite is built on a modular architecture that extends the core flext_tests framework through composition and specific Mixin patterns. It provides a standardized environment for validating Singer Tap behavior, LDIF file parsing, and data integrity.
This system ensures technical consistency by enforcing a unified namespace pattern (e.g., u.TapLdif.*, m.TapLdif.*) and utilizing runtime bootstrapping for typed settings. The primary goal is to provide developers with a robust set of protocols, models, and base services to write behavior contracts for the LDIF extraction logic.
Sources: tests/base.py:10-15, tests/protocols.py:20-30, tests/utilities.py:1-10
Service Architecture & Base Classes
The testing infrastructure relies on a central service base class that facilitates runtime bootstrapping and global settings management.
TestsFlextTapLdifServiceBase
The TestsFlextTapLdifServiceBase class serves as the foundation for all service-level tests. It inherits from the core flext_tests service base and overrides key methods to inject project-specific configurations. It primarily manages the lifecycle of TestsFlextTapLdifSettings and ensures the runtime environment is correctly initialized before tests execute.
Sources: tests/base.py:16-30
The diagram above illustrates the inheritance from the core test service and the dependency on typed settings.
Sources: tests/base.py:16-25
Test Protocols & Interfaces
The project uses PEP 544 Protocols to define structural subtyping for test components, specifically for mocking LDIF file operations and validating data providers.
Namespace Organization
Test protocols are organized into a tiered namespace to avoid naming collisions and maintain clarity:
- Tests: Generic project-specific test protocols.
- TapLdif: Domain-specific protocols for LDIF extraction testing.
| Protocol Class | Purpose | Key Methods |
|---|---|---|
MockLdifFile | Interfaces for simulated file operations. | open_file, read_entries |
TestLdifDataProvider | Standardizes how test data (LDIF content) is provided to tests. | test_entries, test_file_content |
TestLdifAssertion | Provides specialized assertions for LDIF-specific logic. | assert_ldif_file_parsed, assert_ldif_entries_valid |
Sources: tests/protocols.py:20-100
Domain Models & Type Definitions
Testing requires specialized data structures to represent mock LDIF entries and validation results. These are implemented as extensions of the main project models.
Mock Data Structures
The system defines complex types for mocking LDAP/LDIF data, allowing for nested attribute mappings and sequence-based file representations.
Sources: tests/typings.py:35-50
# From tests/typings.py
class TapLdifTest:
type MockLdifEntry = t.MappingKV[
str,
str | t.MappingKV[str, FlextTestsTypes.StrSequence],
]
type MockLdifFile = t.SequenceOf[MockLdifEntry]
Sources: tests/typings.py:37-47
Test Models Logic
The TestsFlextTapLdifModels class combines core test models with tap-specific extensions. It follows a composition pattern where project-specific test models reside under the m.TapLdif.Tests namespace.
Sources: tests/models.py:18-30
Implementation of Behavior Contracts
Behavior contracts define the expected public API surface and functional outcomes of the Tap.
Stream Discovery Validation
The TestsFlextTapLdifTap class validates that the FlextTapLdif class correctly discovers streams from provided configuration.
This sequence ensures that the Tap can find and identify the primary LDIF entry stream when pointing to a valid file path.
Sources: tests/unit/test_tap.py:15-25
Test Utilities & Extensions
Test utilities are accessed via the u singleton, which merges standard project utilities with test-only helpers.
Namespace Pattern
u.TapLdif: Standard tap utilities.u.TapLdif.Tests: Utilities designed exclusively for the test suite.
This structure allows for a "discoverable" API within IDEs while keeping the production utility footprint clean.
Sources: tests/utilities.py:15-28
Summary
The Test Fixtures & Base Classes module provides a strictly typed and namespaced environment for LDIF extraction testing. By leveraging TestsFlextTapLdifServiceBase for initialization and TestsFlextTapLdifProtocols for mocking, the suite ensures that all extraction scenarios—from file discovery to entry parsing—are validated against a consistent behavior contract. This modular approach allows the project to scale its test coverage without compromising the integrity of the core extraction logic.