Skip to content

Commit f62aeae

Browse files
committed
run: tests: clumsy deterministic_run migration
1 parent 6d61e62 commit f62aeae

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

tests/func/test_run.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import filecmp
22
import logging
33
import os
4-
import shutil
54
import uuid
5+
from pathlib import Path
66

77
import mock
88
import pytest
@@ -612,21 +612,25 @@ def test_cwd_is_ignored(self):
612612

613613

614614
class DeterministicRunBaseFixture(object):
615-
def __init__(self, repo_dir, dvc_repo):
615+
def __init__(self, tmp_dir, dvc):
616+
tmp_dir.gen(
617+
"copy.py",
618+
"import sys, shutil\nshutil.copyfile(sys.argv[1], sys.argv[2])",
619+
)
620+
tmp_dir.gen("foo", "foo content")
621+
616622
self.out_file = "out"
617623
self.stage_file = self.out_file + ".dvc"
618-
self.cmd = "python {} {} {}".format(
619-
repo_dir.CODE, repo_dir.FOO, self.out_file
620-
)
621-
self.deps = [repo_dir.FOO, repo_dir.CODE]
624+
self.cmd = "python {} {} {}".format("copy.py", "foo", self.out_file)
625+
self.deps = ["foo", "copy.py"]
622626
self.outs = [self.out_file]
623627
self.overwrite = False
624628
self.ignore_build_cache = False
625-
self.dvc_repo = dvc_repo
629+
self.dvc = dvc
626630
self.stage = None
627631

628632
def run(self):
629-
self.stage = self.dvc_repo.run(
633+
self.stage = self.dvc.run(
630634
cmd=self.cmd,
631635
fname=self.stage_file,
632636
overwrite=self.overwrite,
@@ -638,8 +642,8 @@ def run(self):
638642

639643

640644
@pytest.fixture
641-
def deterministic_run(dvc_repo, repo_dir):
642-
run_base = DeterministicRunBaseFixture(repo_dir, dvc_repo)
645+
def deterministic_run(tmp_dir, dvc):
646+
run_base = DeterministicRunBaseFixture(tmp_dir, dvc)
643647
run_base.run()
644648
yield run_base
645649

@@ -663,27 +667,30 @@ def test_run_deterministic_callback(deterministic_run):
663667
assert deterministic_run.run()
664668

665669

666-
def test_run_deterministic_changed_dep(deterministic_run, repo_dir):
667-
os.unlink(repo_dir.FOO)
668-
shutil.copy(repo_dir.BAR, repo_dir.FOO)
670+
def test_run_deterministic_changed_dep(deterministic_run):
671+
foo = Path("foo")
672+
foo.unlink()
673+
foo.write_text("bar")
669674
with pytest.raises(StageFileAlreadyExistsError):
670675
deterministic_run.run()
671676

672677

673-
def test_run_deterministic_changed_deps_list(deterministic_run, repo_dir):
674-
deterministic_run.deps = [repo_dir.BAR, repo_dir.CODE]
678+
def test_run_deterministic_changed_deps_list(tmp_dir, deterministic_run):
679+
tmp_dir.gen("bar", "bar content")
680+
deterministic_run.deps = ["bar", "copy.py"]
675681
with pytest.raises(StageFileAlreadyExistsError):
676682
deterministic_run.run()
677683

678684

679-
def test_run_deterministic_new_dep(deterministic_run, repo_dir):
680-
deterministic_run.deps = [repo_dir.FOO, repo_dir.BAR, repo_dir.CODE]
685+
def test_run_deterministic_new_dep(tmp_dir, deterministic_run):
686+
tmp_dir.gen("bar", "bar content")
687+
deterministic_run.deps.append("bar")
681688
with pytest.raises(StageFileAlreadyExistsError):
682689
deterministic_run.run()
683690

684691

685-
def test_run_deterministic_remove_dep(deterministic_run, repo_dir):
686-
deterministic_run.deps = [repo_dir.CODE]
692+
def test_run_deterministic_remove_dep(deterministic_run):
693+
deterministic_run.deps = ["copy.py"]
687694
with pytest.raises(StageFileAlreadyExistsError):
688695
deterministic_run.run()
689696

0 commit comments

Comments
 (0)