def test__force_refresh(self):
     p = get_mock_dir_path(iterdir=[
         get_mock_file_path("HAM", b"sandwich"),
         get_mock_dir_path("EGGS")
     ])
     L = LocalFileInfoBrowser()
     L.force_refresh(p)
     assert p in L._cache
     assert p._iterdir[1] in L._cache
 def test_get_fresh_hash__for_dir(self):
     p = get_mock_dir_path(iterdir=[
         get_mock_file_path("HAM", b"sandwich"),
         get_mock_file_path("EGGS", b"with toast")
     ])
     L = LocalFileInfoBrowser()
     h = sha256()
     h.update(fsencode("EGGS"))
     h.update(sha256(b"with toast").digest())
     h.update(fsencode("HAM"))
     h.update(sha256(b"sandwich").digest())
     assert L.get_fresh_hash(p) == h.digest()
 def test___shallow_refresh(self):
     p = get_mock_file_path()
     L = LocalFileInfoBrowser()
     L._shallow_refresh(p)
     assert p in L._cache
     p._read_bytes = b"Updated"
     L._shallow_refresh(p)
     assert L._cache[p].hash == sha256(b"Updated").digest()
     p._exists = False
     L._shallow_refresh(p)
     assert p not in L._cache
 def test_is_possibly_changed__for_updated_mtime(self):
     p = get_mock_file_path()
     L = LocalFileInfoBrowser()
     assert L.is_possibly_changed(p)
     L._cache[p]\
         = FileInfo(path=p, is_dir=False, mtime=0, file_hash=get_mock_hash())
     assert not L.is_possibly_changed(p)
     p._stat.st_mtime_ns += 1
     assert L.is_possibly_changed(p)
 def test_is_possibly_changed__for_updated_dir_contents(self):
     p = get_mock_dir_path(iterdir=[
         get_mock_file_path("HAM", b"sandwich"),
         get_mock_file_path("EGGS", b"with toast")
     ])
     L = LocalFileInfoBrowser()
     assert L.is_possibly_changed(p)
     L._cache[p]\
         = FileInfo(path=p, is_dir=True, mtime=0, file_hash=get_mock_hash())
     L._cache[p._iterdir[0]]\
         = FileInfo(path="HAM", is_dir=False, mtime=0, file_hash=get_mock_hash())
     L._cache[p._iterdir[1]]\
         = FileInfo(path="EGGS", is_dir=False, mtime=0, file_hash=get_mock_hash())
     assert not L.is_possibly_changed(p)
     p._iterdir[1]._stat.st_mtime_ns += 1
     assert L.is_possibly_changed(p)
 def test__get_fresh_hash__for_special_file(self):
     p = get_mock_special_file_path()
     L = LocalFileInfoBrowser()
     with pytest.raises(UnrecognizedSpecialFile) as e:
         L.get_fresh_hash(p)
 def test_get_fresh_hash__for_file(self):
     p = get_mock_file_path()
     L = LocalFileInfoBrowser()
     assert L.get_fresh_hash(p) == sha256(b"Mock contents").digest()