Пример #1
0
def test_glob_matching(
        monkeypatch,
        pattern: ty.Union[ty.AnyStr, filescanner.re_pattern_t,
                          ty.List[ty.Union[ty.AnyStr,
                                           filescanner.re_pattern_t]]],
        path: ty.AnyStr, is_dir: bool, descend: bool, report: bool,
        kwargs: ty.Dict[str, bool]):
    # Hopefully useless sanity check
    assert os.path.sep == "/" or os.path.altsep == "/"

    slash = "/" if isinstance(path, str) else b"/"  # type: ty.AnyStr
    sep = os.path.sep if isinstance(path, str) else os.fsencode(
        os.path.sep)  # type: ty.AnyStr

    path = path.replace(slash, sep)

    matcher = filescanner.matcher_from_spec(pattern, **kwargs)
    assert matcher.should_descend(path) is descend
    assert matcher.should_report(path, is_dir=is_dir) is report
Пример #2
0
def test_matcher_from_spec_builds_non_recursive_open_matcher():
    actual = filescanner.matcher_from_spec(None, recursive=False)

    assert isinstance(actual, filescanner.NoRecusionAdapterMatcher)
    assert isinstance(actual._child, filescanner.MatchAll)
Пример #3
0
def test_matcher_from_spec_builds_non_recursive_glob_matcher():
    actual = filescanner.matcher_from_spec('*.py', recursive=False)

    assert isinstance(actual, filescanner.NoRecusionAdapterMatcher)
    assert isinstance(actual._child, filescanner.GlobMatcher)
Пример #4
0
def test_matcher_from_spec_builds_recursive_open_matcher():
    actual = filescanner.matcher_from_spec(None)

    assert isinstance(actual, filescanner.MatchAll)
Пример #5
0
def test_matcher_from_spec_builds_recursive_glob_matcher():
    actual = filescanner.matcher_from_spec('*.py')

    assert isinstance(actual, filescanner.GlobMatcher)
Пример #6
0
def test_matcher_from_spec_rejects_invalid_spec_type(spec: ty.Any) -> None:
    with pytest.raises(MatcherSpecInvalidError):
        filescanner.matcher_from_spec(spec)