Esempio n. 1
0
 def test_no_cwd(self, root, original):
     'When current working directory changes, hash unchanged'
     root = root.absolute()
     Path('cwd').mkdir()
     original_cwd = os.getcwd()
     try:
         os.chdir('cwd')
         current = path_.hash(root).hexdigest()
         assert original == current
     finally:
         # Restore cwd for next tests, this should actually be in a fixture
         os.chdir(original_cwd)
Esempio n. 2
0
 def test_file_dir_stat(self, root, original):
     'When file/dir stat() changes, hash unchanged'
     (root / 'emptydir').chmod(0o404)
     (root / 'file').chmod(0o404)
     current = path_.hash(root).hexdigest()
     assert original == current
Esempio n. 3
0
 def test_no_root_name(self, root, original):
     'When root directory renamed, hash unchanged'
     root.rename('notroot')
     current = path_.hash(Path('notroot')).hexdigest()
     assert original == current
Esempio n. 4
0
 def test_no_root_location(self, root, original):
     'When root directory moved, hash unchanged'
     Path('subdir').mkdir()
     root.rename('subdir/root')
     current = path_.hash(Path('subdir/root')).hexdigest()
     assert original == current
Esempio n. 5
0
 def test_directory_move(self, root, original):
     'When directory moves, hash changes'
     (root / 'emptydir').rename(root / 'subdir1/emptydir')
     current = path_.hash(root).hexdigest()
     assert original != current
Esempio n. 6
0
 def test_file_content(self, root, original, contents):
     'When file content changes, hash changes'
     (root / 'file').write_text(contents * 3)
     current = path_.hash(root).hexdigest()
     assert original != current
Esempio n. 7
0
 def test_file_move(self, root, original):
     'When file moves, hash changes'
     (root / 'file').rename(root / 'subdir1/file')
     current = path_.hash(root).hexdigest()
     assert original != current
Esempio n. 8
0
 def test_file_remove(self, root, original):
     'When file removed, hash changes'
     (root / 'file').unlink()
     current = path_.hash(root).hexdigest()
     assert original != current
Esempio n. 9
0
 def test_empty_directory_remove(self, root, original):
     'When empty directory removed, hash changes'
     (root / 'emptydir').rmdir()
     current = path_.hash(root).hexdigest()
     assert original != current
Esempio n. 10
0
 def original(self, root):
     return path_.hash(root).hexdigest()
Esempio n. 11
0
def test_digest_file(path, contents):
    'When file, digest only its contents'
    path.write_text(contents)
    hash_ = hashlib.sha512()
    hash_.update(contents.encode())
    assert path_.hash(path).hexdigest() == hash_.hexdigest()