def test_remove(tmp_dir, scm, dvc, run_copy, remove_outs): (stage1, ) = tmp_dir.dvc_gen("foo", "foo") stage2 = run_copy("foo", "bar", single_stage=True) stage3 = run_copy("bar", "foobar", name="copy-bar-foobar") assert "/foo" in get_gitignore_content() assert "/bar" in get_gitignore_content() assert "/foobar" in get_gitignore_content() for stage in [stage1, stage2, stage3]: dvc.remove(stage.addressing, outs=remove_outs) out_exists = (out.exists for out in stage.outs) assert stage not in dvc.stage.collect_repo() if remove_outs: assert not any(out_exists) else: assert all(out_exists) assert not (tmp_dir / ".gitignore").exists()
def test_escape_gitignore_entries(tmp_dir, scm, dvc): fname = "file!with*weird#naming_[1].t?t" ignored_fname = r"/file\!with\*weird\#naming_\[1\].t\?t" if os.name == "nt": # Some characters are not supported by Windows in the filename # https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file fname = "file!with_weird#naming_[1].txt" ignored_fname = r"/file\!with_weird\#naming_\[1\].txt" tmp_dir.dvc_gen(fname, "...") assert ignored_fname in get_gitignore_content()
def test_should_cleanup_after_failed_add(tmp_dir, scm, dvc, repo_template): # Add and corrupt a stage file dvc.add("foo") tmp_dir.gen("foo.dvc", "- broken\nyaml") with pytest.raises(StageFileCorruptedError): dvc.add("bar") assert not os.path.exists("bar.dvc") gitignore_content = get_gitignore_content() assert "/bar" not in gitignore_content
def test_failed_add_cleanup(tmp_dir, scm, dvc): tmp_dir.gen({"foo": "foo", "bar": "bar"}) # Add and corrupt a stage file dvc.add("foo") tmp_dir.gen("foo.dvc", "- broken\nyaml") with pytest.raises(YAMLFileCorruptedError): dvc.add("bar") assert not os.path.exists("bar.dvc") gitignore_content = get_gitignore_content() assert "/bar" not in gitignore_content
def test_escape_gitignore_entries(git, dvc_repo, repo_dir): fname = "file!with*weird#naming_[1].t?t" ignored_fname = r"/file\!with\*weird\#naming_\[1\].t\?t" if os.name == "nt": # Some characters are not supported by Windows in the filename # https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file fname = "file!with_weird#naming_[1].txt" ignored_fname = r"/file\!with_weird\#naming_\[1\].txt" os.rename(repo_dir.FOO, fname) dvc_repo.add(fname) assert ignored_fname in get_gitignore_content()
def test_should_cleanup_after_failed_add(git, dvc_repo, repo_dir): stages = dvc_repo.add(repo_dir.FOO) assert len(stages) == 1 foo_stage_file = repo_dir.FOO + Stage.STAGE_FILE_SUFFIX # corrupt stage file repo_dir.create(foo_stage_file, "this will break yaml structure") with pytest.raises(StageFileCorruptedError): dvc_repo.add(repo_dir.BAR) bar_stage_file = repo_dir.BAR + Stage.STAGE_FILE_SUFFIX assert not os.path.exists(bar_stage_file) gitignore_content = get_gitignore_content() assert "/" + repo_dir.BAR not in gitignore_content
def test(self): ret = main(["add", self.FOO]) self.assertEqual(0, ret) foo_stage_file = self.FOO + Stage.STAGE_FILE_SUFFIX # corrupt stage file with open(foo_stage_file, "a+") as file: file.write("this will break yaml file structure") ret = main(["add", self.BAR]) self.assertEqual(1, ret) bar_stage_file = self.BAR + Stage.STAGE_FILE_SUFFIX self.assertFalse(os.path.exists(bar_stage_file)) gitignore_content = get_gitignore_content() self.assertNotIn("/" + self.BAR, gitignore_content)
def _count_gitignore_entries(string): lines = get_gitignore_content() return len([i for i in lines if i == string])
def test_add_with_out(tmp_dir, scm, dvc): tmp_dir.gen({"foo": "foo"}) dvc.add("foo", out="out_foo") gitignore_content = get_gitignore_content() assert "/out_foo" in gitignore_content
def _count_gitignore_entries(line): lines = get_gitignore_content() return lines.count(line)
def _count_gitignore(self): lines = get_gitignore_content() return len([i for i in lines if i == "/" + self.FOO])
def _count_gitignore(self): lines = get_gitignore_content() return len(list(filter(lambda x: x.strip() == "/" + self.FOO, lines)))