mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 23:09:35 +01:00
Merge pull request #1681 from shcheklein/fix-1680
Stage checksum with default wdir fix
This commit is contained in:
+5
-6
@@ -527,7 +527,9 @@ class Stage(object):
|
||||
for key, value in {
|
||||
Stage.PARAM_MD5: self.md5,
|
||||
Stage.PARAM_CMD: self.cmd,
|
||||
Stage.PARAM_WDIR: self.wdir,
|
||||
Stage.PARAM_WDIR: os.path.relpath(
|
||||
self.wdir, os.path.dirname(self.path)
|
||||
),
|
||||
Stage.PARAM_LOCKED: self.locked,
|
||||
Stage.PARAM_DEPS: [d.dumpd() for d in self.deps],
|
||||
Stage.PARAM_OUTS: [o.dumpd() for o in self.outs],
|
||||
@@ -535,8 +537,8 @@ class Stage(object):
|
||||
if value
|
||||
}
|
||||
|
||||
def dump(self, fname=None):
|
||||
fname = fname or self.path
|
||||
def dump(self):
|
||||
fname = self.path
|
||||
|
||||
self._check_dvc_filename(fname)
|
||||
|
||||
@@ -547,9 +549,6 @@ class Stage(object):
|
||||
)
|
||||
d = self.dumpd()
|
||||
|
||||
d[Stage.PARAM_WDIR] = os.path.relpath(
|
||||
self.wdir, os.path.dirname(fname)
|
||||
)
|
||||
with open(fname, "w") as fd:
|
||||
yaml.safe_dump(d, fd, default_flow_style=False)
|
||||
|
||||
|
||||
@@ -103,6 +103,9 @@ class TestDefaultWorkingDirectory(TestDvc):
|
||||
outs=[self.FOO],
|
||||
)
|
||||
|
||||
d = stage.dumpd()
|
||||
self.assertEqual(d[stage.PARAM_WDIR], ".")
|
||||
|
||||
with open(stage.relpath, "r") as fobj:
|
||||
d = yaml.safe_load(fobj)
|
||||
self.assertEqual(d[stage.PARAM_WDIR], ".")
|
||||
@@ -111,6 +114,10 @@ class TestDefaultWorkingDirectory(TestDvc):
|
||||
with open(stage.relpath, "w") as fobj:
|
||||
yaml.safe_dump(d, fobj, default_flow_style=False)
|
||||
|
||||
with open(stage.relpath, "r") as fobj:
|
||||
d = yaml.safe_load(fobj)
|
||||
self.assertIsNone(d.get(stage.PARAM_WDIR))
|
||||
|
||||
with self.dvc.state:
|
||||
stage = Stage.load(self.dvc, stage.relpath)
|
||||
self.assertFalse(stage.changed())
|
||||
|
||||
@@ -14,3 +14,37 @@ class TestStageChecksum(TestCase):
|
||||
self.assertEqual(
|
||||
stage._compute_md5(), "e9521a22111493406ea64a88cda63e0b"
|
||||
)
|
||||
|
||||
def test_wdir_default_ignored(self):
|
||||
stage = Stage(None, "path")
|
||||
outs = [{"path": "a", "md5": "123456789"}]
|
||||
deps = [{"path": "b", "md5": "987654321"}]
|
||||
d = {
|
||||
"md5": "123456",
|
||||
"cmd": "mycmd",
|
||||
"outs": outs,
|
||||
"deps": deps,
|
||||
"wdir": ".",
|
||||
}
|
||||
|
||||
with mock.patch.object(stage, "dumpd", return_value=d):
|
||||
self.assertEqual(
|
||||
stage._compute_md5(), "e9521a22111493406ea64a88cda63e0b"
|
||||
)
|
||||
|
||||
def test_wdir_non_default_is_not_ignored(self):
|
||||
stage = Stage(None, "path")
|
||||
outs = [{"path": "a", "md5": "123456789"}]
|
||||
deps = [{"path": "b", "md5": "987654321"}]
|
||||
d = {
|
||||
"md5": "123456",
|
||||
"cmd": "mycmd",
|
||||
"outs": outs,
|
||||
"deps": deps,
|
||||
"wdir": "..",
|
||||
}
|
||||
|
||||
with mock.patch.object(stage, "dumpd", return_value=d):
|
||||
self.assertEqual(
|
||||
stage._compute_md5(), "2ceba15e87f6848aa756502c1e6d24e9"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user