class TestCheckoutCorruptedCacheDir(TestDvc): def test(self): time.sleep(1) # NOTE: using 'copy' so that cache and link don't have same inode ret = main(['config', 'cache.type', 'copy']) self.assertEqual(ret, 0) self.dvc = Project('.') stages = self.dvc.add(self.DATA_DIR) self.assertEqual(len(stages), 1) self.assertEqual(len(stages[0].outs), 1) out = stages[0].outs[0] # NOTE: modifying cache file for one of the files inside the directory # to check if dvc will detect that the cache is corrupted. entry = self.dvc.cache.local.load_dir_cache(out.md5)[0] md5 = entry[self.dvc.cache.local.PARAM_MD5] cache = self.dvc.cache.local.get(md5) with open(cache, 'w+') as fobj: fobj.write('1') self.dvc.checkout(force=True) self.assertFalse(os.path.exists(cache))
class TestCheckoutCorruptedCacheDir(TestDvc): def test(self): # NOTE: using 'copy' so that cache and link don't have same inode ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) self.dvc = Project(".") stages = self.dvc.add(self.DATA_DIR) self.assertEqual(len(stages), 1) self.assertEqual(len(stages[0].outs), 1) out = stages[0].outs[0] # NOTE: modifying cache file for one of the files inside the directory # to check if dvc will detect that the cache is corrupted. entry = self.dvc.cache.local.load_dir_cache(out.checksum)[0] checksum = entry[self.dvc.cache.local.PARAM_CHECKSUM] cache = self.dvc.cache.local.get(checksum) with open(cache, "w+") as fobj: fobj.write("1") self.dvc.checkout(force=True) self.assertFalse(os.path.exists(cache))
class TestGCMultipleProjects(TestDvc): def _check_cache(self, num): total = 0 for root, dirs, files in os.walk(os.path.join('.dvc', 'cache')): total += len(files) self.assertEqual(total, num) def setUp(self): super(TestGCMultipleProjects, self).setUp() self.additional_path = TestDir.mkdtemp() self.additional_git = Repo.init(self.additional_path) self.additional_dvc = Project.init(self.additional_path) cache_path = os.path.join(self._root_dir, '.dvc', 'cache') config_path = os.path.join(self.additional_path, '.dvc', 'config.local') cfg = configobj.ConfigObj() cfg.filename = config_path cfg['cache'] = {'dir': cache_path} cfg.write() self.additional_dvc = Project(self.additional_path) def test(self): # ADD FILE ONLY IN MAIN PROJECT fname = 'only_in_first' with open(fname, 'w+') as fobj: fobj.write('only in main project') stages = self.dvc.add(fname) self.assertEqual(len(stages), 1) # ADD FILE IN MAIN PROJECT THAT IS ALSO IN SECOND PROJECT fname = 'in_both' with open(fname, 'w+') as fobj: fobj.write('in both projects') stages = self.dvc.add(fname) self.assertEqual(len(stages), 1) cwd = os.getcwd() os.chdir(self.additional_path) # ADD FILE ONLY IN SECOND PROJECT fname = os.path.join(self.additional_path, 'only_in_second') with open(fname, 'w+') as fobj: fobj.write('only in additional project') stages = self.additional_dvc.add(fname) self.assertEqual(len(stages), 1) # ADD FILE IN SECOND PROJECT THAT IS ALSO IN MAIN PROJECT fname = os.path.join(self.additional_path, 'in_both') with open(fname, 'w+') as fobj: fobj.write('in both projects') stages = self.additional_dvc.add(fname) self.assertEqual(len(stages), 1) os.chdir(cwd) self._check_cache(3) self.dvc.gc(projects=[self.additional_path]) self._check_cache(3) self.dvc.gc() self._check_cache(2)
class TestGCMultipleProjects(TestDvc): def _check_cache(self, num): total = 0 for root, dirs, files in os.walk(os.path.join(".dvc", "cache")): total += len(files) self.assertEqual(total, num) def setUp(self): super(TestGCMultipleProjects, self).setUp() self.additional_path = TestDir.mkdtemp() self.additional_git = Repo.init(self.additional_path) self.additional_dvc = Project.init(self.additional_path) cache_path = os.path.join(self._root_dir, ".dvc", "cache") config_path = os.path.join(self.additional_path, ".dvc", "config.local") cfg = configobj.ConfigObj() cfg.filename = config_path cfg["cache"] = {"dir": cache_path} cfg.write() self.additional_dvc = Project(self.additional_path) def test(self): # ADD FILE ONLY IN MAIN PROJECT fname = "only_in_first" with open(fname, "w+") as fobj: fobj.write("only in main project") stages = self.dvc.add(fname) self.assertEqual(len(stages), 1) # ADD FILE IN MAIN PROJECT THAT IS ALSO IN SECOND PROJECT fname = "in_both" with open(fname, "w+") as fobj: fobj.write("in both projects") stages = self.dvc.add(fname) self.assertEqual(len(stages), 1) cwd = os.getcwd() os.chdir(self.additional_path) # ADD FILE ONLY IN SECOND PROJECT fname = os.path.join(self.additional_path, "only_in_second") with open(fname, "w+") as fobj: fobj.write("only in additional project") stages = self.additional_dvc.add(fname) self.assertEqual(len(stages), 1) # ADD FILE IN SECOND PROJECT THAT IS ALSO IN MAIN PROJECT fname = os.path.join(self.additional_path, "in_both") with open(fname, "w+") as fobj: fobj.write("in both projects") stages = self.additional_dvc.add(fname) self.assertEqual(len(stages), 1) os.chdir(cwd) self._check_cache(3) self.dvc.gc(projects=[self.additional_path]) self._check_cache(3) self.dvc.gc() self._check_cache(2)