From 90461c946ff00eb78d4f2615e1a03bc1e7026c38 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 20 Feb 2024 19:29:30 +0300 Subject: [PATCH 01/10] MAINT: plugin: run tests in a tempdir, stop blank filtering DeprecationWarnings --- scpdt/plugin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scpdt/plugin.py b/scpdt/plugin.py index bdd0994..7ab7433 100644 --- a/scpdt/plugin.py +++ b/scpdt/plugin.py @@ -13,10 +13,11 @@ from scpdt.impl import DTChecker, DTParser, DebugDTRunner from scpdt.conftest import dt_config -from scpdt.util import np_errstate, matplotlib_make_nongui +from scpdt.util import np_errstate, matplotlib_make_nongui, temp_cwd from scpdt.frontend import find_doctests +# XXX: unused global? copied_files = [] @@ -107,6 +108,7 @@ def pytest_collection_modifyitems(config, items): items[:] = unique_items +# XXX: unused? def copy_local_files(local_resources, destination_dir): """ Copy necessary local files for doctests to the current working directory. @@ -254,10 +256,14 @@ def run(self, test, compileflags=None, out=None, clear_globs=False): *unless* the `mpl()` context mgr has a chance to filter them out *before* they become errors in `config.user_context_mgr()`. """ + dt_config = config.dt_config + with np_errstate(): - with config.dt_config.user_context_mgr(test): + with dt_config.user_context_mgr(test): with matplotlib_make_nongui(): - super().run(test, compileflags=compileflags, out=out, clear_globs=clear_globs) + # XXX: local_resourses needed? they seem to be, w/o pytest + with temp_cwd(test, dt_config.local_resources): + super().run(test, compileflags=compileflags, out=out, clear_globs=clear_globs) """ Almost verbatim copy of `_pytest.doctest.PytestDoctestRunner` except we utilize From 917d2da312f989b06c0dba50a8bd64b69ff2dcc7 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 20 Feb 2024 23:13:27 +0300 Subject: [PATCH 02/10] DEBUG: check the folder contents --- .github/workflows/pip.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index 0da483c..acf3244 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -68,6 +68,7 @@ jobs: - name: Test pytest plugin # This test will fail in a venv where scpdt has not been installed and the plugin has not been activated run: | + ls -l /home/runner/work/scpdt/scpdt/scpdt/tests/scpdt/tests/ test_files=("scpdt/tests/module_cases.py" "scpdt/tests/stopwords_cases.py" "scpdt/tests/local_file_cases.py") for file in "${test_files[@]}"; do python -m pytest "${file}" --doctest-modules From 22c876c3c9d36a9b6004aaf44de26b078e790d6f Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 20 Feb 2024 23:15:44 +0300 Subject: [PATCH 03/10] more CI debug --- .github/workflows/pip.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pip.yml b/.github/workflows/pip.yml index acf3244..55852ed 100644 --- a/.github/workflows/pip.yml +++ b/.github/workflows/pip.yml @@ -68,7 +68,9 @@ jobs: - name: Test pytest plugin # This test will fail in a venv where scpdt has not been installed and the plugin has not been activated run: | - ls -l /home/runner/work/scpdt/scpdt/scpdt/tests/scpdt/tests/ + #ls -l /home/runner/work/scpdt/scpdt/scpdt/tests/scpdt/tests/ + pwd + ls -l test_files=("scpdt/tests/module_cases.py" "scpdt/tests/stopwords_cases.py" "scpdt/tests/local_file_cases.py") for file in "${test_files[@]}"; do python -m pytest "${file}" --doctest-modules From ae0e13192d560080cd8bc792eca859fcd2ceaa77 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 20 Feb 2024 23:19:17 +0300 Subject: [PATCH 04/10] more debugging --- scpdt/tests/test_pytest_configuration.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scpdt/tests/test_pytest_configuration.py b/scpdt/tests/test_pytest_configuration.py index d43f416..f8753ef 100644 --- a/scpdt/tests/test_pytest_configuration.py +++ b/scpdt/tests/test_pytest_configuration.py @@ -38,11 +38,8 @@ def copy_files(): pass -""" -Test that pytest uses the DTChecker for doctests -""" - def test_module_cases(pytester): + """Test that pytest uses the DTChecker for doctests.""" path_str = module_cases.__file__ python_file = PosixPath(path_str) result = pytester.inline_run(python_file, "--doctest-modules") @@ -58,21 +55,18 @@ def test_failure_cases(pytester): assert result.ret == pytest.ExitCode.TESTS_FAILED -""" -Test that pytest uses the DTParser for doctests -""" def test_stopword_cases(pytester): + """Test that pytest uses the DTParser for doctests.""" path_str = stopwords_cases.__file__ python_file = PosixPath(path_str) result = pytester.inline_run(python_file, "--doctest-modules") assert result.ret == pytest.ExitCode.OK -""" -Test that local files are found for use in doctests -""" def test_local_file_cases(pytester): + """Test that local files are found for use in doctests.""" path_str = local_file_cases.__file__ python_file = PosixPath(path_str) + assert python_file is None result = pytester.inline_run(python_file, "--doctest-modules") assert result.ret == pytest.ExitCode.OK From e8f7d4813e8a0d9ae63a4d2296260a1058f29fbc Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Tue, 20 Feb 2024 23:27:27 +0300 Subject: [PATCH 05/10] xfail the test of local files + plugin --- scpdt/tests/test_pytest_configuration.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scpdt/tests/test_pytest_configuration.py b/scpdt/tests/test_pytest_configuration.py index f8753ef..0b9d54f 100644 --- a/scpdt/tests/test_pytest_configuration.py +++ b/scpdt/tests/test_pytest_configuration.py @@ -63,10 +63,14 @@ def test_stopword_cases(pytester): assert result.ret == pytest.ExitCode.OK +@pytest.mark.xfail def test_local_file_cases(pytester): - """Test that local files are found for use in doctests.""" + """Test that local files are found for use in doctests. + + XXX: this one fails because nobody told pytest how to find those local files. + cf test_testmod.py::TestLocalFiles + """ path_str = local_file_cases.__file__ python_file = PosixPath(path_str) - assert python_file is None result = pytester.inline_run(python_file, "--doctest-modules") assert result.ret == pytest.ExitCode.OK From f444008ff70ef9f1a384049e73000391fc77791f Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Wed, 21 Feb 2024 01:17:35 +0300 Subject: [PATCH 06/10] WIP: messy debug 1. why local_files tests pass with doctest: the paths are clearly wrong? 2. who filled the dt_config key? --- scpdt/plugin.py | 6 ++++-- scpdt/tests/test_pytest_configuration.py | 19 ++++++++++++++++--- scpdt/util.py | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/scpdt/plugin.py b/scpdt/plugin.py index 7ab7433..d635575 100644 --- a/scpdt/plugin.py +++ b/scpdt/plugin.py @@ -167,8 +167,8 @@ def collect(self): raise # Copy local files specified by the `local_resources` attribute to the current working directory - if self.config.dt_config.local_resources: - copy_local_files(self.config.dt_config.local_resources, os.getcwd()) + # if self.config.dt_config.local_resources: + # copy_local_files(self.config.dt_config.local_resources, os.getcwd()) optionflags = dt_config.optionflags @@ -258,6 +258,8 @@ def run(self, test, compileflags=None, out=None, clear_globs=False): """ dt_config = config.dt_config + breakpoint() + with np_errstate(): with dt_config.user_context_mgr(test): with matplotlib_make_nongui(): diff --git a/scpdt/tests/test_pytest_configuration.py b/scpdt/tests/test_pytest_configuration.py index 0b9d54f..91366ba 100644 --- a/scpdt/tests/test_pytest_configuration.py +++ b/scpdt/tests/test_pytest_configuration.py @@ -8,7 +8,7 @@ pytest_plugins = ['pytester'] - +''' @pytest.fixture(autouse=True) def copy_files(): """ @@ -36,7 +36,7 @@ def copy_files(): os.remove(filepath) except FileNotFoundError: pass - +''' def test_module_cases(pytester): """Test that pytest uses the DTChecker for doctests.""" @@ -63,7 +63,7 @@ def test_stopword_cases(pytester): assert result.ret == pytest.ExitCode.OK -@pytest.mark.xfail +#@pytest.mark.xfail def test_local_file_cases(pytester): """Test that local files are found for use in doctests. @@ -72,5 +72,18 @@ def test_local_file_cases(pytester): """ path_str = local_file_cases.__file__ python_file = PosixPath(path_str) + + # pytester.makeconftest( + # """ + # import pytest + # from scpdt.conftest import dt_config + # + # dt_config.local_resources = {'scpdt.tests.local_file_cases.local_files': + # ['local_file.txt']} + # """ + # ) + + # breakpoint() + result = pytester.inline_run(python_file, "--doctest-modules") assert result.ret == pytest.ExitCode.OK diff --git a/scpdt/util.py b/scpdt/util.py index c82eb93..203f4ed 100644 --- a/scpdt/util.py +++ b/scpdt/util.py @@ -54,6 +54,8 @@ def temp_cwd(test, local_resources=None): cwd = os.getcwd() tmpdir = tempfile.mkdtemp() + breakpoint() + if local_resources and test.name in local_resources: # local files requested; copy the files path, _ = os.path.split(test.filename) From 4bda98756092a6fe753c70719374f3158b5e96b2 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Sat, 24 Feb 2024 13:57:06 +0300 Subject: [PATCH 07/10] .. --- scpdt/util.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scpdt/util.py b/scpdt/util.py index 203f4ed..2eeef60 100644 --- a/scpdt/util.py +++ b/scpdt/util.py @@ -54,13 +54,11 @@ def temp_cwd(test, local_resources=None): cwd = os.getcwd() tmpdir = tempfile.mkdtemp() - breakpoint() - if local_resources and test.name in local_resources: # local files requested; copy the files path, _ = os.path.split(test.filename) for fname in local_resources[test.name]: - shutil.copy(os.path.join(path, fname), tmpdir) + shutil.copy(os.path.join(path, fname), tmpdir) try: os.chdir(tmpdir) yield tmpdir From 20594e151ee84c1122cac4b97249474aa0c196b4 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Sat, 24 Feb 2024 13:58:59 +0300 Subject: [PATCH 08/10] rm stray breakpoint --- scpdt/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scpdt/plugin.py b/scpdt/plugin.py index d635575..3b857ce 100644 --- a/scpdt/plugin.py +++ b/scpdt/plugin.py @@ -258,7 +258,6 @@ def run(self, test, compileflags=None, out=None, clear_globs=False): """ dt_config = config.dt_config - breakpoint() with np_errstate(): with dt_config.user_context_mgr(test): From 0bed0d4c7a207ac3083170084d3b4d0eb16af174 Mon Sep 17 00:00:00 2001 From: Sheila-nk Date: Mon, 26 Feb 2024 15:13:08 +0300 Subject: [PATCH 09/10] change local file path --- scpdt/tests/local_file_cases.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scpdt/tests/local_file_cases.py b/scpdt/tests/local_file_cases.py index cb45aed..8508213 100644 --- a/scpdt/tests/local_file_cases.py +++ b/scpdt/tests/local_file_cases.py @@ -3,9 +3,9 @@ # Specify local files required by doctests dt_config.local_resources = {'scpdt.tests.local_file_cases.local_files': - ['scpdt/tests/local_file.txt'], + ['local_file.txt'], 'scpdt.tests.local_file_cases.sio': - ['scpdt/tests/octave_a.mat'] + ['octave_a.mat'] } __all__ = ['local_files', 'sio'] From a8475afba3824f897c8818e074762463b86fd3e6 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Mon, 26 Feb 2024 13:00:14 +0300 Subject: [PATCH 10/10] MAINT: use super() in DTRunner Explicit doctest.DocTestRunnner(self, ...) are from python 2 era where doctest was using old-style classes (yes indeed). --- scpdt/impl.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/scpdt/impl.py b/scpdt/impl.py index 9379b67..5a7e015 100644 --- a/scpdt/impl.py +++ b/scpdt/impl.py @@ -334,8 +334,7 @@ def __init__(self, checker=None, verbose=None, optionflags=None, config=None): self.nameerror_after_exception = config.nameerror_after_exception if optionflags is None: optionflags = config.optionflags - doctest.DocTestRunner.__init__(self, checker=checker, verbose=verbose, - optionflags=optionflags) + super().__init__(checker=checker, verbose=verbose, optionflags=optionflags) def _report_item_name(self, out, item_name, new_line=False): if item_name is not None: @@ -344,12 +343,12 @@ def _report_item_name(self, out, item_name, new_line=False): out("\n") def report_start(self, out, test, example): - return doctest.DocTestRunner.report_start(self, out, test, example) + return super().report_start(out, test, example) def report_success(self, out, test, example, got): if self._verbose: self._report_item_name(out, test.name, new_line=True) - return doctest.DocTestRunner.report_success(self, out, test, example, got) + return super().report_success(out, test, example, got) def report_unexpected_exception(self, out, test, example, exc_info): if not self.nameerror_after_exception: @@ -367,8 +366,7 @@ def report_unexpected_exception(self, out, test, example, exc_info): def report_failure(self, out, test, example, got): self._report_item_name(out, test.name) - return doctest.DocTestRunner.report_failure(self, out, test, - example, got) + return super().report_failure(out, test, example, got) def get_history(self): """Return a dict with names of items which were run.