move: awareness of cwd when moving files

fix #1636
This commit is contained in:
Mr. Outis
2019-02-19 11:55:43 -06:00
parent f0b1c30222
commit 758c71e249
4 changed files with 34 additions and 4 deletions
+15 -1
View File
@@ -6,7 +6,7 @@ from dvc.stage import Stage
from tests.basic_env import TestDvc
from tests.test_repro import TestRepro
from tests.utils import load_stage_file
from tests.utils import load_stage_file, cd
class TestMove(TestDvc):
@@ -168,3 +168,17 @@ class TestMoveFileBetweenDirectories(TestDvc):
self.assertEqual(
os.path.basename(self.DATA), new_stage_file["outs"][0]["path"]
)
class TestMoveFileInsideDirectory(TestDvc):
def test(self):
ret = main(["add", "data_dir/data"])
self.assertEqual(ret, 0)
with cd("data_dir"):
ret = main(["move", "data", "data.txt"])
self.assertEqual(ret, 0)
self.assertFalse(os.path.exists("data_dir/data"))
self.assertTrue(os.path.exists("data_dir/data.txt"))
self.assertTrue(os.path.exists("data_dir/data.txt.dvc"))
+12
View File
@@ -1,5 +1,7 @@
import yaml
import os
from mock import MagicMock
from contextlib import contextmanager
def spy(method_to_decorate):
@@ -16,3 +18,13 @@ def spy(method_to_decorate):
def load_stage_file(path):
with open(path, "r") as fobj:
return yaml.safe_load(fobj)
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(prevdir)