-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: add new test loader and its test cases, for test cases o…
…f backends
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# | ||
# Copyright (C) 2023, 2024 Satoru SATOH <satoru.satoh gmail.com> | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# pylint: disable=missing-docstring,too-few-public-methods | ||
r"""Common functions for test cases of loaders and dumpers.""" | ||
from __future__ import annotations | ||
|
||
import pathlib | ||
import re | ||
import typing | ||
|
||
from .. import common | ||
|
||
|
||
PATH_PATTERN: re.Pattern = re.compile( | ||
r".+[/\\:\.]test_([^_]+)_([^_]+).py" | ||
) | ||
|
||
|
||
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/ | ||
""" | ||
match = pattern.match(testfile) | ||
if not match: | ||
raise NameError( | ||
f"Filename does not match expected pattern: {testfile}" | ||
) | ||
|
||
name = ".".join(match.groups()) | ||
subdir = "loaders" if is_loader else "dumpers" | ||
|
||
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) | ||
return common.load_data_for_testfile( | ||
testfile, datadir=datadir, **opts | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# Copyright (C) 2024 Satoru SATOH <satoru.satoh gmail.com> | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# pylint: disable=missing-docstring,too-few-public-methods | ||
r"""Test cases for Test Data Collecor.""" | ||
from __future__ import annotations | ||
|
||
import pathlib | ||
|
||
import pytest | ||
|
||
from . import common as TT | ||
|
||
|
||
CURDIR: pathlib.Path = pathlib.Path(__file__).parent | ||
TESTFILE = CURDIR / "loaders" / "json" / "test_json_stdlib.py" | ||
|
||
TEST_DATADIR = TT.common.RESOURCE_DIR / "loaders" / "json.stdlib" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("path", "is_loader", "exp"), | ||
((str(TESTFILE), True, TEST_DATADIR), | ||
), | ||
) | ||
def test_get_test_resdir(path, is_loader, exp): | ||
assert TT.get_test_resdir(path, is_loader) == exp |