Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Jan 22, 2020
1 parent e41aa00 commit fc92266
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 55 deletions.
10 changes: 1 addition & 9 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand All @@ -29,8 +29,6 @@
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"})
Expand Down Expand Up @@ -246,12 +244,6 @@ def test_dir(self):
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")
Expand Down
31 changes: 3 additions & 28 deletions tests/func/test_import_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

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):
Expand Down Expand Up @@ -42,34 +40,11 @@ def test(self):
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
Expand Down
30 changes: 12 additions & 18 deletions tests/unit/utils/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ def test(self):


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")
Expand All @@ -73,20 +69,6 @@ def test_should_return_false_on_no_more_dirs_below_path(
)
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"
Expand All @@ -111,6 +93,18 @@ def test_path_object_and_str_are_valid_arg_types(self):
)


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")
Expand Down

0 comments on commit fc92266

Please sign in to comment.