From ab7d7cff1385c15ae5e6d468a6db5f51b7a062d7 Mon Sep 17 00:00:00 2001 From: Satoru SATOH Date: Tue, 21 May 2024 20:21:11 +0900 Subject: [PATCH] change: make subdir (loaders or dumpers) detected automatically from test file path --- tests/backend/common.py | 6 ++---- tests/backend/test_common.py | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/backend/common.py b/tests/backend/common.py index 1206812d..1eca5eb0 100644 --- a/tests/backend/common.py +++ b/tests/backend/common.py @@ -59,7 +59,6 @@ def get_test_ids(*args, **opts): def get_test_resdir( testfile: str, - is_loader: bool = True, pattern: re.Pattern = PATH_PATTERN ) -> pathlib.Path: """Get test resource dir for given test file path. @@ -67,7 +66,7 @@ def get_test_resdir( ex. tests/backend/loaders/json/test_json_stdlib.py -> tests/res/1/loaders/json.stdlib/ """ - subdir = "loaders" if is_loader else "dumpers" + subdir = pathlib.Path(testfile).parent.parent.name name = get_name(testfile, pattern=pattern) return common.RESOURCE_DIR / subdir / name @@ -75,10 +74,9 @@ def get_test_resdir( def load_data_for_testfile( testfile: str, - is_loader: bool = True, **opts ) -> list[tuple[pathlib.Path, dict[str, typing.Any], ...]]: - datadir = get_test_resdir(testfile, is_loader=is_loader) + datadir = get_test_resdir(testfile) return common.load_data_for_testfile( testfile, datadir=datadir, **opts ) diff --git a/tests/backend/test_common.py b/tests/backend/test_common.py index 5bd114b7..e687d667 100644 --- a/tests/backend/test_common.py +++ b/tests/backend/test_common.py @@ -45,9 +45,9 @@ def test_get_mod(testfile, exp): @pytest.mark.parametrize( - ("path", "is_loader", "exp"), - ((str(TESTFILE), True, TEST_DATADIR), + ("path", "exp"), + ((str(TESTFILE), TEST_DATADIR), ), ) -def test_get_test_resdir(path, is_loader, exp): - assert TT.get_test_resdir(path, is_loader) == exp +def test_get_test_resdir(path, exp): + assert TT.get_test_resdir(path) == exp