diff --git a/dvc/stage.py b/dvc/stage.py index a9f5409bd..5abc53e54 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -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: diff --git a/tests/func/test_run.py b/tests/func/test_run.py index 774999f9b..7f6ee289c 100644 --- a/tests/func/test_run.py +++ b/tests/func/test_run.py @@ -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")