def test_skips_files_in_hidden_directory(self, dir_with_hidden_dir): """Hidden directory files should be skipped.""" out1 = list(iter_files(dir_with_hidden_dir)) has_hidden_by_parent = ["hidden_by_parent" in x for x in out1] assert not any(has_hidden_by_parent) # But if skip_hidden is False it should be there out2 = list(iter_files(dir_with_hidden_dir, skip_hidden=False)) has_hidden_by_parent = ["hidden_by_parent" in x for x in out2] assert sum(has_hidden_by_parent) == 1
def test_mtime(self, simple_dir): """Test filtering based on modified time""" files = list(self.get_file_paths(self.file_paths, simple_dir)) # set the first file mtime in future now = time.time() first_file = files[0] os.utime(first_file, (now + 10, now + 10)) # get output make sure it only returned first file out = list(iter_files(simple_dir, mtime=now + 5)) assert len(out) == 1 assert Path(out[0]) == first_file
def test_multiple_subdirs(self, simple_dir): """Test with multiple sub directories.""" path1 = simple_dir / "B" / "D" path2 = simple_dir / "B" / "G" out = {Path(x) for x in iter_files([path1, path2])} files = self.get_file_paths(self.file_paths, simple_dir) expected = { x for x in files if str(x).startswith(str(path1)) or str(x).startswith(str(path2)) } assert out == expected
def _unindexed_iterator(self, paths: Optional[bank_subpaths_type] = None): """Return an iterator of potential unindexed files.""" # get mtime, subtract a bit to avoid odd bugs mtime = None last_updated = self.last_updated_timestamp # this needs db so only call once if last_updated is not None: mtime = last_updated - 0.001 # get paths to iterate bank_path = self.bank_path if paths is None: paths = self.bank_path else: paths = [ f"{self.bank_path}/{x}" if str(bank_path) not in str(x) else str(x) for x in iterate(paths) ] # return file iterator return iter_files(paths, ext=self.ext, mtime=mtime)
def test_extention(self, simple_dir): """Test filtering based on extention.""" out = set(iter_files(simple_dir, ext=".txt")) for val in out: assert val.endswith(".txt")
def test_one_subdir(self, simple_dir): """Test with one sub directory.""" subdirs = simple_dir / "B" / "D" out = set(iter_files(subdirs)) assert len(out) == 1
def test_basic(self, simple_dir): """test basic usage of iterfiles.""" files = set(self.get_file_paths(self.file_paths, simple_dir)) out = set((Path(x) for x in iter_files(simple_dir))) assert files == out