Constants & Data Cases
Relevant source files
The following files were used as context for generating this wiki page:
- src/flext_tests/_constants/data_cases.py
- src/flext_tests/_constants/files.py
- src/flext_tests/_constants/_validator_parts/validator_part_01.py
- src/flext_tests/_constants/_validator_parts/validator_part_02.py
- src/flext_tests/_models/_filesystem_parts/filesystem_part_01.py
- src/flext_tests/_models/_filesystem_parts/filesystem_part_02.py
Constants and Data Cases within flext-tests provide the foundation for standardized testing, filesystem operations, and architectural validation across the FLEXT ecosystem. This module centralizes reusable test data for parametrized testing, file format definitions, and violation rules for the system's static analysis validators.
By centralizing these definitions, the project ensures consistency in how files are handled, how identifiers are normalized, and how architectural constraints (such as layer hierarchies and typing rules) are enforced.
Reusable Data Cases
The system provides FlextTestsConstantsDataCases to support data-driven testing. These cases include tuples for normalization checks and validation logic for strings and identifiers.
Standard Test Case Collections
- App ID Normalization: Used to verify that raw application identifiers are correctly normalized to lowercase without hyphens (e.g., "Flext-App" to "flextapp").
- Safe String Validation: Defines valid patterns for identifiers (alphanumeric and underscores) and explicit invalid cases (empty strings, numeric prefixes, or special characters).
Filesystem Management Constants
File operations in the test infrastructure rely on a set of enums and static mappings defined in FlextTestsConstantsFiles. These constants manage everything from supported formats to permission bits and error messages.
File Formats and Extensions
The system maps common file extensions to specific internal formats to facilitate auto-detection during file creation and reading.
| Extension | Format | Description |
|---|---|---|
| .txt, .log, .md | text | Standard text files |
| .bin, .dat | bin | Binary data |
| .json | json | JSON structured data |
| .yaml, .yml | yaml | YAML structured data |
| .csv, .tsv | csv | Delimited data |
Sources: src/flext_tests/_constants/files.py:46-59
Operational Constants
- Permissions: Defines standard Unix-style bits for read-only files (
292), writable files (420), and writable directories (493). - Embellishments: Includes human-readable size units (B to PB) and a threshold of
1024for unit conversion. - Encoding: Defaults to a project-standard encoding with specific support for "binary".
Sources: src/flext_tests/_constants/files.py:61-75
Architecture Validator Constants
The validator system uses a two-part constant structure (validator_part_01 and part_02) to define the rules, severities, and regular expressions used to scan source code and markdown for violations.
Rule Definitions and Severities
Violations are categorized by severity levels: CRITICAL, HIGH, MEDIUM, and LOW. These rules cover multiple domains:
- Imports: Detects lazy imports,
sys.pathmanipulation, and non-root imports from flext packages. - Typing: Flags wildcard types (
Any), legacy annotations (e.g.,Optional,Union), and forbiddenobjectannotations. - Testing: Identifies usage of
monkeypatch,Mock, or@patchdecorators which may violate architecture guidelines. - Layers: Enforces the hierarchy where lower layers are forbidden from importing upper layers (
LAYER-001).
Sources: src/flext_tests/_constants/_validator_parts/validator_part_01.py:17-106
Regex and Message Constants
Part 02 defines the specific RegexPattern objects used to identify these violations in code and the message templates used for reporting.
Data Models for Filesystem Operations
The FlextTestsFilesystemModelsMixin provides the schema for interacting with the filesystem during tests. These models define the parameters for creation, reading, and metadata extraction.
File Information (FileInfo)
The FileInfo model tracks the state and metadata of a file.
| Field | Type | Description |
|---|---|---|
exists | bool | Whether the file exists on disk. |
size | int | File size in bytes. |
encoding | str | Detected or assumed text encoding. |
sha256 | str | None | Hex-encoded digest for integrity checks. |
content_meta | ContentMeta | Parsed metadata for structured files (JSON/YAML/CSV). |
Sources: src/flext_tests/_models/_filesystem_parts/filesystem_part_01.py:20-56
Operation Parameters
Specific models govern the inputs for filesystem actions:
- CreateParams: Requires
contentandname, with optional overrides forfmt,enc,indent, anddelim. - CompareParams: Configures file comparisons with modes for
CONTENT,SIZE,HASH, orLINES. Includes options to ignore whitespace or case. - InfoParams: Controls the depth of metadata extraction, including whether to compute hashes or validate against a specific Pydantic model.
Sources: src/flext_tests/_models/_filesystem_parts/filesystem_part_02.py:22-130
Summary
Constants & Data Cases serve as the configuration backbone for the flext-tests library. By standardizing file formats, regex patterns for validation, and reusable test scenarios, the module enables a robust and consistent testing infrastructure that enforces architectural integrity while simplifying filesystem manipulations.