Testing¶
This section provides information about the test suite for the Abacus library, including how to run tests and understand their structure.
Test Structure¶
The test suite is located in the tests/ directory at the root of the project. Tests are organised into subdirectories that mirror the structure of the abacus/ package:
tests/core/: Tests for theabacus.coremodule.tests/prepro/: Tests for theabacus.prepromodule.tests/sketch/: Tests for theabacus.sketchmodule.tests/diagnostics/: Tests for theabacus.diagnosticsmodule.tests/driver/: Tests for theabacus.drivermodule.
Tests typically use the pytest framework and may involve mocking dependencies or file system operations.
Running Tests¶
To run the test suite:
Ensure you have installed the development dependencies:
pip install -e .[dev]
Navigate to the root directory of the project (
/home/user/Desktop/ABACUS).Run
pytest:pytest tests/Or, to run tests with verbose output:
pytest -v tests/
Writing Tests¶
When contributing new tests, please adhere to the following general guidelines:
Location: Place test files in the appropriate subdirectory within
tests/that mirrors the location of the module being tested inabacus/.Naming: Test files should be named
test_*.py, and test functions should be namedtest_*.Framework: Use
pytestconventions. Simpleassertstatements are often sufficient.Mocking: Use
unittest.mock.patch(often as a decorator or context manager) to isolate the unit under test from its dependencies (e.g., file system operations, external libraries, other Abacus modules). Pay close attention to the correct patch target path based on where the dependency is imported in the module under test.Fixtures: Use
pytestfixtures (@pytest.fixture) for setting up reusable test data or objects. Seetests/conftest.pyfor potential shared fixtures.Clarity: Write clear and concise tests that focus on a single piece of functionality or behaviour.
(More specific conventions may be established as the test suite evolves.)
Test Coverage¶
To measure test coverage, you can use the pytest-cov plugin.
Ensure
pytest-covis installed (it should be included in the development dependencies):pip install pytest-cov # Or confirm via: pip install -e .[dev]
Run
pytestwith the--covflag, specifying theabacuspackage:pytest --cov=abacus tests/
This will output a coverage summary to the console. For a more detailed HTML report:
pytest --cov=abacus --cov-report=html tests/
This will generate an
htmlcov/directory containing an interactive report that you can open in your browser (htmlcov/index.html).
(The target coverage percentage and policies for handling uncovered code may be defined later.)