Skip to content

Commit

Permalink
improve readability of test parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 15, 2024
1 parent ff9228a commit 0fff16e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion tests/filesystem/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
},
]

GLOB_RESULTS = [
FACTORY_TEST_IDS = [
f"url={factory_args['bucket_url'][:15]}..." for factory_args in FACTORY_ARGS
]

GLOBS = [
{
"glob": None,
"file_names": ["sample.txt"],
Expand Down Expand Up @@ -84,3 +88,5 @@
"file_names": ["sample.txt"],
},
]

GLOB_TEST_IDS = [f"glob={glob_result['glob']}" for glob_result in GLOBS]
14 changes: 7 additions & 7 deletions tests/filesystem/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
)
from tests.filesystem.utils import unpack_factory_args

from .settings import GLOB_RESULTS, FACTORY_ARGS
from .settings import GLOBS, GLOB_TEST_IDS, FACTORY_ARGS, FACTORY_TEST_IDS


@pytest.mark.parametrize("factory_args", FACTORY_ARGS)
@pytest.mark.parametrize("glob_params", GLOB_RESULTS)
def test_file_list(factory_args: Dict[str, Any], glob_params: Dict[str, Any]) -> None:
@pytest.mark.parametrize("factory_args", FACTORY_ARGS, ids=FACTORY_TEST_IDS)
@pytest.mark.parametrize("globs", GLOBS, ids=GLOB_TEST_IDS)
def test_file_list(factory_args: Dict[str, Any], globs: Dict[str, Any]) -> None:
bucket_url, kwargs = unpack_factory_args(factory_args)

@dlt.transformer
def bypass(items) -> str:
return items

# we only pass the glob parameter to the resource if it is not None
if file_glob := glob_params["glob"]:
if file_glob := globs["glob"]:
filesystem_res = (
filesystem(
bucket_url=bucket_url,
Expand All @@ -48,8 +48,8 @@ def bypass(items) -> str:
all_files = list(filesystem_res)
file_count = len(all_files)
file_names = [item["file_name"] for item in all_files]
assert file_count == len(glob_params["file_names"])
assert file_names == glob_params["file_names"]
assert file_count == len(globs["file_names"])
assert file_names == globs["file_names"]


@pytest.mark.parametrize("extract_content", [True, False])
Expand Down

0 comments on commit 0fff16e

Please sign in to comment.