From 05924ccf5a310db04d2bcbb463687b1c50bbee81 Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:34:33 +0000 Subject: [PATCH 01/10] Don't omit dcor/tests from pytest --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2327f5b..51982a1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: - name: Run tests run: | pip3 install ".[test]" - coverage run --source=dcor/ --omit=dcor/tests/ -m pytest + coverage run --source=dcor/ -m pytest - name: Generate coverage XML run: | From 528567ef35fdf4cacccbb3aa421e605e58fbdfc8 Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:47:50 +0000 Subject: [PATCH 02/10] Revert "Don't omit dcor/tests from pytest" This reverts commit 05924ccf5a310db04d2bcbb463687b1c50bbee81. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51982a1..2327f5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: - name: Run tests run: | pip3 install ".[test]" - coverage run --source=dcor/ -m pytest + coverage run --source=dcor/ --omit=dcor/tests/ -m pytest - name: Generate coverage XML run: | From 929b90e341b4cdb028f49ba6c47f7895dfd5c8ef Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 10:37:26 +0000 Subject: [PATCH 03/10] Relax numpy < 2 pin in testing deps --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 84e10e7..e9d2c0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ docs = [ ] test = [ "array-api-strict", - "numpy<2", # NumPy 2 changes array repr, affecting doctests. + "numpy", "pytest", "pytest-cov", "pytest-subtests", @@ -78,4 +78,4 @@ build-backend = "setuptools.build_meta" include = ["dcor*"] [tool.setuptools.dynamic] -version = {attr = "dcor.__version__"} \ No newline at end of file +version = {attr = "dcor.__version__"} From d1b771b6f1407fefa1dbde79b666561fc4a8b0fd Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 10:38:03 +0000 Subject: [PATCH 04/10] Try to skip doctests --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2327f5b..097d1d6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: - name: Run tests run: | pip3 install ".[test]" - coverage run --source=dcor/ --omit=dcor/tests/ -m pytest + coverage run --source=dcor/ --omit=dcor/tests/ -m pytest --doctest-glob="" - name: Generate coverage XML run: | From d6de854913d9aebdfa18a99a588e3aea046f590f Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:12:12 +0000 Subject: [PATCH 05/10] Update conftest.py --- conftest.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/conftest.py b/conftest.py index 3cf9d22..3a65e2b 100644 --- a/conftest.py +++ b/conftest.py @@ -1,13 +1,39 @@ + +import doctest + collect_ignore = ['setup.py'] pytest_plugins = ("pytest_cov", "subtests") +doctest_normal_output_checker = doctest.OutputChecker + +class Numpy1Numpy2AgnosticOutputChecker(doctest.OutputChecker): + + + def numpy_doctest_output_fix(self, want, got, optionflags): + if want == got: + return True + if want == f'np.float64({got})': + return True + + + + return False + + + def pytest_configure(config): import sys sys._called_from_test = True + doctest.OutputChecker = Numpy1Numpy2AgnosticOutputChecker + def pytest_unconfigure(config): import sys del sys._called_from_test + doctest.OutputChecker = doctest_normal_output_checker + + + From 3681832f7f29de1ee6cf4425d549ad8197ff8b90 Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:37:52 +0000 Subject: [PATCH 06/10] Update conftest.py --- conftest.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/conftest.py b/conftest.py index 3a65e2b..82e8f30 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,4 @@ - +import re import doctest collect_ignore = ['setup.py'] @@ -6,20 +6,24 @@ pytest_plugins = ("pytest_cov", "subtests") -doctest_normal_output_checker = doctest.OutputChecker +OutputChecker = doctest.OutputChecker -class Numpy1Numpy2AgnosticOutputChecker(doctest.OutputChecker): - def numpy_doctest_output_fix(self, want, got, optionflags): - if want == got: - return True - if want == f'np.float64({got})': - return True +class Numpy1Numpy2AgnosticOutputChecker(doctest.OutputChecker): + + numpy2_float64_pattern = r'np\.float64\((?Pinf|[+-]?\d*\.\d+)\)' + + def check_output(self, want, got, optionflags): + numpy_1_style_got = re.sub( + self.numpy2_float64_pattern, + lambda m: m['num'], + got, + ) + return super().check_output(want, numpy_1_style_got, optionflags) - return False @@ -33,7 +37,7 @@ def pytest_configure(config): def pytest_unconfigure(config): import sys del sys._called_from_test - doctest.OutputChecker = doctest_normal_output_checker + doctest.OutputChecker = OutputChecker From 2b122d35df9e25cd96d71b93635491f7bfdc55ae Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:38:56 +0000 Subject: [PATCH 07/10] Test on 3.13 too --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 097d1d6..ceda137 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.10', '3.11', '3.12'] + python-version: ['3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v2 From c5c0b8947d637bf03a253f91fedcf18d7294af7d Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 12:13:02 +0000 Subject: [PATCH 08/10] Disable type checking on conftest.py (it dynamically patches the core library, so will never statically type check) --- conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conftest.py b/conftest.py index 82e8f30..5fe7715 100644 --- a/conftest.py +++ b/conftest.py @@ -1,3 +1,4 @@ +# type: ignore import re import doctest From 021fc4d457fc19206bcfef2f7cda5dc5ada5002e Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:04:37 +0000 Subject: [PATCH 09/10] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ceda137..5d63911 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: - name: Run tests run: | pip3 install ".[test]" - coverage run --source=dcor/ --omit=dcor/tests/ -m pytest --doctest-glob="" + coverage run --source=dcor/ --omit=dcor/tests/ -m pytest - name: Generate coverage XML run: | From a73e8a2a355ca1b81bdc01c63dba5bbaafd3a10e Mon Sep 17 00:00:00 2001 From: JamesParrott <80779630+JamesParrott@users.noreply.github.com> Date: Sat, 1 Feb 2025 09:58:01 +0000 Subject: [PATCH 10/10] Convert docstring repr expected and actual to numpy 1 style repr --- conftest.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/conftest.py b/conftest.py index 5fe7715..dcbc835 100644 --- a/conftest.py +++ b/conftest.py @@ -10,20 +10,24 @@ OutputChecker = doctest.OutputChecker +numpy2_float64_pattern = r'np\.float64\((?Pinf|[+-]?\d*\.\d+)\)' + +def ensure_numpy_1_style_repr(repr_: str)-> str: + return re.sub( + numpy2_float64_pattern, + lambda m: m['num'], + repr_, + ) + class Numpy1Numpy2AgnosticOutputChecker(doctest.OutputChecker): - numpy2_float64_pattern = r'np\.float64\((?Pinf|[+-]?\d*\.\d+)\)' - def check_output(self, want, got, optionflags): - numpy_1_style_got = re.sub( - self.numpy2_float64_pattern, - lambda m: m['num'], - got, - ) + numpy_1_style_want = ensure_numpy_1_style_repr(want) + numpy_1_style_got = ensure_numpy_1_style_repr(got) - return super().check_output(want, numpy_1_style_got, optionflags) + return super().check_output(numpy_1_style_want, numpy_1_style_got, optionflags)