From 4ed730f7ea489e42dc1ce43d5586ed7860da4f7a Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Fri, 10 Jan 2025 16:32:31 +0200 Subject: [PATCH] Fix some py unit tests --- .github/workflows/unittests.yml | 15 --------- tests/conftest.py | 2 +- tests/eko/io/test_metadata.py | 6 ++-- tests/eko/io/test_struct.py | 4 +-- tests/eko/runner/test_legacy.py | 58 --------------------------------- 5 files changed, 6 insertions(+), 79 deletions(-) delete mode 100644 tests/eko/runner/test_legacy.py diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 447f84717..a21b8531e 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -3,22 +3,7 @@ name: Python unit tests on: push jobs: - data: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Get test data - id: cache-test-data - uses: actions/cache@v4 - with: - path: test-data - key: test-data-v1 - - name: Download test data - if: steps.cache-test-data.outputs.cache-hit != 'true' - run: | - ./tests/data/assets.sh test: - needs: data strategy: matrix: python-version: ["3.9", "3.10", "3.11", "3.12"] diff --git a/tests/conftest.py b/tests/conftest.py index 4ff7a8224..8ce700e46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -90,7 +90,7 @@ def _create(self): lx = len(self.operator.xgrid) lpids = len(self.operator.pids) for mu2, op in self._operators( - mugrid=self.operator.evolgrid, shape=(lpids, lx) + mugrid=self.operator.evolgrid, shape=(lpids, lx, lpids, lx) ).items(): self.cache[mu2] = op diff --git a/tests/eko/io/test_metadata.py b/tests/eko/io/test_metadata.py index cdc3308c9..852e1a0be 100644 --- a/tests/eko/io/test_metadata.py +++ b/tests/eko/io/test_metadata.py @@ -12,7 +12,7 @@ def test_metadata(tmp_path, caplog): m.update() assert "no file" in caplog.text with pytest.raises(RuntimeError): - m.path + _ = m.path # now modify m.path = tmp_path m.update() @@ -22,11 +22,11 @@ def test_metadata(tmp_path, caplog): assert p.metadata.is_file() assert "version" in p.metadata.read_text() # change version - m.version = "0.0.0-a1~really1.0.0" + m.version = "0.0.1" m.update() # if I read back the thing should be what I set mn = metadata.Metadata(origin=(1.0, 3), xgrid=[0.1, 1.0]) mm = metadata.Metadata.load(tmp_path) assert m.path == tmp_path assert mm.version != mn.version - assert mm.version == "0.0.0-a1~really1.0.0" + assert mm.version == "0.0.1" diff --git a/tests/eko/io/test_struct.py b/tests/eko/io/test_struct.py index 1370ccdb6..e0c056da1 100644 --- a/tests/eko/io/test_struct.py +++ b/tests/eko/io/test_struct.py @@ -119,7 +119,7 @@ def test_copy(self, eko_factory: EKOFactory, tmp_path: pathlib.Path): mugrid = [(mu, nf)] eko_factory.operator.mugrid = mugrid eko1 = eko_factory.get() - v = np.random.rand(2, 2) + v = np.random.rand(2, 2, 2, 2) opv = struct.Operator(operator=v) eko1[ep] = opv np.testing.assert_allclose(eko1[ep].operator, v) @@ -128,7 +128,7 @@ def test_copy(self, eko_factory: EKOFactory, tmp_path: pathlib.Path): with EKO.edit(p) as eko2: np.testing.assert_allclose(eko1[ep].operator, v) np.testing.assert_allclose(eko2[ep].operator, v) - vv = np.random.rand(2, 2) + vv = np.random.rand(2, 2, 2, 2) opvv = struct.Operator(operator=vv) eko2[ep] = opvv np.testing.assert_allclose(eko1[ep].operator, v) diff --git a/tests/eko/runner/test_legacy.py b/tests/eko/runner/test_legacy.py deleted file mode 100644 index aed8df0ac..000000000 --- a/tests/eko/runner/test_legacy.py +++ /dev/null @@ -1,58 +0,0 @@ -import copy -import enum - -import pytest - -import eko -from eko import EKO -from eko.io.runcards import TheoryCard -from eko.quantities.heavy_quarks import QuarkMassScheme - -from . import check_shapes - - -def test_raw(theory_card, operator_card, tmp_path): - """We don't check the content here, but only the shape.""" - path = tmp_path / "eko.tar" - tc = theory_card - oc = operator_card - r = eko.runner.legacy.Runner(tc, oc, path=path) - r.compute() - with EKO.read(path) as eko_: - check_shapes(eko_, eko_.xgrid, eko_.xgrid, tc, oc) - - -def test_mass_scheme(theory_card, operator_card, tmp_path): - """We don't check the content here, but only the shape.""" - - # wrong mass scheme - class FakeEM(enum.Enum): - BLUB = "blub" - - path = tmp_path / "eko.tar" - theory_card.heavy.masses_scheme = FakeEM.BLUB - with pytest.raises(ValueError, match="BLUB"): - eko.runner.legacy.Runner(theory_card, operator_card, path=path) - # MSbar scheme - theory_card.heavy.masses_scheme = QuarkMassScheme.MSBAR - theory_card.couplings.ref = (91.0, 5) - theory_card.heavy.masses.c.scale = 2 - theory_card.heavy.masses.b.scale = 4.5 - theory_card.heavy.masses.t.scale = 173.07 - r = eko.runner.legacy.Runner(theory_card, operator_card, path=path) - r.compute() - with EKO.read(path) as eko_: - check_shapes(eko_, eko_.xgrid, eko_.xgrid, theory_card, operator_card) - - -def test_vfns(theory_ffns, operator_card, tmp_path): - path = tmp_path / "eko.tar" - tc: TheoryCard = theory_ffns(3) - oc = copy.deepcopy(operator_card) - tc.heavy.matching_ratios.c = 1.0 - tc.heavy.matching_ratios.b = 1.0 - tc.order = (2, 0) - r = eko.runner.legacy.Runner(tc, oc, path=path) - r.compute() - with EKO.read(path) as eko_: - check_shapes(eko_, eko_.xgrid, eko_.xgrid, tc, oc)