Skip to content

Commit

Permalink
scan source directory instead of using pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Sep 12, 2024
1 parent 69474e6 commit dd2dd9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
19 changes: 0 additions & 19 deletions romancal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,6 @@

collect_ignore = ["lib/dqflags.py"]

ALL_TEST_NAMES = set()


def pytest_collection_modifyitems(config, items):
for item in items:

if not hasattr(item, "module"):
# for doctests just use name (since it contains the module)
name = item.name
else:
# otherwise add module
name = ".".join((item.module.__name__, item.name))
ALL_TEST_NAMES.add(name)


@pytest.fixture
def all_test_names():
return ALL_TEST_NAMES


@pytest.fixture
def mk_tmp_dirs():
Expand Down
26 changes: 20 additions & 6 deletions romancal/tests/test_dms_requirements.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
import json
import re
from pathlib import Path

TEST_REQUIREMENTS_FILENAME = Path(__file__).parent / "dms_requirement_tests.json"
TEST_DIRECTORY = Path(__file__).parent.parent
TEST_REQUIREMENTS_FILENAME = TEST_DIRECTORY / "dms_requirement_tests.json"


def test_requirements(all_test_names):
def test_requirements():
test_requirements_filename = TEST_REQUIREMENTS_FILENAME.expanduser().absolute()
test_directory = TEST_DIRECTORY.expanduser().absolute()

with open(test_requirements_filename) as test_requirements_file:
requirements = json.load(test_requirements_file)

required_test_names = {
required_tests = {
test
for requirement_tests in requirements.values()
for test in requirement_tests
}

missing_test_names = required_test_names - all_test_names
existing_tests = set()
test_regex = re.compile(r"def (test_[^\(]+)\(.*\):")
for test_filename in test_directory.glob("**/test_*.py"):
with open(test_filename) as test_file:
test_file_contents = test_file.read()

for match in re.finditer(test_regex, test_file_contents):
test = f"{test_directory.stem}.{str(test_filename.relative_to(test_directory).parent).replace('/', '.')}.{test_filename.stem}.{match.group(1)}"
if test in required_tests:
existing_tests.add(test)

missing_tests = required_tests - existing_tests
assert (
not missing_test_names
), f"could not find the following tests correlated with DMS requirements: {missing_test_names}"
not missing_tests
), f"could not find the following tests correlated with DMS requirements: {missing_tests}"

0 comments on commit dd2dd9d

Please sign in to comment.