# 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 the `abacus.core` module. - `tests/prepro/`: Tests for the `abacus.prepro` module. - `tests/sketch/`: Tests for the `abacus.sketch` module. - `tests/diagnostics/`: Tests for the `abacus.diagnostics` module. - `tests/driver/`: Tests for the `abacus.driver` module. Tests typically use the `pytest` framework and may involve mocking dependencies or file system operations. ## Running Tests To run the test suite: 1. Ensure you have installed the development dependencies: ```bash pip install -e .[dev] ``` 2. Navigate to the root directory of the project (`/home/user/Desktop/ABACUS`). 3. Run `pytest`: ```bash pytest tests/ ``` Or, to run tests with verbose output: ```bash 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 in `abacus/`. - **Naming**: Test files should be named `test_*.py`, and test functions should be named `test_*`. - **Framework**: Use `pytest` conventions. Simple `assert` statements 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 `pytest` fixtures (`@pytest.fixture`) for setting up reusable test data or objects. See `tests/conftest.py` for 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. 1. Ensure `pytest-cov` is installed (it should be included in the development dependencies): ```bash pip install pytest-cov # Or confirm via: pip install -e .[dev] ``` 2. Run `pytest` with the `--cov` flag, specifying the `abacus` package: ```bash pytest --cov=abacus tests/ ``` 3. This will output a coverage summary to the console. For a more detailed HTML report: ```bash 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.)*