diff --git a/snakebids/tests/test_generate_inputs.py b/snakebids/tests/test_generate_inputs.py index 8bce626e..0ad24ca8 100644 --- a/snakebids/tests/test_generate_inputs.py +++ b/snakebids/tests/test_generate_inputs.py @@ -13,7 +13,7 @@ import warnings from collections import defaultdict from pathlib import Path -from typing import Iterable, Literal, NamedTuple, TypedDict, TypeVar, cast +from typing import Any, Iterable, Literal, NamedTuple, TypedDict, TypeVar, cast import attrs import more_itertools as itx @@ -25,7 +25,7 @@ from pytest_mock import MockerFixture from snakemake.io import expand as sb_expand -from snakebids.core._querying import PostFilter, UnifiedFilter +from snakebids.core._querying import PostFilter, UnifiedFilter, get_matching_files from snakebids.core.datasets import BidsComponent, BidsDataset from snakebids.core.input_generation import ( _all_custom_paths, @@ -36,7 +36,7 @@ _parse_custom_path, generate_inputs, ) -from snakebids.exceptions import ConfigError, RunError +from snakebids.exceptions import ConfigError, PybidsError, RunError from snakebids.paths.presets import bids from snakebids.tests import strategies as sb_st from snakebids.tests.helpers import ( @@ -163,6 +163,28 @@ def test_non_deprecated_text_in_reset_raises_error(self, pybidsdb_reset: bool): _normalize_database_args(None, pybidsdb_reset, None, None) +def test_regex_search_removed_from_filters(): + assert not len(UnifiedFilter.from_filter_dict({"regex_search": "foo"}).prefilters) + + +@given( + filters=st.dictionaries(st.text(), st.text() | st.booleans() | st.lists(st.text())) +) +def test_get_matching_files_skips_get_when_empty_prefilter(filters: dict[str, Any]): + assert ( + get_matching_files( + ..., # type: ignore + UnifiedFilter.from_filter_dict({**filters, "foo": []}), + ) + == [] + ) + + +def test_attribute_errors_from_pybids_qualified_and_raised(): + with pytest.raises(PybidsError, match="Pybids has encountered a problem"): + get_matching_files(..., UnifiedFilter.from_filter_dict({})) # type: ignore + + class TestFilterBools: @pytest.fixture(autouse=True) def bids_fs(self, bids_fs: FakeFilesystem | None): @@ -1105,6 +1127,29 @@ def test_collect_all_but_filters_when_exclusion_filters_used( name="foo", path=get_bids_path(result_excluded), zip_lists=result_excluded ) + @given( + boolean=st.booleans(), + filter=st.none() | st.lists(st.text()), + path_entities=path_entities(), + ) + @allow_function_scoped + def test_errors_when_bools_given_as_filters( + self, + temp_dir: Path, + path_entities: PathEntities, + boolean: bool, + filter: list[str] | None, + ): + entities, template, _ = path_entities + test_path = self.generate_test_directory(entities, template, temp_dir) + with pytest.raises(ValueError, match="Boolean filters in items with custom "): + _parse_custom_path( + test_path, + UnifiedFilter.from_filter_dict( + {"foo": boolean if filter is None else [*filter, boolean]} + ), + ) + def test_custom_pybids_config(tmpdir: Path): # Generate directory diff --git a/snakebids/utils/utils.py b/snakebids/utils/utils.py index 62b98f93..199c7ff0 100644 --- a/snakebids/utils/utils.py +++ b/snakebids/utils/utils.py @@ -239,7 +239,7 @@ def __init__(self, path: str, entity: BidsEntity) -> None: class _Documented(Protocol): - __doc__: str # noqa: A003 + __doc__: str def property_alias(