From 4d142569957ac103d11302b08cba711e23c64563 Mon Sep 17 00:00:00 2001 From: Dani Hodovic Date: Sat, 23 Nov 2019 14:57:56 +0100 Subject: [PATCH] fixup! get: copy regular files --- tests/basic_env.py | 13 ++++++++++--- tests/func/test_get.py | 10 +++++----- tests/func/test_repro.py | 8 ++++---- tests/func/test_tree.py | 9 ++++++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/tests/basic_env.py b/tests/basic_env.py index a2f059df6..d27130fbf 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -41,14 +41,19 @@ class TestDirFixture(object): # in tests, we replace foo with bar, so we need to make sure that when we # modify a file in our tests, its content length changes. BAR_CONTENTS = BAR + "r" - CODE_DIR = "code" - CODE = "code/code.py" + CODE = "code.py" CODE_CONTENTS = ( "import sys\nimport shutil\n" "shutil.copyfile(sys.argv[1], sys.argv[2])" ) UNICODE = "тест" UNICODE_CONTENTS = "проверка" + REGULAR_DIR = "lib" + REGULAR_FILE = os.path.join(REGULAR_DIR, "file.txt") + REGULAR_FILE_CONTENTS = """ + A file used to test retrieval of regular files tracked by git that + are not stored in a dvc remote backend. + """ def __init__(self): root_dir = self.mkdtemp() @@ -91,13 +96,14 @@ class TestDirFixture(object): self._pushd(self._root_dir) self.create(self.FOO, self.FOO_CONTENTS) self.create(self.BAR, self.BAR_CONTENTS) - os.mkdir(self.CODE_DIR) self.create(self.CODE, self.CODE_CONTENTS) os.mkdir(self.DATA_DIR) os.mkdir(self.DATA_SUB_DIR) self.create(self.DATA, self.DATA_CONTENTS) self.create(self.DATA_SUB, self.DATA_SUB_CONTENTS) self.create(self.UNICODE, self.UNICODE_CONTENTS) + os.mkdir(self.REGULAR_DIR) + self.create(self.REGULAR_FILE, self.REGULAR_FILE_CONTENTS) def tearDown(self): self._popd() @@ -139,6 +145,7 @@ class TestGitFixture(TestDirFixture): raise self.git.index.add([self.CODE]) + self.git.index.add([self.REGULAR_DIR]) self.git.index.commit("add code") def tearDown(self): diff --git a/tests/func/test_get.py b/tests/func/test_get.py index 7c2fccfe4..e66f0d96b 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -39,19 +39,19 @@ def test_get_repo_dir(erepo): def test_get_regular_file(repo_dir, erepo): - src = erepo.CODE - dst = erepo.CODE + src = erepo.REGULAR_FILE + dst = erepo.REGULAR_FILE + "_imported" Repo.get(erepo.root_dir, src, dst) assert os.path.exists(dst) assert os.path.isfile(dst) - assert filecmp.cmp(repo_dir.CODE, dst, shallow=False) + assert filecmp.cmp(src, dst, shallow=False) def test_get_regular_dir(repo_dir, erepo): - src = erepo.CODE_DIR - dst = erepo.CODE_DIR + src = erepo.REGULAR_DIR + dst = erepo.REGULAR_DIR + "_imported" Repo.get(erepo.root_dir, src, dst) diff --git a/tests/func/test_repro.py b/tests/func/test_repro.py index 5caf5c40e..a85995fe9 100644 --- a/tests/func/test_repro.py +++ b/tests/func/test_repro.py @@ -738,9 +738,9 @@ class TestCmdReproChdirCwdBackwardCompatible(TestDvc): os.mkdir(dname) foo = os.path.join(dname, self.FOO) bar = os.path.join(dname, self.BAR) - code_dir = os.path.join(dname, self.CODE_DIR) + code = os.path.join(dname, self.CODE) shutil.copyfile(self.FOO, foo) - shutil.copytree(self.CODE_DIR, code_dir) + shutil.copyfile(self.CODE, code) ret = main( [ @@ -776,9 +776,9 @@ class TestCmdReproChdir(TestDvc): os.mkdir(dname) foo = os.path.join(dname, self.FOO) bar = os.path.join(dname, self.BAR) - code_dir = os.path.join(dname, self.CODE_DIR) + code = os.path.join(dname, self.CODE) shutil.copyfile(self.FOO, foo) - shutil.copytree(self.CODE_DIR, code_dir) + shutil.copyfile(self.CODE, code) ret = main( [ diff --git a/tests/func/test_tree.py b/tests/func/test_tree.py index c2ae316c2..656303525 100644 --- a/tests/func/test_tree.py +++ b/tests/func/test_tree.py @@ -115,9 +115,10 @@ class TestWalkInNoSCM(AssertWalkEqualMixin, TestDir): [ ( self._root_dir, - ["data_dir"], + ["lib", "data_dir"], ["code.py", "bar", "тест", "foo"], ), + (join(self._root_dir, "lib"), [], ["file.txt"]), (join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]), ( join(self._root_dir, "data_dir", "data_sub_dir"), @@ -151,9 +152,10 @@ class TestWalkInGit(AssertWalkEqualMixin, TestGit): [ ( self._root_dir, - ["data_dir"], + ["lib", "data_dir"], ["bar", "тест", "code.py", "foo"], ), + (join(self._root_dir, "lib"), [], ["file.txt"]), (join(self._root_dir, "data_dir"), ["data_sub_dir"], ["data"]), ( join(self._root_dir, "data_dir", "data_sub_dir"), @@ -181,13 +183,14 @@ class TestWalkInGit(AssertWalkEqualMixin, TestGit): self.assertWalkEqual( tree.walk("."), [ - (self._root_dir, ["data_dir"], ["code.py"]), + (self._root_dir, ["data_dir", "lib"], ["code.py"]), (join(self._root_dir, "data_dir"), ["data_sub_dir"], []), ( join(self._root_dir, "data_dir", "data_sub_dir"), [], ["data_sub"], ), + (join(self._root_dir, "lib"), [], ["file.txt"]), ], ) self.assertWalkEqual(