dvc: check stage name before running command

Closes #2150.
This commit is contained in:
Alexander Schepanovski
2019-06-25 19:21:16 +07:00
parent dd6ed7e7e9
commit 6e761c7e7a
2 changed files with 16 additions and 10 deletions
+2
View File
@@ -480,6 +480,8 @@ class Stage(object):
if not fname:
fname = Stage._stage_fname(stage.outs, add=add)
stage._check_dvc_filename(fname)
wdir = os.path.abspath(wdir)
if cwd is not None:
+14 -10
View File
@@ -97,16 +97,6 @@ class TestRunMissingDep(TestDvc):
class TestRunBadStageFilename(TestDvc):
def test(self):
with self.assertRaises(StageFileBadNameError):
self.dvc.run(
cmd="",
deps=[],
outs=[],
outs_no_cache=[],
fname="empty",
cwd=os.curdir,
)
with self.assertRaises(StageFileBadNameError):
self.dvc.run(
cmd="",
@@ -1000,3 +990,17 @@ class TestPersistentOutput(TestDvc):
# it should run the command again, as it is "ignoring build cache"
with open("greetings", "r") as fobj:
assert "hello\nhello\n" == fobj.read()
def test_bad_stage_fname(repo_dir, dvc_repo):
dvc_repo.add(repo_dir.FOO)
with pytest.raises(StageFileBadNameError):
dvc_repo.run(
cmd="python {} {} {}".format(repo_dir.CODE, repo_dir.FOO, "out"),
deps=[repo_dir.FOO, repo_dir.CODE],
outs=["out"],
fname="out_stage", # Bad name, should end with .dvc
)
# Check that command hasn't been run
assert not os.path.exists("out")