Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand paths unaltered when comp has no wcards #378

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions snakebids/core/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,20 @@
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(

Check warning on line 398 in snakebids/core/datasets.py

View check run for this annotation

Codecov / codecov/patch

snakebids/core/datasets.py#L397-L398

Added lines #L397 - L398 were not covered by tests
# 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))

Check warning on line 410 in snakebids/core/datasets.py

View check run for this annotation

Codecov / codecov/patch

snakebids/core/datasets.py#L410

Added line #L410 was not covered by tests
if not wildcards:
return inner_expand

Expand Down
4 changes: 3 additions & 1 deletion snakebids/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions snakebids/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
11 changes: 8 additions & 3 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading