Testing and Code Quality

This section describes how to run the project test suite and perform static code quality checks using mypy, ruff, and pylint.

Running Tests

Run the project tests by executing the following command:

python manage.py test test

Running the full test suite verifies that all existing functionality works as expected after changes.

Running Targeted Tests

The tests are organized into one subfolder per component. To test a specific component, file, class, or method, specify its path:

python manage.py test test.<component>.<file_name>

Examples:

Test one component:

python manage.py test test.rdmc

Test a specific test file:

python manage.py test test.rdmc.test_core

Test a specific test class or method:

python manage.py test test.rdmc_metadata.test_metadata.MetadataTestCase
python manage.py test test.rdmc_metadata.test_metadata.MetadataTestCase.test_get_container_metadata

Running targeted tests allows developers to verify individual components without executing the entire suite.

Docstrings

Every public function, class, and method should include a docstring that describes its purpose, parameters, and return value, following the conventions described in PEP 257:

def my_function(param1: str) -> bool:
   """
   Brief description of what this function does.

   Args:
       param1: Description of the first parameter.

   Returns:
       True if the operation succeeded, False otherwise.
   """

Docstrings improve code readability and enable automatic documentation generation, making the codebase self-documenting.

Typing

Use Python type hints for function parameters and return types to enable static type checking, as described in the official Python typing documentation:

def calculate_total(items: list[float], tax_rate: float) -> float:
   return sum(items) * (1 + tax_rate)

Type hints catch type-related errors early and serve as inline documentation for expected data shapes.

mypy Check

mypy is a static type checker for Python. Run it to verify type correctness across the project:

mypy rdmc

mypy analyzes type annotations to detect type mismatches before runtime, reducing bugs in production.

ruff Check

ruff is a fast Python linter and code formatter. Run it to check for linting issues:

ruff check rdmc

To automatically fix supported linting issues:

ruff check --fix rdmc

ruff enforces consistent code style and identifies potential issues such as unused imports or undefined names.

pylint Check

pylint is a Python source code analyzer that looks for programming errors, helps enforce a coding standard, and sniffs for code smells. Run it to analyze the project code:

pylint rdmc

pylint performs deeper static analysis to find logical errors, code smells, and maintainability issues.

If you have further questions about running tests and the local setup, see the Frequently Asked Questions (FAQ).