def test(self): file_md5_counter = spy(dvc.remote.local.file_md5) with patch.object(dvc.remote.local, "file_md5", file_md5_counter): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) ret = main(["add", self.FOO]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) ret = main(["run", "-d", self.FOO, "echo foo"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) os.rename(self.FOO, self.FOO + ".back") ret = main(["checkout"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1)
def test(self): from dvc.remote.local import RemoteLOCAL collect_dir_counter = spy(RemoteLOCAL.collect_dir_cache) with patch.object(RemoteLOCAL, "collect_dir_cache", collect_dir_counter): LARGE_DIR_FILES_NUM = self.NEW_LARGE_DIR_SIZE + 1 data_dir = "dir" os.makedirs(data_dir) for i in range(LARGE_DIR_FILES_NUM): with open(os.path.join(data_dir, str(i)), "w+") as f: f.write(str(i)) ret = main(["add", data_dir]) self.assertEqual(0, ret) ret = main(["status"]) self.assertEqual(0, ret) ret = main(["status"]) self.assertEqual(0, ret) self.assertEqual(1, collect_dir_counter.mock.call_count)
def test(self): file_md5_counter = spy(dvc.remote.local.file_md5) with patch.object(dvc.remote.local, "file_md5", file_md5_counter): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) ret = main(["add", self.DATA_DIR]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) ls = "dir" if os.name == "nt" else "ls" ret = main([ "run", "-d", self.DATA_DIR, "{} {}".format(ls, self.DATA_DIR) ]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) os.rename(self.DATA_DIR, self.DATA_DIR + ".back") ret = main(["checkout"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3)
def test(self): remove_outs_call_counter = spy(dvc.stage.Stage.remove_outs) with patch.object(dvc.stage.Stage, "remove_outs", remove_outs_call_counter): ret = main(["import-url", self.external_source]) self.assertEqual(0, ret) self.assertEqual(1, remove_outs_call_counter.mock.call_count)
def test(self): test_collect = spy(State._collect) with patch.object(State, "_collect", test_collect): url = get_local_url() main(["remote", "add", "-d", TEST_REMOTE, url]) main(["add", self.FOO]) main(["push"]) main(["run", "-d", self.FOO, "echo foo"]) self.assertEqual(test_collect.mock.call_count, 1)
def test_should_call_recursive_on_no_condition_matched(self, _, __): contains_symlink_spy = spy(contains_symlink_up_to) with patch.object( dvc.utils.fs, "contains_symlink_up_to", contains_symlink_spy ): # call from full path to match contains_symlink_spy patch path self.assertFalse(dvc.utils.fs.contains_symlink_up_to("path")) self.assertEqual(2, contains_symlink_spy.mock.call_count)
def test(self): stage_creator_spy = spy(dvc.repo.add._create_stages) with patch.object(dvc.repo.add, "_create_stages", stage_creator_spy): ret = main(["add", "-R", self.dvc.root_dir]) self.assertEqual(0, ret) created_stages_filenames = stage_creator_spy.mock.call_args[0][0] for fname in created_stages_filenames: self.assertNotIn(".git", fname)
def test_should_relink_only_one_file_in_dir(dvc_repo, repo_dir): dvc_repo.cache.local.cache_types = ["symlink"] dvc_repo.add(repo_dir.DATA_DIR) dvc_repo.unprotect(repo_dir.DATA_SUB) link_spy = spy(System.symlink) with patch.object(dvc_repo.cache.local, "symlink", link_spy): dvc_repo.checkout(repo_dir.DATA_DIR + Stage.STAGE_FILE_SUFFIX) assert link_spy.mock.call_count == 1
def test_should_not_checkout_when_adding_cached_copy(tmp_dir, dvc, mocker): dvc.cache.local.cache_types = ["copy"] tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"}) shutil.copy("bar", "foo") copy_spy = spy(dvc.cache.local.copy) mocker.patch.object(dvc.cache.local, "copy", copy_spy) dvc.add("foo") assert copy_spy.mock.call_count == 0
def test_should_not_checkout_when_adding_cached_copy(repo_dir, dvc_repo): dvc_repo.cache.local.cache_types = ["copy"] dvc_repo.add(repo_dir.FOO) dvc_repo.add(repo_dir.BAR) shutil.copy(repo_dir.BAR, repo_dir.FOO) copy_spy = spy(dvc_repo.cache.local.copy) with patch.object(dvc_repo.cache.local, "copy", copy_spy): dvc_repo.add(repo_dir.FOO) assert copy_spy.mock.call_count == 0
def test_should_not_checkout_when_adding_cached_copy(repo_dir, dvc_repo): dvc_repo.cache.local.cache_types = ["copy"] dvc_repo.add(repo_dir.FOO) dvc_repo.add(repo_dir.BAR) shutil.copy(repo_dir.BAR, repo_dir.FOO) copy_spy = spy(shutil.copyfile) RemoteLOCAL.CACHE_TYPE_MAP["copy"] = copy_spy dvc_repo.add(repo_dir.FOO) assert copy_spy.mock.call_count == 0
def test_should_relink_single_file_in_dir(link, link_func, dvc_repo, repo_dir): dvc_repo.cache.local.cache_types = [link] dvc_repo.add(repo_dir.DATA_DIR) # NOTE status triggers unpacked dir creation for hardlink case dvc_repo.status() dvc_repo.unprotect(repo_dir.DATA_SUB) link_spy = spy(link_func) RemoteLOCAL.CACHE_TYPE_MAP[link] = link_spy dvc_repo.add(repo_dir.DATA_DIR) assert link_spy.mock.call_count == 1
def test_readding_dir_should_not_unprotect_all(dvc_repo, repo_dir): dvc_repo.cache.local.cache_types = ["symlink"] dvc_repo.cache.local.protected = True dvc_repo.add(repo_dir.DATA_DIR) new_file = os.path.join(repo_dir.DATA_DIR, "new_file") repo_dir.create(new_file, "new_content") unprotect_spy = spy(RemoteLOCAL.unprotect) with patch.object(RemoteLOCAL, "unprotect", unprotect_spy): dvc_repo.add(repo_dir.DATA_DIR) assert not unprotect_spy.mock.called assert System.is_symlink(new_file)
def test(self): from dvc.remote.local import RemoteLOCAL get_dir_checksum_counter = spy(RemoteLOCAL.get_dir_checksum) with patch.object(RemoteLOCAL, "get_dir_checksum", get_dir_checksum_counter): ret = main(["add", self.DATA_DIR]) self.assertEqual(0, ret) ret = main(["status"]) self.assertEqual(0, ret) ret = main(["status"]) self.assertEqual(0, ret) self.assertEqual(1, get_dir_checksum_counter.mock.call_count)
def test_readding_dir_should_not_unprotect_all(tmp_dir, dvc, mocker): tmp_dir.gen("dir/data", "data") dvc.cache.local.cache_types = ["symlink"] dvc.cache.local.protected = True dvc.add("dir") tmp_dir.gen("dir/new_file", "new_file_content") unprotect_spy = spy(RemoteLOCAL.unprotect) mocker.patch.object(RemoteLOCAL, "unprotect", unprotect_spy) dvc.add("dir") assert not unprotect_spy.mock.called assert System.is_symlink(os.path.join("dir", "new_file"))
def test(self): test_get_file_checksum = spy(RemoteLOCAL.get_file_checksum) with patch.object(RemoteLOCAL, "get_file_checksum", test_get_file_checksum): url = Local.get_url() ret = main(["remote", "add", "-d", TEST_REMOTE, url]) self.assertEqual(ret, 0) ret = main(["config", "cache.type", "hardlink"]) self.assertEqual(ret, 0) ret = main(["add", self.FOO]) self.assertEqual(ret, 0) ret = main(["push"]) self.assertEqual(ret, 0) ret = main(["run", "-d", self.FOO, "echo foo"]) self.assertEqual(ret, 0) self.assertEqual(test_get_file_checksum.mock.call_count, 1)
def test(self): file_md5_counter = spy(dvc.remote.local.file_md5) with patch.object(dvc.remote.local, "file_md5", file_md5_counter): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) ret = main(["add", self.FOO]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1) ret = main(["run", "-d", self.FOO, "cat {}".format(self.FOO)]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 1)
def test(self): remote_local_loader_spy = spy( dvc.remote.local.RemoteLOCAL.load_dir_cache) with patch.object( dvc.remote.local.RemoteLOCAL, "load_dir_cache", remote_local_loader_spy, ): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) ret = main(["add", self.DATA_DIR]) self.assertEqual(ret, 0) self.assertEqual(1, remote_local_loader_spy.mock.call_count) ret = main(["status", "{}.dvc".format(self.DATA_DIR)]) self.assertEqual(ret, 0) self.assertEqual(1, remote_local_loader_spy.mock.call_count)
def test(self): file_md5_counter = spy(dvc.state.file_md5) with patch.object(dvc.state, "file_md5", file_md5_counter): ret = main(["config", "cache.type", "copy"]) self.assertEqual(ret, 0) ret = main(["add", self.DATA_DIR]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) ret = main(["status"]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3) ret = main( ["run", "-d", self.DATA_DIR, "ls {}".format(self.DATA_DIR)]) self.assertEqual(ret, 0) self.assertEqual(file_md5_counter.mock.call_count, 3)