Ejemplo n.º 1
0
 def test_open_existing_store(self, temp_dir):
     '''
     Open an existing store.
     '''
     test_file = temp_dir / 'test.txt'
     test_file.touch()
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         version = store.put(test_file)
     with Store(store_path) as store:
         versions = store.get_versions(test_file)
         assert list(versions) == [version]
Ejemplo n.º 2
0
 def test_put_nonexisting_path(self, temp_dir):
     '''
     Put a non-existing path into the store.
     '''
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         with pytest.raises(FileNotFoundError):
             store.put(temp_dir / 'not-existing')
Ejemplo n.º 3
0
 def test_create_store_with_relative_path(self, temp_dir):
     '''
     Create a store using a relative path.
     '''
     with working_dir(temp_dir):
         with Store(Path('store')) as store:
             store_path = temp_dir / 'store'
             assert store.path == store_path
             assert store_path.is_dir()
Ejemplo n.º 4
0
 def test_create_store_in_existing_file(self, temp_dir):
     '''
     Try to create a store in an existing file.
     '''
     test_file = temp_dir / 'test.txt'
     test_file.touch()
     with pytest.raises(FileExistsError):
         with Store(test_file) as store:
             pass
Ejemplo n.º 5
0
 def test_create_store_in_nonexisting_directory(self, temp_dir):
     '''
     Create a store in a nonexisting directory.
     '''
     test_file = temp_dir / 'test.txt'
     test_file.touch()
     with Store(temp_dir / 'new') as store:
         version = store.put(test_file)
         versions = store.get_versions(test_file)
         assert list(versions) == [version]
Ejemplo n.º 6
0
 def test_put_directory(self, temp_dir):
     '''
     Put a directory into the store.
     '''
     subdir_path = temp_dir / 'subdir'
     subdir_path.mkdir()
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         with pytest.raises(IsADirectoryError):
             store.put(subdir_path)
Ejemplo n.º 7
0
 def test_put_relative_path(self, temp_dir):
     '''
     Put a file into the store using a relative path.
     '''
     test_filename = 'test.txt'
     (temp_dir / test_filename).touch()
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         with working_dir(temp_dir):
             version = store.put(Path(test_filename))
         assert version.path == temp_dir / test_filename
Ejemplo n.º 8
0
 def test_put_existing_file(self, temp_dir):
     '''
     Put an existing file into the store.
     '''
     test_file = temp_dir / 'test.txt'
     test_file.touch()
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         version = store.put(test_file)
         age = (datetime.datetime.utcnow() -
                version.stored_at).total_seconds()
         assert 0 < age < 2
         assert version.path == test_file
Ejemplo n.º 9
0
 def test_get_versions_of_relative_path(self, temp_dir):
     '''
     Get the versions of a file using a relative path.
     '''
     store_path = temp_dir / 'store'
     test_filename = 'test.txt'
     (temp_dir / test_filename).touch()
     other_file = temp_dir / 'other.txt'
     other_file.touch()
     with Store(store_path) as store:
         store.put(other_file)
         version = store.put(temp_dir / test_filename)
         with working_dir(temp_dir):
             assert list(store.get_versions(
                 Path(test_filename))) == [version]
Ejemplo n.º 10
0
 def test_get_versions(self, temp_dir):
     '''
     Get the versions of a file.
     '''
     test_file = temp_dir / 'test.txt'
     test_file.touch()
     other_file = temp_dir / 'other.txt'
     other_file.touch()
     store_path = temp_dir / 'store'
     with Store(store_path) as store:
         store.put(other_file)
         versions = []
         for i in range(5):
             version = store.put(test_file)
             assert isinstance(version.path, Path)
             versions.append(version)
             assert list(store.get_versions(test_file)) == versions
             test_file.write_text(str(i))
     for i in range(4):
         assert versions[i].stored_at < versions[i + 1].stored_at
Ejemplo n.º 11
0
def store():
    with tempfile.TemporaryDirectory() as d:
        with Store(Path(d)) as store:
            yield store