address comments

This commit is contained in:
Fábio Santos
2020-01-22 17:31:46 +00:00
parent e41aa00c20
commit fc92266114
3 changed files with 16 additions and 55 deletions
+1 -9
View File
@@ -9,7 +9,7 @@ import colorama
import pytest
from mock import patch
import dvc
import dvc as dvc_module
from dvc.cache import Cache
from dvc.exceptions import DvcException
from dvc.exceptions import RecursiveAddingWhileUsingFilename
@@ -29,8 +29,6 @@ from dvc.utils.stage import load_stage_file
from tests.basic_env import TestDvc
from tests.utils import get_gitignore_content
dvc_module = dvc # to disambiguate between the module and the fixture
def test_add(tmp_dir, dvc):
stage, = tmp_dir.dvc_gen({"foo": "foo"})
@@ -246,12 +244,6 @@ class TestDoubleAddUnchanged(TestDvc):
self.assertEqual(ret, 0)
class TestDvcWithMocker(TestDvc):
@pytest.fixture(autouse=True)
def use_mocker(self, mocker):
self.mocker = mocker
def test_should_update_state_entry_for_file_after_add(mocker, dvc, tmp_dir):
file_md5_counter = mocker.spy(dvc_module.remote.local, "file_md5")
tmp_dir.gen("foo", "foo")
+3 -28
View File
@@ -3,13 +3,11 @@ from uuid import uuid4
import pytest
import dvc
from dvc.stage import Stage
from dvc.main import main
from dvc.utils.fs import makedirs
from dvc.compat import fspath
from tests.basic_env import TestDvc
from tests.dir_helpers import TmpDir
class TestCmdImport(TestDvc):
@@ -42,34 +40,11 @@ class TestDefaultOutput(TestDvc):
self.assertEqual(fd.read(), "content")
class TestShouldRemoveOutsBeforeImport(TestDvc):
@pytest.fixture(autouse=True)
def use_mocker(self, mocker):
self.mocker = mocker
def setUp(self):
super().setUp()
tmp_dir = self.mkdtemp()
self.external_source = os.path.join(tmp_dir, "file")
with open(self.external_source, "w") as fobj:
fobj.write("content")
def test(self):
remove_outs_call_counter = self.mocker.spy(
dvc.stage.Stage, "remove_outs"
)
ret = main(["import-url", self.external_source])
self.assertEqual(0, ret)
self.assertEqual(1, remove_outs_call_counter.mock.call_count)
def test_should_remove_outs_before_import(mocker, dvc, tmp_path_factory):
import_dir = TmpDir(tmp_path_factory.mktemp("import"))
import_dir.gen({"foo": "foo"})
def test_should_remove_outs_before_import(mocker, erepo_dir):
erepo_dir.gen({"foo": "foo"})
remove_outs_call_counter = mocker.spy(Stage, "remove_outs")
ret = main(["import-url", fspath(import_dir / "foo")])
ret = main(["import-url", fspath(erepo_dir / "foo")])
assert ret == 0
assert remove_outs_call_counter.mock.call_count == 1
+12 -18
View File
@@ -44,10 +44,6 @@ class TestMtimeAndSize(TestDir):
class TestContainsLink(TestCase):
@pytest.fixture(autouse=True)
def use_mocker(self, mocker):
self.mocker = mocker
def test_should_raise_exception_on_base_path_not_in_path(self):
with self.assertRaises(BasePathNotInCheckedPathException):
contains_symlink_up_to(os.path.join("foo", "path"), "bar")
@@ -73,20 +69,6 @@ class TestContainsLink(TestCase):
)
dirname_patch.assert_called_once()
@patch.object(System, "is_symlink", return_value=False)
def test_should_call_recursive_on_no_condition_matched(self, _):
contains_symlink_spy = self.mocker.spy(
dvc.utils.fs, "contains_symlink_up_to"
)
# call from full path to match contains_symlink_spy patch path
self.assertFalse(
dvc.utils.fs.contains_symlink_up_to(
os.path.join("foo", "path"), "foo"
)
)
self.assertEqual(2, contains_symlink_spy.mock.call_count)
@patch.object(System, "is_symlink", return_value=True)
def test_should_return_false_when_base_path_is_symlink(self, _):
base_path = "foo"
@@ -111,6 +93,18 @@ class TestContainsLink(TestCase):
)
def test_should_call_recursive_on_no_condition_matched(mocker):
mocker.patch.object(System, "is_symlink", return_value=False)
contains_symlink_spy = mocker.spy(dvc.utils.fs, "contains_symlink_up_to")
# call from full path to match contains_symlink_spy patch path
assert not dvc.utils.fs.contains_symlink_up_to(
os.path.join("foo", "path"), "foo"
)
assert contains_symlink_spy.mock.call_count == 2
@pytest.mark.skipif(os.name != "nt", reason="Windows specific")
def test_relpath_windows_different_drives():
path1 = os.path.join("A:", os.sep, "some", "path")