def test_transforms_inode(self, get_inode_mock): state = State(self.dvc, self.dvc.config.config) inode = state.MAX_INT + 2 self.assertNotEqual(inode, state._to_sqlite(inode)) path = os.path.join(self.dvc.root_dir, self.FOO) md5 = file_md5(path)[0] get_inode_mock.side_effect = self.mock_get_inode(path, inode) with state: state.save({"scheme": "local", "path": path}, md5) ret = state.get_state_record_for_inode(inode) self.assertIsNotNone(ret)
def test_get_state_record_for_inode(get_inode_mock, dvc_repo, repo_dir): state = State(dvc_repo, dvc_repo.config.config) inode = state.MAX_INT + 2 assert inode != state._to_sqlite(inode) path = os.path.join(dvc_repo.root_dir, repo_dir.FOO) md5 = file_md5(path)[0] get_inode_mock.side_effect = mock_get_inode(inode) with state: state.save(PathInfo(path), md5) ret = state.get_state_record_for_inode(inode) assert ret is not None
def test_get_state_record_for_inode(get_inode_mock, tmp_dir, dvc): tmp_dir.gen("foo", "foo content") state = State(dvc, dvc.config.config) inode = state.MAX_INT + 2 assert inode != state._to_sqlite(inode) foo = tmp_dir / "foo" md5 = file_md5(foo)[0] get_inode_mock.side_effect = mock_get_inode(inode) with state: state.save(PathInfo(foo), md5) ret = state.get_state_record_for_inode(inode) assert ret is not None
def test_state(tmp_dir, dvc): tmp_dir.gen("foo", "foo content") path = tmp_dir / "foo" hash_info = HashInfo("md5", file_md5(path, dvc.fs)) state = State(dvc.root_dir, dvc.tmp_dir, dvc.dvcignore) state.save(path, dvc.fs, hash_info) assert state.get(path, dvc.fs)[1] == hash_info path.unlink() path.write_text("1") assert state.get(path, dvc.fs) == (None, None) hash_info = HashInfo("md5", file_md5(path, dvc.fs)) state.save(path, dvc.fs, hash_info) assert state.get(path, dvc.fs)[1] == hash_info
def test_state(tmp_dir, dvc): tmp_dir.gen("foo", "foo content") path = tmp_dir / "foo" path_info = PathInfo(path) hash_info = HashInfo("md5", file_md5(path, dvc.fs)) state = State(dvc.root_dir, dvc.tmp_dir) state.save(path_info, dvc.fs, hash_info) assert state.get(path_info, dvc.fs) == hash_info path.unlink() path.write_text("1") assert state.get(path_info, dvc.fs) is None hash_info = HashInfo("md5", file_md5(path, dvc.fs)) state.save(path_info, dvc.fs, hash_info) assert state.get(path_info, dvc.fs) == hash_info
def test_update(self): path = os.path.join(self.dvc.root_dir, self.FOO) path_info = {"scheme": "local", "path": path} md5 = file_md5(path)[0] state = State(self.dvc, self.dvc.config.config) with state: state.save(path_info, md5) entry_md5 = state.get(path_info) self.assertEqual(entry_md5, md5) os.unlink(path) with open(path, "a") as fd: fd.write("1") entry_md5 = state.get(path_info) self.assertTrue(entry_md5 is None) md5 = file_md5(path)[0] state.save(path_info, md5) entry_md5 = state.get(path_info) self.assertEqual(entry_md5, md5)
def test_state(dvc_repo, repo_dir): path = os.path.join(dvc_repo.root_dir, repo_dir.FOO) path_info = PathInfo(path) md5 = file_md5(path)[0] state = State(dvc_repo, dvc_repo.config.config) with state: state.save(path_info, md5) entry_md5 = state.get(path_info) assert entry_md5 == md5 os.unlink(path) with open(path, "a") as fd: fd.write("1") entry_md5 = state.get(path_info) assert entry_md5 is None md5 = file_md5(path)[0] state.save(path_info, md5) entry_md5 = state.get(path_info) assert entry_md5 == md5
def test_state(tmp_dir, dvc): tmp_dir.gen("foo", "foo content") path = tmp_dir / "foo" path_info = PathInfo(path) md5 = file_md5(path)[0] state = State(dvc, dvc.config.config) with state: state.save(path_info, md5) entry_md5 = state.get(path_info) assert entry_md5 == md5 path.unlink() path.write_text("1") entry_md5 = state.get(path_info) assert entry_md5 is None md5 = file_md5(path)[0] state.save(path_info, md5) entry_md5 = state.get(path_info) assert entry_md5 == md5