Esempio n. 1
0
def test_glob_sep_normalize(monkeypatch):
    monkeypatch.setattr(os.path, "sep", "#")
    monkeypatch.setattr(os.path, "altsep", "~")

    assert len(filescanner.GlobMatcher("a#b~c")._pat) == 3

    monkeypatch.setattr(os.path, "altsep", None)

    assert len(filescanner.GlobMatcher("a#b~c")._pat) == 2
Esempio n. 2
0
def test_glob_not_implemented():
    with pytest.raises(NotImplementedError):
        filescanner.GlobMatcher("*/.**")
Esempio n. 3
0
def test_glob_errors(pattern):
    with pytest.raises(AssertionError):
        filescanner.GlobMatcher(pattern)
Esempio n. 4
0
def test_glob_compile(pattern: ty.AnyStr, expected: ty.List[ty.AnyStr],
                      kwargs: ty.Dict[str, bool]):
    matcher = filescanner.GlobMatcher(pattern, **kwargs)
    assert list(
        map(lambda r: r.pattern
            if r is not None else None, matcher._pat)) == expected
Esempio n. 5
0
        ("*.a/", ".a", False, False, False, {
            "period_special": False
        }),
        ("*.a/", ".a", True, False, False, {}),
        ("*.a/", ".a", True, False, True, {
            "period_special": False
        }),

        # Tests for double-star recursion with premium leading-period shenanigans
        ("*/**/*.dir/**/**/.hidden", ".dir/.hidden", False, False, False, {}),
        ("*/**/*.dir/**/**/.hidden", "a/.dir/.hidden", False, True, False, {}),
        ("*/**/*.dir/**/**/.hidden", "a/b.dir/.hidden", False, True, True, {}),
        ("*/**/*.dir/**/**/.hidden", "a/u/v/w/b.dir/c/d/e/f/.hidden", False,
         True, True, {}),
        ("**", ".a", False, True, False, {}),
        (filescanner.GlobMatcher("**"), ".a", False, True, False, {}),

        # Regular expression test
        (re.compile(r"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"),
         "Camera/IMG-0169.jpeg", False, True, True, {}),
        (re.compile(r"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"), "Camera", True,
         True, True, {}),
        (re.compile(r"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"), "Camera/Thumbs.db",
         False, True, False, {}),
        (re.compile(br"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"),
         b"Camera/IMG-0169.jpeg", False, True, True, {}),
        (re.compile(br"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"), b"Camera", True,
         True, True, {}),
        (re.compile(br"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"),
         b"Camera/Thumbs.db", False, True, False, {}),
        (filescanner.ReMatcher(br"[^/\\]+[/\\](IMG-\d{0,4}\.jpeg)?$"),