Skip to content

Commit

Permalink
Cover missed lines in _querying.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pvandyken committed Jan 24, 2024
1 parent b0359b9 commit b74eb2a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
51 changes: 48 additions & 3 deletions snakebids/tests/test_generate_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion snakebids/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init__(self, path: str, entity: BidsEntity) -> None:


class _Documented(Protocol):
__doc__: str # noqa: A003
__doc__: str


def property_alias(
Expand Down

0 comments on commit b74eb2a

Please sign in to comment.