def _HashDirectory(self, absolute_path: pathlib.Path) -> str: if fs.directory_is_empty(absolute_path): last_modified_fn = lambda path: int(time.time()) else: last_modified_fn = lambda path: GetDirectoryMTime(path) return self._InMemoryWrapper( absolute_path, last_modified_fn, lambda x: checksumdir.dirhash(x, self.hash_fn_name))
def test_directory_is_empty_file_argument(): """Test that path to a file is an empty directory.""" with tempfile.TemporaryDirectory() as d: (pathlib.Path(d) / 'a').touch() assert fs.directory_is_empty(pathlib.Path(d) / 'a')
def test_directory_is_empty_non_existent(): """Test that a non-existent path is an empty directory.""" with tempfile.TemporaryDirectory() as d: assert fs.directory_is_empty(pathlib.Path(d) / 'a')
def test_directory_is_empty_file(): """Test that a file means the directory is not empty.""" with tempfile.TemporaryDirectory() as d: (pathlib.Path(d) / 'a').touch() assert not fs.directory_is_empty(d)
def test_directory_is_empty_only_subdirs(): """Test that a subdirectory means the directory is not empty.""" with tempfile.TemporaryDirectory() as d: (pathlib.Path(d) / 'a').mkdir() assert not fs.directory_is_empty(d)
def test_directory_is_empty_empty_dir(): """Test that en empty directory returns True.""" with tempfile.TemporaryDirectory() as d: assert fs.directory_is_empty(d)