From 2a87b30831655a46256b0e8d208cea976c967827 Mon Sep 17 00:00:00 2001 From: Abhishek Dasgupta Date: Wed, 11 Dec 2024 15:12:01 +0000 Subject: [PATCH 1/3] chore(deps): add pytest-xdist --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 59c6900..86a170c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ dependencies = [ dev = [ "pytest >= 8", "pytest-cov", + "pytest-xdist", "pylint", "pre_commit == 4.0.1" ] From 53175228146b600de2ef282e34c5ed2bc73bff10 Mon Sep 17 00:00:00 2001 From: Abhishek Dasgupta Date: Wed, 11 Dec 2024 15:13:41 +0000 Subject: [PATCH 2/3] fix: add missing function and re-enable l2g testing --- l2gv2/patch/utils.py | 11 +++++++++ tests/test_local2global.py | 46 +++++--------------------------------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/l2gv2/patch/utils.py b/l2gv2/patch/utils.py index a9e524c..41bb1b6 100644 --- a/l2gv2/patch/utils.py +++ b/l2gv2/patch/utils.py @@ -40,6 +40,17 @@ from .patch import Patch +def seed(new_seed): + """ + Change seed of random number generator. + + Args: + new_seed: New seed value + + """ + np.random.default_rng(new_seed) + + def random_gen(new_seed=None) -> np.random.Generator: """Change seed of random number generator. diff --git a/tests/test_local2global.py b/tests/test_local2global.py index 143231c..f08f6bb 100644 --- a/tests/test_local2global.py +++ b/tests/test_local2global.py @@ -3,7 +3,6 @@ # pylint: disable=too-many-positional-arguments """Test local2global reconstruction""" -import os import sys from copy import copy from statistics import mean @@ -80,16 +79,13 @@ def iter_seed(it: int) -> None: it (int): Iteration number used to generate a unique seed. Returns: - None + """ it_seed = np.random.SeedSequence(entropy=_seed.entropy, n_children_spawned=it) ut.seed(it_seed.spawn(1)[0]) -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) +@pytest.mark.xfail(reason="Noisy tests may fail, though many failures are a bad sign") @pytest.mark.parametrize("it", range(100)) @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("patches,min_overlap", zip(patches_list, MIN_OVERLAP)) @@ -114,15 +110,11 @@ def test_stability(it, problem_cls, patches, min_overlap): # ex.add_noise(problem, 1e-8) rotations = ex.rand_rotate_patches(problem) recovered_rots = problem.calc_synchronised_rotations() - error = ut.orthogonal_MSE_error(rotations, recovered_rots) + error = ut.orthogonal_mse_error(rotations, recovered_rots) print(f"Mean error is {error}") assert error < TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("patches,min_overlap", zip(patches_list, MIN_OVERLAP)) def test_calc_synchronised_rotations(problem_cls, patches, min_overlap): @@ -142,15 +134,11 @@ def test_calc_synchronised_rotations(problem_cls, patches, min_overlap): rotations = ex.rand_rotate_patches(problem) ex.rand_shift_patches(problem) recovered_rots = problem.calc_synchronised_rotations() - error = ut.orthogonal_MSE_error(rotations, recovered_rots) + error = ut.orthogonal_mse_error(rotations, recovered_rots) print(f"Mean error is {error}") assert error < TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.xfail(reason="Noisy tests may fail, though many failures are a bad sign") @pytest.mark.parametrize("test_class", test_classes) @pytest.mark.parametrize("noise", NOISE_SCALES) @@ -188,7 +176,7 @@ def test_noisy_calc_synchronised_rotations(noise, test_class, patches, min_overl recovered_rots = problem.calc_synchronised_rotations() problem.rotate_patches(rotations=[r.T for r in recovered_rots]) - error = ut.orthogonal_MSE_error(rotations, recovered_rots) + error = ut.orthogonal_mse_error(rotations, recovered_rots) print(f"Mean rotation error is {error}") print( f"Error of relative rotations is min: {min_err}, mean: {mean_err}, max: {max_err}" @@ -196,10 +184,6 @@ def test_noisy_calc_synchronised_rotations(noise, test_class, patches, min_overl assert error < max(max_err, TOL) -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("patches,min_overlap", zip(patches_list, MIN_OVERLAP)) def test_calc_synchronised_scales(problem_cls, patches, min_overlap): @@ -225,10 +209,6 @@ def test_calc_synchronised_scales(problem_cls, patches, min_overlap): assert error < TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.xfail(reason="Noisy tests may fail, though many failures are a bad sign") @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("noise", NOISE_SCALES) @@ -277,10 +257,6 @@ def test_noisy_calc_synchronised_scales(problem_cls, noise, patches, min_overlap assert error < max_err + TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("patches,min_overlap", zip(patches_list, MIN_OVERLAP)) def test_calc_synchronised_translations(problem_cls, patches, min_overlap): @@ -304,10 +280,6 @@ def test_calc_synchronised_translations(problem_cls, patches, min_overlap): assert error < TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.xfail(reason="Noisy tests may fail, though many failures are a bad sign") @pytest.mark.parametrize("noise", NOISE_SCALES) @pytest.mark.parametrize("patches,min_overlap", zip(patches_list, MIN_OVERLAP)) @@ -333,10 +305,6 @@ def test_noisy_calc_synchronised_translations(noise, patches, min_overlap): assert error < noise + TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize( "patches,min_overlap,points", zip(patches_list, MIN_OVERLAP, points_list) @@ -366,10 +334,6 @@ def test_get_aligned_embedding(problem_cls, patches, min_overlap, points): assert error < TOL -@pytest.mark.skipif( - os.getenv("GITHUB_ACTIONS") == "true", - reason="local2global tests disabled in GitHub Actions", -) @pytest.mark.xfail(reason="Noisy tests may fail, though many failures are a bad sign") @pytest.mark.parametrize("problem_cls", test_classes) @pytest.mark.parametrize("it", range(3)) From c446ab1f2be3022204b699bd4a48f0aefef2a825 Mon Sep 17 00:00:00 2001 From: Abhishek Dasgupta Date: Wed, 11 Dec 2024 15:15:00 +0000 Subject: [PATCH 3/3] ci: use xdist to run tests in parallel, add coverage output --- .github/workflows/tests.yml | 2 +- pyproject.toml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 058bf8e..e51f09f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,4 +28,4 @@ jobs: python3 -m pip install '.[dev]' --find-links https://data.pyg.org/whl/torch-2.4.1%2Bcpu.html - name: Test with pytest run: | - python3 -m pytest --ignore tests/test_local2global.py + python3 -m pytest -n auto diff --git a/pyproject.toml b/pyproject.toml index 86a170c..8b9f438 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,3 +91,6 @@ reportOptionalMemberAccess = false reportOptionalSubscript = false reportGeneralTypeIssues = false reportMissingTypeStubs = false + +[tool.coverage.run] +omit = ["tests/*"]