def test_compare(self): file_a_path = get_named_tmpfile_path() file_b_path = get_named_tmpfile_path() file_c_path = get_named_tmpfile_path() fill_tmpfile(file_a_path) fill_tmpfile(file_b_path) file_a_instance = File(file_a_path, True, Path(), transform.string_as_hashid("foo")) file_b_instance = File(file_b_path) file_c_instance = File(file_c_path) file_a_modified_instance = File(file_a_path, True, Path(), transform.string_as_hashid("bar")) directory_old_instance = Directory({ "a": Directory( {}, { "file_a.txt": file_a_instance, "file_c.txt": file_c_instance, }, ) }) directory_new_instance = Directory({ "a": Directory({}, {"file_a.txt": file_a_modified_instance}), "b": Directory({}, {"file_b.txt": file_b_instance}), }) differences_instance = directory.compare(Path(), directory_old_instance, directory_new_instance) expected_result = [ "added: b/file_b.txt", "updated: a/file_a.txt", "removed: a/file_c.txt", ] result = differences.serialize_as_messages(differences_instance) self.assertListEqual(result, expected_result)
def test_string_as_hashid(self): data = "this is a string" expected_result = ( "bc7e8a24e2911a5827c9b33d618531ef094937f2b3803a591c625d0ede1fffc6" ) result = transform.string_as_hashid(data) self.assertEqual(result, expected_result)
def test_store_dict_as_blob(self): data = {"hello": "world"} result = "" expected_result = transform.string_as_hashid( transform.dict_as_json(data)) with tempfile.TemporaryDirectory() as tmpdirname: result = fs.store_dict_as_blob(Path(tmpdirname), data) self.assertEqual(result, expected_result)
def store_dict_as_blob(directory: Path, data: Dict[str, Any]) -> str: contents = transform.dict_as_json(data) hashid = transform.string_as_hashid(contents) hashid_path = directory.joinpath(transform.hashid_as_path(hashid)) store_file(hashid_path, contents) return hashid
def test_get_commit_path(self): hashid = transform.string_as_hashid("test") expected_result = str( Path("foobar/.snapfs/blobs").joinpath( transform.hashid_as_path(hashid))) result = str(repository.get_commit_path(Path("foobar"), hashid, False)) self.assertEqual(result, expected_result)
def test_store_as_blob(self): directory_instance = Directory() result = "" expected_result = transform.string_as_hashid( transform.dict_as_json( directory.serialize_as_dict(directory_instance))) with tempfile.TemporaryDirectory() as tmpdirname: result = directory.store_as_blob(Path(tmpdirname), directory_instance) self.assertEqual(result, expected_result)
def test_store_as_blob(self): commit_hashid = "" with tempfile.TemporaryDirectory() as tmpdirname: commit_hashid = commit.store_as_blob( Path(tmpdirname), commit_instance ) self.assertEqual( commit_hashid, transform.string_as_hashid( transform.dict_as_json(expected_result) ), )