Skip to content

Commit

Permalink
dvc: check stage name before running command
Browse files Browse the repository at this point in the history
  • Loading branch information
Suor committed Jun 25, 2019
1 parent dd6ed7e commit 6e761c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ def create(

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:
Expand Down
24 changes: 14 additions & 10 deletions tests/func/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ def test(self):

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="",
Expand Down Expand Up @@ -1000,3 +990,17 @@ def test_ignore_build_cache(self):
# 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")

0 comments on commit 6e761c7

Please sign in to comment.