mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
+3
-1
@@ -52,7 +52,9 @@ def move(self, from_path, to_path):
|
||||
os.path.basename(to_path) + Stage.STAGE_FILE_SUFFIX,
|
||||
)
|
||||
|
||||
stage.cwd = os.path.join(self.root_dir, os.path.dirname(to_path))
|
||||
stage.cwd = os.path.abspath(
|
||||
os.path.join(os.curdir, os.path.dirname(to_path))
|
||||
)
|
||||
|
||||
to_out = Output.loads_from(
|
||||
stage, [os.path.basename(to_path)], out.cache, out.metric
|
||||
|
||||
+4
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
import errno
|
||||
|
||||
|
||||
# Syntax sugar.
|
||||
@@ -42,8 +43,9 @@ def _makedirs(name, mode=0o777, exist_ok=False):
|
||||
if head and tail and not os.path.exists(head):
|
||||
try:
|
||||
_makedirs(head, exist_ok=exist_ok)
|
||||
except FileExistsError:
|
||||
pass
|
||||
except OSError as e:
|
||||
if e.errno == errno.EEXIST:
|
||||
pass
|
||||
cdir = os.curdir
|
||||
if isinstance(tail, bytes):
|
||||
cdir = bytes(os.curdir, "ASCII")
|
||||
|
||||
+15
-1
@@ -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"))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user