def test_update(self): path = os.path.join(self.dvc.root_dir, '1') md5_1 = '1' md5_2 = '2' mtime_1 = 1 mtime_2 = 2 inode_1 = 1 inode_2 = 2 state = State(self.dvc.root_dir, self.dvc.dvc_dir) self.assertIsNone(state.get(path)) state.add(path, md5_1, mtime_1, inode_1) entry = state.get(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.path, path) self.assertEqual(entry.md5, md5_1) self.assertEqual(entry.mtime, mtime_1) self.assertEqual(entry.inode, inode_1) state.update(path, md5_2, mtime_2, inode_2) entry = state.get(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.path, path) self.assertEqual(entry.md5, md5_2) self.assertEqual(entry.mtime, mtime_2) self.assertEqual(entry.inode, inode_2)
def test_update(self): path = os.path.join(self.dvc.root_dir, self.FOO) md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) state = State(self.dvc.root_dir, self.dvc.dvc_dir) state.update(path) entry = state.get(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.md5, md5) self.assertEqual(entry.mtime, mtime) self.assertEqual(entry.inode, inode) os.chmod(path, stat.S_IWRITE) os.unlink(path) with open(path, 'w+') as fd: fd.write('1') md5 = file_md5(path)[0] mtime = os.path.getmtime(path) inode = System.inode(path) entry = state.update(path) self.assertIsInstance(entry, StateEntry) self.assertEqual(entry.md5, md5) self.assertEqual(entry.mtime, mtime) self.assertEqual(entry.inode, inode)
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