Testing Suite
Relevant source files
The following files were used as context for generating this wiki page:
The Testing Suite in DGL-LifeSci is designed to ensure the reliability and accuracy of graph-based models, data processing utilities, and biological datasets. It encompasses unit tests for dataset loading, molecular analysis verification, and automated linting scripts to maintain code quality across the repository. The suite is integrated into the project's contribution workflow, requiring local tests to pass before any pull request submission.
Sources: CONTRIBUTING.md:27-32, README.md:10-15
Core Testing Components
The testing architecture is divided into specialized modules targeting different layers of the library, from low-level molecule analysis to high-level dataset integration.
Dataset Verification
The suite extensively tests the integrity of built-in datasets by verifying graph construction, featurization, and metadata consistency. Tests ensure that datasets such as Tox21, Alchemy, and PDBBind load correctly and return the expected data structures (SMILES, DGLGraph, labels, and masks).
Sources: tests/data/test_datasets.py:19-120
Molecular Analysis Testing
The analyze_mols utility is validated by comparing calculated molecular descriptors (atom types, bond frequencies, ring counts) against known ground-truth values for specific SMILES strings. This ensures that the RDKit-based featurization and summarization logic remains accurate.
Sources: tests/utils/test_analysis.py:16-43, python/dgllife/utils/analysis.py:84-142
Automated Quality Checks
The suite includes shell scripts for automated linting using pylint. These scripts enforce coding standards across the python/dgllife directory, checking for style consistency and potential programmatic errors.
Sources: tests/scripts/task_lint.sh:1-6
Testing Workflow and Architecture
The following diagram illustrates the lifecycle of a test execution within the DGL-LifeSci environment.
This diagram shows the flow from triggering tests to the validation of specific components and final cleanup of binary artifacts.
Sources: tests/scripts/task_lint.sh:5-6, tests/data/test_datasets.py:12-25, tests/utils/test_analysis.py:8-14
Key Test Categories
Biological and Chemical Dataset Tests
Tests for datasets often involve downloading remote archives, extracting them, and verifying the resulting DGLGraph objects.
| Dataset Test Function | Target Dataset | Verification Criteria |
|---|---|---|
test_tox21 | Tox21 | Label length (4 or 5), Task weights |
test_alchemy | Tencent Alchemy | Node/Edge featurizer loading |
test_pdbbind | PDBBind | Subset (core/refined) loading |
test_esol | ESOL | Data structure length (3 or 11) |
test_jtvae | JTVAE/Junction Tree | Tree size, Vocabulary matching |
Sources: tests/data/test_datasets.py:38-120, tests/data/test_datasets.py:186-224
Molecule Property Analysis
The analysis tests verify the analyze_mols function, which processes collections of molecules to provide statistical summaries.
def test_analyze_mols():
smiles = ['CCO', 'CC1([C@@H](https://github.com/sjiki/dgl-lifesci/blob/HEAD/N2%5BC%40H%5D(S1)[C@@H](https://github.com/sjiki/dgl-lifesci/blob/HEAD/C2%3DO)NC(=O)CC3=CC=CC=C3)C(=O)O)C', '1']
results = analyze_mols(smiles, path_to_export='.')
assert results['num_atoms'] == [3, 23]
assert results['num_valid_mols'] == 2
Sources: tests/utils/test_analysis.py:16-23
Data Flow in Reaction Testing
Reaction prediction tests (e.g., WLN) follow a specific sequence of validating SMILES mapping and bond change identification.
This sequence ensures that the logic for identifying chemical reactivity centers is consistent with the provided atom mapping.
Sources: tests/data/test_datasets.py:133-145
Cleanup and Resource Management
To maintain a clean testing environment, the suite utilizes helper functions to remove temporary files and directories generated during dataset processing (e.g., .bin graph files or extracted archives).
remove_file(fname): Usesos.removeto delete cached DGL graph binaries.remove_dir(dir_name): Usesshutil.rmtreeto clean up extracted dataset folders.
Sources: tests/data/test_datasets.py:12-25, tests/utils/test_analysis.py:8-14
Summary
The DGL-LifeSci Testing Suite provides a robust framework for validating both the data and the logic of the library. By combining linting, chemical descriptor validation, and dataset integrity checks, it ensures that contributions meet the project's quality standards and that the library remains reliable for life science research.