Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_url(path, repo=None, rev=None, remote=None):
"""Returns an url of a resource specified by path in repo"""
with _make_repo(repo, rev=rev) as _repo:
abspath = os.path.join(_repo.root_dir, path)
out, = _repo.find_outs_by_path(abspath)
(out,) = _repo.find_outs_by_path(abspath)
remote_obj = _repo.cloud.get_remote(remote)
return str(remote_obj.checksum_to_path_info(out.checksum))

Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def used_cache(

for stage in stages:
if stage.is_repo_import:
dep, = stage.deps
(dep,) = stage.deps
cache.external[dep.repo_pair].add(dep.def_path)
continue

Expand Down Expand Up @@ -445,7 +445,7 @@ def func(out):

def find_out_by_relpath(self, relpath):
path = os.path.join(self.root_dir, relpath)
out, = self.find_outs_by_path(path)
(out,) = self.find_outs_by_path(path)
return out

def is_dvc_internal(self, path):
Expand All @@ -457,7 +457,7 @@ def open(self, path, remote=None, mode="r", encoding=None):
"""Opens a specified resource as a file descriptor"""
cause = None
try:
out, = self.find_outs_by_path(path)
(out,) = self.find_outs_by_path(path)
except OutputNotFoundError as e:
out = None
cause = e
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/get_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def get_url(url, out=None):

out = os.path.abspath(out)

dep, = dependency.loads_from(None, [url])
out, = output.loads_from(None, [out], use_cache=False)
(dep,) = dependency.loads_from(None, [url])
(out,) = output.loads_from(None, [out], use_cache=False)
dep.download(out)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def run(self):
]

if (sys.version_info) >= (3, 6):
tests_requirements.append("black==19.3b0")
tests_requirements.append("black==19.10b0")

setup(
name="dvc",
Expand Down
8 changes: 4 additions & 4 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


def test_add(tmp_dir, dvc):
stage, = tmp_dir.dvc_gen({"foo": "foo"})
(stage,) = tmp_dir.dvc_gen({"foo": "foo"})
md5, _ = file_md5("foo")

assert stage is not None
Expand All @@ -50,7 +50,7 @@ def test_add_unicode(tmp_dir, dvc):
with open("\xe1", "wb") as fd:
fd.write("something".encode("utf-8"))

stage, = dvc.add("\xe1")
(stage,) = dvc.add("\xe1")

assert os.path.isfile(stage.path)

Expand All @@ -61,7 +61,7 @@ def test_add_unsupported_file(dvc):


def test_add_directory(tmp_dir, dvc):
stage, = tmp_dir.dvc_gen({"dir": {"file": "file"}})
(stage,) = tmp_dir.dvc_gen({"dir": {"file": "file"}})

assert stage is not None
assert len(stage.deps) == 0
Expand Down Expand Up @@ -162,7 +162,7 @@ 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)
(stage,) = dvc.add(subdir_path)

assert stage is not None
assert len(stage.deps) == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _set_remote_url_and_commit(repo, remote_url):

# FIXME: this test doesn't use scm ;D
def test_open_scm_controlled(dvc_repo, repo_dir):
stage, = dvc_repo.add(repo_dir.FOO)
(stage,) = dvc_repo.add(repo_dir.FOO)

stage_content = open(stage.path, "r").read()
with api.open(stage.path) as fd:
Expand Down
6 changes: 3 additions & 3 deletions tests/func/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_commit_recursive(tmp_dir, dvc):

def test_commit_force(tmp_dir, dvc):
tmp_dir.gen({"dir": {"file": "text1", "file2": "text2"}})
stage, = dvc.add("dir", no_commit=True)
(stage,) = dvc.add("dir", no_commit=True)

with dvc.state:
assert stage.outs[0].changed_cache()
Expand All @@ -42,7 +42,7 @@ def test_commit_force(tmp_dir, dvc):

def test_commit_with_deps(tmp_dir, dvc, run_copy):
tmp_dir.gen("foo", "foo")
foo_stage, = dvc.add("foo", no_commit=True)
(foo_stage,) = dvc.add("foo", no_commit=True)
assert foo_stage is not None
assert len(foo_stage.outs) == 1

Expand All @@ -62,7 +62,7 @@ def test_commit_with_deps(tmp_dir, dvc, run_copy):

def test_commit_changed_md5(tmp_dir, dvc):
tmp_dir.gen({"file": "file content"})
stage, = dvc.add("file", no_commit=True)
(stage,) = dvc.add("file", no_commit=True)

stage_file_content = load_stage_file(stage.path)
stage_file_content["md5"] = "1111111111"
Expand Down
28 changes: 0 additions & 28 deletions tests/func/test_destroy.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/func/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def test_all_commits(tmp_dir, scm, dvc):

def test_gc_no_dir_cache(tmp_dir, dvc, repo_template):
dvc.add(["foo", "bar"])
dir_stage, = dvc.add("dir")
(dir_stage,) = dvc.add("dir")

os.unlink(dir_stage.outs[0].cache_path)

Expand Down
98 changes: 40 additions & 58 deletions tests/func/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,53 @@
from dvc.ignore import DvcIgnore
from dvc.main import main
from dvc.repo import Repo
from dvc.scm.git import GitTree
from dvc.scm.tree import WorkingTree
from dvc.stage import Stage
from tests.basic_env import TestDvcGit
from dvc.system import System
from dvc.utils.compat import fspath


class TestCollect(TestDvcGit):
def setUp(self):
super(TestCollect, self).setUp()
self.dvc.add(self.FOO)
self.dvc.run(
deps=[self.FOO],
outs=[self.BAR],
cmd="python code.py {} {}".format(self.FOO, self.BAR),
)
self.dvc.scm.add([".gitignore", self.FOO + ".dvc", self.BAR + ".dvc"])
self.dvc.scm.commit("foo.dvc and bar.dvc")
self.dvc.scm.checkout("new_branch", True)
self.dvc.run(
deps=[self.BAR],
outs=["buzz"],
cmd="python code.py {} {}".format(self.BAR, "buzz"),
)
self.dvc.scm.add([".gitignore", "buzz.dvc"])
self.dvc.scm.commit("add buzz")
self.dvc.scm.checkout("master")
def test_destroy(tmp_dir, dvc):
dvc.config.set("cache", "type", "symlink")

def _check(self, branch, target, with_deps, expected):
if branch:
self.dvc.tree = GitTree(self.dvc.scm.repo, branch)
else:
self.dvc.tree = WorkingTree()
result = self.dvc.collect(target + ".dvc", with_deps=with_deps)
self.assertEqual([[str(j) for j in i.outs] for i in result], expected)
return result
tmp_dir.dvc_gen("file", "text")
tmp_dir.dvc_gen({"dir": {"file": "lorem", "subdir/file": "ipsum"}})

def test(self):
self._check("", self.BAR, True, [[self.FOO], [self.BAR]])
self._check("master", self.BAR, True, [[self.FOO], [self.BAR]])
self._check(
"new_branch", "buzz", True, [[self.FOO], [self.BAR], ["buzz"]]
)
result = self._check("new_branch", "buzz", False, [["buzz"]])
self.assertEqual([str(i) for i in result[0].deps], ["bar"])
dvc.destroy()

# Remove all the files related to DVC
for path in [".dvc", "file.dvc", "dir.dvc"]:
assert not (tmp_dir / path).exists()

# Leave the rest of the files
for path in ["file", "dir/file", "dir/subdir/file"]:
assert (tmp_dir / path).is_file()

# Make sure that data was unprotected after `destroy`
for path in ["file", "dir", "dir/file", "dir/subdir", "dir/subdir/file"]:
assert not System.is_symlink(fspath(tmp_dir / path))


def test_collect(tmp_dir, scm, dvc, run_copy):
def collect_outs(*args, **kwargs):
return set(
str(out.path_info)
for stage in dvc.collect(*args, **kwargs)
for out in stage.outs
)

class TestIgnore(TestDvcGit):
def _stage_name(self, file):
return file + Stage.STAGE_FILE_SUFFIX
tmp_dir.dvc_gen("foo", "foo")
run_copy("foo", "bar")
assert collect_outs("bar.dvc", with_deps=True) == {"foo", "bar"}

def test_should_not_gather_stage_files_from_ignored_dir(self):
ret = main(["add", self.FOO, self.BAR, self.DATA, self.DATA_SUB])
self.assertEqual(0, ret)
run_copy("bar", "buzz")
assert collect_outs("buzz.dvc", with_deps=True) == {"foo", "bar", "buzz"}
assert collect_outs("buzz.dvc", with_deps=False) == {"buzz"}

stages = self.dvc.stages
self.assertEqual(4, len(stages))

self.create(DvcIgnore.DVCIGNORE_FILE, self.DATA_DIR)
def test_stages(tmp_dir, dvc):
def stages():
return set(stage.relpath for stage in Repo(str(tmp_dir)).stages)

self.dvc = Repo(self.dvc.root_dir)
stages = self.dvc.stages
self.assertEqual(2, len(stages))
tmp_dir.dvc_gen({"file": "a", "dir/file": "b", "dir/subdir/file": "c"})
assert stages() == {"file.dvc", "dir/file.dvc", "dir/subdir/file.dvc"}

stagenames = [s.relpath for s in stages]
self.assertIn(self._stage_name(self.FOO), stagenames)
self.assertIn(self._stage_name(self.BAR), stagenames)
self.assertNotIn(self._stage_name(self.DATA), stagenames)
self.assertNotIn(self._stage_name(self.DATA_SUB), stagenames)
tmp_dir.gen(".dvcignore", "dir")
assert stages() == {"file.dvc"}
4 changes: 2 additions & 2 deletions tests/func/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_remote_dependency(self):


def test_md5_ignores_comments(repo_dir, dvc_repo):
stage, = dvc_repo.add("foo")
(stage,) = dvc_repo.add("foo")

with open(stage.path, "a") as f:
f.write("# End comment\n")
Expand All @@ -165,7 +165,7 @@ def test_md5_ignores_comments(repo_dir, dvc_repo):


def test_meta_is_preserved(dvc_repo):
stage, = dvc_repo.add("foo")
(stage,) = dvc_repo.add("foo")

# Add meta to DVC-file
data = load_stage_file(stage.path)
Expand Down
15 changes: 4 additions & 11 deletions tests/unit/test_repo.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import os
from dvc.utils.compat import fspath

from tests.basic_env import TestDvc


class TestIsDvcInternal(TestDvc):
def test_return_false_on_non_dvc_file(self):
path = os.path.join("path", "to-non-.dvc", "file")
self.assertFalse(self.dvc.is_dvc_internal(path))

def test_return_true_on_dvc_internal_file(self):
path = os.path.join("path", "to", ".dvc", "file")
self.assertTrue(path)
def test_is_dvc_internal(tmp_dir, dvc):
assert dvc.is_dvc_internal(fspath(tmp_dir / ".dvc" / "file"))
assert not dvc.is_dvc_internal("file")