From fc33c6e4513d4a715dcf202a7f37ae54d302085c Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Mon, 19 Feb 2024 17:22:11 -0500 Subject: [PATCH 1/3] Expand paths unaltered when comp has no wcards Previously returned an empty list. This is different from a component with no entries (but with wildcards), which should return an empty list Resolves #371 --- snakebids/core/datasets.py | 21 ++++++++++++--------- snakebids/tests/test_datasets.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/snakebids/core/datasets.py b/snakebids/core/datasets.py index 361e4998..33e84506 100644 --- a/snakebids/core/datasets.py +++ b/snakebids/core/datasets.py @@ -394,17 +394,20 @@ def sequencify(item: bool | str | Iterable[str]) -> bool | list[str]: return list(itx.always_iterable(item)) allow_missing_seq = sequencify(allow_missing) - inner_expand = list( - # order preserving deduplication - dict.fromkeys( - sn_expand( - list(itx.always_iterable(paths)), - zip, - allow_missing=True if wildcards else allow_missing_seq, - **self.zip_lists, + if self.zip_lists: + inner_expand = list( + # order preserving deduplication + dict.fromkeys( + sn_expand( + list(itx.always_iterable(paths)), + zip, + allow_missing=True if wildcards else allow_missing_seq, + **self.zip_lists, + ) ) ) - ) + else: + inner_expand = list(itx.always_iterable(paths)) if not wildcards: return inner_expand diff --git a/snakebids/tests/test_datasets.py b/snakebids/tests/test_datasets.py index 89dd8378..2be0fd10 100644 --- a/snakebids/tests/test_datasets.py +++ b/snakebids/tests/test_datasets.py @@ -340,6 +340,16 @@ def test_expand_preserves_entry_order(self, component: Expandable): for path, entity_vals in zip(paths, zip(*component.zip_lists.values())): assert bids(**dict(zip(component.zip_lists.keys(), entity_vals))) == path + @given(path=st.text()) + def test_expandable_with_no_wildcards_returns_path_unaltered(self, path: str): + component = BidsPartialComponent(zip_lists={}) + assert itx.one(component.expand(path)) == path + + @given(component=sb_st.expandables(min_values=0, max_values=0, path_safe=True)) + def test_expandable_with_no_entries_returns_empty_list(self, component: Expandable): + path_tpl = bids(**get_wildcard_dict(component.zip_lists)) + assert component.expand(path_tpl) == [] + class TestBidsComponentExpand: """ From 0e86b87ca66aac9a96704288ab5e45e9646c71b9 Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Tue, 20 Feb 2024 14:31:41 -0500 Subject: [PATCH 2/3] Catch our own warnings in pybidsdb tests --- snakebids/tests/test_generate_inputs.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/snakebids/tests/test_generate_inputs.py b/snakebids/tests/test_generate_inputs.py index eb226337..9070cab8 100644 --- a/snakebids/tests/test_generate_inputs.py +++ b/snakebids/tests/test_generate_inputs.py @@ -112,9 +112,14 @@ def test_old_params_passed_on_to_new( pybids_database_dir: str, pybids_database_reset: bool, ): - assert (pybids_database_dir, pybids_database_reset) == _normalize_database_args( - None, None, pybids_database_dir, pybids_database_reset - ) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=UserWarning) + assert ( + pybids_database_dir, + pybids_database_reset, + ) == _normalize_database_args( + None, None, pybids_database_dir, pybids_database_reset + ) @given( pybidsdb_reset=st.booleans() | st.none(), From 12201541c8ac31edfad97b5b0aa39a9188c3945d Mon Sep 17 00:00:00 2001 From: Peter Van Dyken Date: Tue, 20 Feb 2024 14:33:20 -0500 Subject: [PATCH 3/3] Add character exclusion to copier call test --- snakebids/tests/test_admin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snakebids/tests/test_admin.py b/snakebids/tests/test_admin.py index a82c3336..a26b9505 100644 --- a/snakebids/tests/test_admin.py +++ b/snakebids/tests/test_admin.py @@ -133,7 +133,9 @@ def test_create_fails_when_snakebids_version_specifies_extras( @given( name=st.from_regex(r"^[a-zA-Z_][a-zA-Z_0-9]*$"), - version=st.text(st.characters(blacklist_characters=["@", ";", "["])) + version=st.text(st.characters(blacklist_characters=["@", ";", "["])).filter( + lambda s: not s.startswith("-") + ) | st.none(), ) @allow_function_scoped