Пример #1
0
    def test_initialization(self):
        ld = Glob(path="/some/path")
        assert ld.path == "/some/path"
        assert ld.pattern == "*"

        ld = Glob()
        assert ld.path == ""
Пример #2
0
    def test_list_dir_str(self, tmp_path: pathlib.Path):
        dir = tmp_path / "source"
        dir.mkdir(exist_ok=True)
        file = dir / "testfile"
        file.write_text("test")

        ld = Glob(path=str(dir))
        res = ld.run()

        assert res[0] == file
        assert isinstance(res[0], Path)
Пример #3
0
    def test_glob_pattern(self, tmp_path: pathlib.Path):
        dir = tmp_path / "source"
        dir.mkdir(exist_ok=True)
        file1 = dir / "testfile.txt"
        file2 = dir / "testfile.log"
        file1.write_text("test")
        file2.write_text("test")

        ld = Glob(path=dir, pattern="*.log")
        res = ld.run()

        assert len(res) == 1
        assert res[0] == file2
Пример #4
0
    def test_list_dir_recursive(self, tmp_path: pathlib.Path):
        parent_dir = tmp_path / "source"

        child_dir1 = parent_dir / "dir1"
        child_dir1.mkdir(parents=True, exist_ok=True)
        file1 = child_dir1 / "testfile"
        file1.write_text("test")

        child_dir2 = parent_dir / "dir2"
        child_dir2.mkdir(parents=True, exist_ok=True)
        file2 = child_dir2 / "filetest"
        file2.write_text("test")

        ld = Glob(path=parent_dir, pattern="**/*")
        res = ld.run()

        assert file1 in res
        assert file2 in res
        assert len(res) == 4
Пример #5
0
 def test_path_not_provided(self):
     ld = Glob()
     with pytest.raises(ValueError, match="No `path` provided"):
         ld.run()