def test_should_protect_on_repeated_add(link, tmp_dir, dvc): dvc.cache.local.cache_types = [link] dvc.cache.local.protected = True tmp_dir.dvc_gen({"foo": "foo"}) dvc.unprotect("foo") dvc.add("foo") assert not os.access("foo", os.W_OK)
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_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_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(StageFileCorruptedError): dvc.add("bar") assert not os.path.exists("bar.dvc") gitignore_content = get_gitignore_content() assert "/bar" not in gitignore_content
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_should_relink_on_repeated_add( link, new_link, link_test_func, tmp_dir, dvc ): dvc.config.set("cache", "type", link) tmp_dir.dvc_gen({"foo": "foo", "bar": "bar"}) os.remove("foo") getattr(dvc.cache.local, link)("bar", "foo") dvc.cache.local.cache_types = [new_link] dvc.add("foo") assert link_test_func("foo")
def test_add_unicode(tmp_dir, dvc): with open("\xe1", "wb") as fd: fd.write("something".encode("utf-8")) stage, = dvc.add("\xe1") assert os.path.isfile(stage.path)
def test_add_file_in_dir(tmp_dir, dvc): tmp_dir.gen({"dir": {"subdir": {"subdata": "subdata content"}}}) subdir_path = os.path.join("dir", "subdir", "subdata") stage, = dvc.add(subdir_path) assert stage is not None assert len(stage.deps) == 0 assert len(stage.outs) == 1 assert stage.relpath == subdir_path + ".dvc" # Current dir should not be taken into account assert stage.wdir == os.path.dirname(stage.path) assert stage.outs[0].def_path == "subdata"
def test_add_tracked_file(tmp_dir, scm, dvc): tmp_dir.scm_gen("tracked_file", "...", commit="add tracked file") with pytest.raises(OutputAlreadyTrackedError): dvc.add("tracked_file")
def test_add_unsupported_file(dvc): with pytest.raises(DvcException): dvc.add("unsupported://unsupported")