Skip to content

Add comprehensive precomputed input pytest coverage#176

Open
MattScicluna wants to merge 1 commit intomainfrom
test/precomputed-pytest-suite
Open

Add comprehensive precomputed input pytest coverage#176
MattScicluna wants to merge 1 commit intomainfrom
test/precomputed-pytest-suite

Conversation

@MattScicluna
Copy link
Contributor

No description provided.

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

Pull Request Test Coverage Report for Build 22677665907

Details

  • 102 of 103 (99.03%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.6%) to 87.504%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Python/test/test_precomputed.py 102 103 99.03%
Totals Coverage Status
Change from base Build 21373206547: 0.6%
Covered Lines: 2437
Relevant Lines: 2785

💛 - Coveralls

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new pytest module to validate PHATE’s handling of precomputed distance/affinity inputs, including alias behavior, sparse inputs, and expected error cases.

Changes:

  • Introduces regression tests for knn_dist="precomputed" vs explicit precomputed_distance / precomputed_affinity.
  • Adds coverage for sparse COO precomputed inputs.
  • Adds error-path tests for invalid matrices and unsupported out-of-sample transforms.
Comments suppressed due to low confidence (7)

Python/test/test_precomputed.py:11

  • Directly mutating sys.path inside tests is brittle and can mask packaging/import issues (e.g., importing the repo checkout instead of the installed distribution). Prefer configuring the test environment via proper packaging (editable install in CI), PYTHONPATH, or conftest.py/pytest configuration so imports resolve naturally.
import sys
import os

# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))

Python/test/test_precomputed.py:46

  • These tests emit a lot of print() output. In pytest suites this adds noise and makes failures harder to scan in CI logs. Prefer relying on assertions alone, or use pytest’s reporting mechanisms (e.g., -vv test names) and only print diagnostic context when asserting/raising (or use caplog/logging if needed).
    print("\n" + "=" * 70)
    print("TEST 1: precomputed alias with random valid distance matrix")
    print("=" * 70)

Python/test/test_precomputed.py:34

  • Setting n_jobs=-1 in unit tests can unnecessarily saturate CI runners and can introduce nondeterminism depending on internal parallel reductions. Consider using n_jobs=1 (or parametrizing) for test stability and predictable runtime.
    return dict(knn=7, t=10, n_jobs=-1, verbose=False, random_state=42)

Python/test/test_precomputed.py:81

  • The tolerance atol=1e-10 is extremely strict for algorithms involving graph construction/eigendecompositions and can lead to flaky tests across BLAS/LAPACK implementations, OSes, or minor dependency changes. Use a more realistic tolerance (e.g., 1e-6/1e-7) and/or add rtol, and consider comparing a more stable invariant if exact embedding coordinates can vary.
    assert np.allclose(
        emb_alias, emb_distance, atol=1e-10
    ), "Alias and explicit distance mode diverged"

Python/test/test_precomputed.py:150

  • The match=... patterns are tightly coupled to exact error-message wording (and could break on minor copy edits). Consider using a more flexible regex (e.g., matching key terms with case-insensitivity) or validating a more stable property (exception type + minimal distinctive substring) to reduce brittleness.
    with pytest.raises(ValueError, match="square matrix"):
        phate.PHATE(knn_dist="precomputed", **create_precomputed_kwargs()).fit_transform(
            D_non_square
        )

Python/test/test_precomputed.py:1

  • For pytest test modules, a shebang and __main__ runner are typically unnecessary and can be undesirable in some test discovery/packaging contexts. It’s cleaner to rely on pytest invocation from the command line/CI and keep test files import-only.
#!/usr/bin/env python

Python/test/test_precomputed.py:198

  • For pytest test modules, a shebang and __main__ runner are typically unnecessary and can be undesirable in some test discovery/packaging contexts. It’s cleaner to rely on pytest invocation from the command line/CI and keep test files import-only.
if __name__ == "__main__":
    pytest.main([__file__, "-v"])

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants