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

Prevent bids values with leading 0s in tests #427

Merged
merged 1 commit into from
May 9, 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
3 changes: 2 additions & 1 deletion snakebids/resources/bids_tags.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"run": {
"tag": "run",
"before": "[_/\\\\]+run-",
"match": "[0-9]{1,5}"
"match": "[0-9]{1,5}",
"type": "int"
},
"proc": {
"tag": "proc",
Expand Down
12 changes: 11 additions & 1 deletion snakebids/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,20 @@ def zip_lists(
)
)

def filter_ints(type_: str | None):
def inner(s: str):
if type_ == "int":
return int(s) > 0 and not s.startswith("0")
return True

return inner

values = {
entity: draw(
st.lists(
bids_value(entity.match if restrict_patterns else ".*"),
bids_value(entity.match if restrict_patterns else ".*").filter(
filter_ints(entity.type if restrict_patterns else None)
),
min_size=min_values,
max_size=max_values,
unique=(cull or unique),
Expand Down
11 changes: 11 additions & 0 deletions snakebids/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def wildcard(self) -> str:
return self.entity
return self.tag

@property
def type(self) -> str | None:
"""Get the type of the entity.

Returns None if type unspecified.
"""
tags = read_bids_tags()
# See note in .before
_def: dict[Any, Any] = {}
return tags.get(self.entity, _def).get("type")

@classmethod
def from_tag(cls, tag: str) -> BidsEntity:
"""Return the entity associated with the given tag, if found.
Expand Down