Beispiel #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)
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #10
0
 def original(self, root):
     return path_.hash(root).hexdigest()
Beispiel #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()