Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The Testing Strategy for the Duplicate Code Detection Tool encompasses a multi-layered approach designed to ensure technical accuracy in code similarity analysis, maintain cross-version Python compatibility (3.8 through 3.13), and validate integration within CI/CD pipelines. The strategy relies on automated unit testing, coverage reporting, static type checking, and practical integration examples that simulate real-world usage in Flext projects.
Sources: pyproject.toml:23-32, README.md:10-15, examples/flext_integration_example.py:7-10
Automated Testing Framework
The project utilizes pytest as its primary testing framework, supplemented by several plugins and tools to maintain high code quality standards. The configuration for these tools is centralized in the project's configuration files.
Test Configuration and Execution
Tests are organized within a tests/ directory. The execution environment is configured to prioritize strictness in markers and configurations to prevent silent failures.
| Tool | Purpose | Configuration Location |
|---|---|---|
pytest | Primary test runner and framework | pyproject.toml:104-109 |
pytest-cov | Measures and reports code coverage | pyproject.toml:53 |
black | Ensures consistent code formatting | pyproject.toml:70-87 |
isort | Manages and validates import ordering | pyproject.toml:89-93 |
mypy | Performs static type analysis and checking | pyproject.toml:95-102 |
Sources: pyproject.toml:53-61, pyproject.toml:104-109
Coverage Analysis
The testing strategy includes mandatory coverage reporting. The configuration explicitly omits test files and virtual environments from coverage metrics to ensure the reported data accurately reflects the core library's health.
[tool.coverage.run]
source = ["duplicate_code_tool"]
omit = ["*/tests/*", "*/test_*", "*/__pycache__/*", "*/venv/*", "*/env/*"]
Sources: pyproject.toml:111-113
Integration and Functional Testing
Beyond unit tests, the strategy includes functional validation through integration examples. These examples demonstrate how the DuplicateCodeDetector and its associated components behave when processing directory structures and file clusters.
Component Relationship
The following diagram illustrates the relationship between core components that are subject to testing, showing how high-level library classes interact with the underlying detection engine.
The diagram shows the hierarchy of data structures returned during an analysis run, which are key targets for assertion in the testing suite.
Sources: core.py:22-115, core.py:118-245
Validation Scenarios
The testing strategy covers several distinct operational modes:
- Directory Analysis: Validating recursive file discovery and similarity comparison across multiple paths.
- File Analysis: Testing specific file comparisons while respecting exclusion lists.
- Threshold Enforcement: Verifying that the tool correctly triggers
ReturnCode.THRESHOLD_EXCEEDEDwhen similarities surpass thefail_threshold. - Source Transformation: Testing the
remove_comments_and_docstringsfunction to ensure AST-based cleaning does not corrupt the code logic before analysis.
Sources: duplicate_code_detection.py:24-30, duplicate_code_detection.py:68-100, examples/flext_integration_example.py:20-50
CI/CD Pipeline Testing
The strategy extends to GitHub Actions integration, where the tool is tested as a Docker-based action. This involves validating the communication between the Python runner and the GitHub API.
This flow represents the automated integration test path for the GitHub Action component.
Sources: run_action.py:126-150, run_action.py:175-210, action.yml:1-68
Environment and Version Testing
Testing is performed against a matrix of Python versions. The pyproject.toml and setup.py files define the supported environments that must be validated:
- Python 3.8 through 3.13
- Operating System: OS Independent
- Dependency versions:
gensim>=4.0.0,nltk>=3.8,numpy>=1.21.0
Sources: pyproject.toml:23-32, setup.py:25-35
Conclusion
The testing strategy for the Duplicate Code Detection Tool combines rigorous static analysis with dynamic execution tests. By utilizing pytest for unit logic and providing comprehensive integration examples, the project ensures that code similarity detection remains accurate across various programming languages and deployment environments, particularly within the Flext ecosystem.