Skip to content

Commit

Permalink
change: make subdir (loaders or dumpers) detected automatically from …
Browse files Browse the repository at this point in the history
…test file path
  • Loading branch information
ssato committed May 21, 2024
1 parent daac5b1 commit ab7d7cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions tests/backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,24 @@ 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.
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


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
)
Expand Down
8 changes: 4 additions & 4 deletions tests/backend/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ab7d7cf

Please sign in to comment.