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 16, 2024
1 parent ff9228a commit fbbec91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 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]
22 changes: 11 additions & 11 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,12 +48,12 @@ 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])
@pytest.mark.parametrize("factory_args", FACTORY_ARGS)
@pytest.mark.parametrize("factory_args", FACTORY_ARGS, ids=FACTORY_TEST_IDS)
def test_load_content_resources(
factory_args: Dict[str, Any], extract_content: bool
) -> None:
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_fsspec_as_credentials():
print(list(gs_resource))


@pytest.mark.parametrize("factory_args", FACTORY_ARGS)
@pytest.mark.parametrize("factory_args", FACTORY_ARGS, ids=FACTORY_TEST_IDS)
def test_csv_transformers(factory_args: Dict[str, Any]) -> None:
from sources.filesystem_pipeline import read_csv

Expand Down Expand Up @@ -170,7 +170,7 @@ def test_csv_transformers(factory_args: Dict[str, Any]) -> None:
assert load_table_counts(pipeline, "met_csv") == {"met_csv": 48}


@pytest.mark.parametrize("factory_args", FACTORY_ARGS)
@pytest.mark.parametrize("factory_args", FACTORY_ARGS, ids=FACTORY_TEST_IDS)
def test_standard_readers(factory_args: Dict[str, Any]) -> None:
bucket_url, kwargs = unpack_factory_args(factory_args)

Expand Down Expand Up @@ -238,7 +238,7 @@ def _copy(item: FileItemDict):
# print(pipeline.default_schema.to_pretty_yaml())


@pytest.mark.parametrize("factory_args", FACTORY_ARGS)
@pytest.mark.parametrize("factory_args", FACTORY_ARGS, ids=FACTORY_TEST_IDS)
def test_incremental_load(factory_args: Dict[str, Any]) -> None:
@dlt.transformer
def bypass(items) -> str:
Expand Down

0 comments on commit fbbec91

Please sign in to comment.