From d4d6e470af5494e34347840c5d21faaa509c65dc Mon Sep 17 00:00:00 2001 From: salotz Date: Tue, 12 Mar 2024 11:45:58 -0400 Subject: [PATCH] fix tests use pytest-datadir instead of my custom thing which was broken --- hatch.toml | 1 + tests/conftest.py | 26 ------------------- tests/test_collector.py | 12 ++++----- {test_data => tests/test_collector}/a.py | 0 .../test_collector}/detect_files/a.py | 0 .../test_collector}/detect_files/b.py | 0 .../mock_structure/__init__.py | 0 .../mock_structure/for_func_finder.py | 0 .../resolve_fq_modules/mymodule/__init__.py | 0 .../resolve_fq_modules/mymodule/other.py | 0 .../resolve_fq_modules/mymodule/thing.py | 0 .../resolve_fq_targets/mymodule/__init__.py | 0 .../mymodule/cases/__init__.py | 0 .../mymodule/cases/async_methods.py | 0 .../mymodule/cases/decorators.py | 0 .../mymodule/cases/ignored.py | 0 .../mymodule/cases/multi_methods.py | 0 .../mymodule/cases/multiclass_same_method.py | 0 .../resolve_fq_targets/mymodule/other.py | 0 .../resolve_fq_targets/mymodule/thing.py | 0 tests/test_data.py | 7 ----- 21 files changed, 7 insertions(+), 39 deletions(-) delete mode 100644 tests/conftest.py rename {test_data => tests/test_collector}/a.py (100%) rename {test_data => tests/test_collector}/detect_files/a.py (100%) rename {test_data => tests/test_collector}/detect_files/b.py (100%) rename {test_data => tests/test_collector}/mock_structure/__init__.py (100%) rename {test_data => tests/test_collector}/mock_structure/for_func_finder.py (100%) rename {test_data => tests/test_collector}/resolve_fq_modules/mymodule/__init__.py (100%) rename {test_data => tests/test_collector}/resolve_fq_modules/mymodule/other.py (100%) rename {test_data => tests/test_collector}/resolve_fq_modules/mymodule/thing.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/__init__.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/__init__.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/async_methods.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/decorators.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/ignored.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/multi_methods.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/cases/multiclass_same_method.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/other.py (100%) rename {test_data => tests/test_collector}/resolve_fq_targets/mymodule/thing.py (100%) delete mode 100644 tests/test_data.py diff --git a/hatch.toml b/hatch.toml index 48f8d7c..73b5958 100644 --- a/hatch.toml +++ b/hatch.toml @@ -8,6 +8,7 @@ python = "3.12" dependencies = [ "pytest", + "pytest-datadir", "black", "ruff", "mypy", diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index b5a864f..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,26 +0,0 @@ -from pathlib import Path - -import pytest - - -def pytest_addoption(parser): - parser.addoption( - "--test-data", - action="store", - default="test_data", - ) - - -@pytest.fixture -def test_data_dir(request): - - test_data_path = Path(request.config.getoption("--test-data")) - - if not test_data_path.exists(): - - raise ValueError(f"Test data path {test_data_path} does not exist.") - - elif not test_data_path.is_dir(): - raise ValueError(f"Test data path {test_data_path} is not a directory.") - - return test_data_path diff --git a/tests/test_collector.py b/tests/test_collector.py index a258c15..30ba44d 100644 --- a/tests/test_collector.py +++ b/tests/test_collector.py @@ -13,19 +13,19 @@ @pytest.mark.pointer(target=detect_files) -def test_detect_files(test_data_dir): - assert len(detect_files(test_data_dir / "detect_files")) == 2 +def test_detect_files(datadir): + assert len(detect_files(datadir / "detect_files")) == 2 @pytest.mark.pointer(target=resolve_fq_modules) -def test_resolve_fq_modules(test_data_dir): +def test_resolve_fq_modules(datadir): expected_module_fqs = [ "mymodule.thing", "mymodule.other", ] - search_dir = test_data_dir / "resolve_fq_modules" + search_dir = datadir / "resolve_fq_modules" modpath = search_dir / "mymodule" submod_paths = [ modpath / "thing.py", @@ -44,9 +44,9 @@ def test_resolve_fq_modules(test_data_dir): @pytest.mark.pointer(target=resolve_fq_targets) -def test_resolve_fq_targets(test_data_dir): +def test_resolve_fq_targets(datadir): - search_dir = test_data_dir / "resolve_fq_targets" + search_dir = datadir / "resolve_fq_targets" modpath = search_dir / "mymodule" submod_paths = modpath.glob("**/*.py") diff --git a/test_data/a.py b/tests/test_collector/a.py similarity index 100% rename from test_data/a.py rename to tests/test_collector/a.py diff --git a/test_data/detect_files/a.py b/tests/test_collector/detect_files/a.py similarity index 100% rename from test_data/detect_files/a.py rename to tests/test_collector/detect_files/a.py diff --git a/test_data/detect_files/b.py b/tests/test_collector/detect_files/b.py similarity index 100% rename from test_data/detect_files/b.py rename to tests/test_collector/detect_files/b.py diff --git a/test_data/mock_structure/__init__.py b/tests/test_collector/mock_structure/__init__.py similarity index 100% rename from test_data/mock_structure/__init__.py rename to tests/test_collector/mock_structure/__init__.py diff --git a/test_data/mock_structure/for_func_finder.py b/tests/test_collector/mock_structure/for_func_finder.py similarity index 100% rename from test_data/mock_structure/for_func_finder.py rename to tests/test_collector/mock_structure/for_func_finder.py diff --git a/test_data/resolve_fq_modules/mymodule/__init__.py b/tests/test_collector/resolve_fq_modules/mymodule/__init__.py similarity index 100% rename from test_data/resolve_fq_modules/mymodule/__init__.py rename to tests/test_collector/resolve_fq_modules/mymodule/__init__.py diff --git a/test_data/resolve_fq_modules/mymodule/other.py b/tests/test_collector/resolve_fq_modules/mymodule/other.py similarity index 100% rename from test_data/resolve_fq_modules/mymodule/other.py rename to tests/test_collector/resolve_fq_modules/mymodule/other.py diff --git a/test_data/resolve_fq_modules/mymodule/thing.py b/tests/test_collector/resolve_fq_modules/mymodule/thing.py similarity index 100% rename from test_data/resolve_fq_modules/mymodule/thing.py rename to tests/test_collector/resolve_fq_modules/mymodule/thing.py diff --git a/test_data/resolve_fq_targets/mymodule/__init__.py b/tests/test_collector/resolve_fq_targets/mymodule/__init__.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/__init__.py rename to tests/test_collector/resolve_fq_targets/mymodule/__init__.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/__init__.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/__init__.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/__init__.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/__init__.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/async_methods.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/async_methods.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/async_methods.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/async_methods.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/decorators.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/decorators.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/decorators.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/decorators.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/ignored.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/ignored.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/ignored.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/ignored.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/multi_methods.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/multi_methods.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/multi_methods.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/multi_methods.py diff --git a/test_data/resolve_fq_targets/mymodule/cases/multiclass_same_method.py b/tests/test_collector/resolve_fq_targets/mymodule/cases/multiclass_same_method.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/cases/multiclass_same_method.py rename to tests/test_collector/resolve_fq_targets/mymodule/cases/multiclass_same_method.py diff --git a/test_data/resolve_fq_targets/mymodule/other.py b/tests/test_collector/resolve_fq_targets/mymodule/other.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/other.py rename to tests/test_collector/resolve_fq_targets/mymodule/other.py diff --git a/test_data/resolve_fq_targets/mymodule/thing.py b/tests/test_collector/resolve_fq_targets/mymodule/thing.py similarity index 100% rename from test_data/resolve_fq_targets/mymodule/thing.py rename to tests/test_collector/resolve_fq_targets/mymodule/thing.py diff --git a/tests/test_data.py b/tests/test_data.py deleted file mode 100644 index cf8f694..0000000 --- a/tests/test_data.py +++ /dev/null @@ -1,7 +0,0 @@ -"""Just test that the data is being loaded properly.""" - - -def test_data_dir(test_data_dir): - - test_data_files = list(test_data_dir.iterdir()) - assert len(test_data_files) > 0