def test_walk(monkeypatch, path: str, pattern: None, kwargs: ty.Dict[str,
                                                                     bool],
              expected: ty.List[filescanner.FSNodeEntry]):
    result = [(e.type, e.relpath, e.name)
              for e in filescanner.walk(path, pattern, **kwargs)]
    assert sorted(result, key=lambda r: r[1]) == expected

    # Check again with plain `os.walk` if the current platform supports `os.fwalk`
    if filescanner.HAVE_FWALK:
        monkeypatch.setattr(filescanner, "HAVE_FWALK", False)

        result = [(e.type, e.relpath, e.name)
                  for e in filescanner.walk(path, pattern, **kwargs)]
        assert sorted(result, key=lambda r: r[1]) == expected
Example #2
0
def test_walk_instaclose(mocker):
    close_spy = mocker.spy(filescanner.walk, "close")

    with filescanner.walk("."):
        pass

    close_spy.assert_called_once()
Example #3
0
 def assert_results() -> None:
     result = [(e.type, e.relpath, e.name)
               for e in filescanner.walk(path, pattern)]
     assert sorted(result, key=lambda r: r[1]) == expected
Example #4
0
def test_walk_fd_unsupported(monkeypatch):
    monkeypatch.setattr(filescanner, "HAVE_FWALK", False)

    with pytest.raises(NotImplementedError):
        filescanner.walk(0)