@@ -611,100 +611,57 @@ def test_cwd_is_ignored(self):
611611 )
612612
613613
614- class DeterministicRunBaseFixture (object ):
615- def __init__ (self , tmp_dir , dvc ):
616- tmp_dir .gen (
617- "copy.py" ,
618- "import sys, shutil\n shutil.copyfile(sys.argv[1], sys.argv[2])" ,
619- )
620- tmp_dir .gen ("foo" , "foo content" )
621-
622- self .out_file = "out"
623- self .stage_file = self .out_file + ".dvc"
624- self .cmd = "python {} {} {}" .format ("copy.py" , "foo" , self .out_file )
625- self .deps = ["foo" , "copy.py" ]
626- self .outs = [self .out_file ]
627- self .overwrite = False
628- self .ignore_build_cache = False
629- self .dvc = dvc
630- self .stage = None
631-
632- def run (self ):
633- self .stage = self .dvc .run (
634- cmd = self .cmd ,
635- fname = self .stage_file ,
636- overwrite = self .overwrite ,
637- ignore_build_cache = self .ignore_build_cache ,
638- deps = self .deps ,
639- outs = self .outs ,
640- )
641- return self .stage
642-
643-
644- @pytest .fixture
645- def deterministic_run (tmp_dir , dvc ):
646- run_base = DeterministicRunBaseFixture (tmp_dir , dvc )
647- run_base .run ()
648- yield run_base
649-
650-
651- def test_run_deterministic (deterministic_run ):
652- deterministic_run .run ()
653-
654-
655- def test_run_deterministic_overwrite (deterministic_run ):
656- deterministic_run .overwrite = True
657- deterministic_run .ignore_build_cache = True
658- deterministic_run .run ()
659-
660-
661- def test_run_deterministic_callback (deterministic_run ):
662- with deterministic_run .stage .repo .lock :
663- deterministic_run .stage .remove ()
664- deterministic_run .deps = []
665- deterministic_run .run ()
666- with mock .patch ("dvc.prompt.confirm" , return_value = True ):
667- assert deterministic_run .run ()
614+ def test_rerun_deterministic (tmp_dir , run_copy ):
615+ tmp_dir .gen ("foo" , "foo content" )
668616
617+ assert run_copy ("foo" , "out" ) is not None
618+ assert run_copy ("foo" , "out" ) is None
669619
670- def test_run_deterministic_changed_dep (deterministic_run ):
671- foo = Path ("foo" )
672- foo .unlink ()
673- foo .write_text ("bar" )
674- with pytest .raises (StageFileAlreadyExistsError ):
675- deterministic_run .run ()
676620
621+ def test_rerun_deterministic_ignore_cache (tmp_dir , run_copy ):
622+ tmp_dir .gen ("foo" , "foo content" )
677623
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" ]
681- with pytest .raises (StageFileAlreadyExistsError ):
682- deterministic_run .run ()
624+ assert run_copy ("foo" , "out" ) is not None
625+ assert run_copy ("foo" , "out" , ignore_build_cache = True ) is not None
683626
684627
685- def test_run_deterministic_new_dep ( tmp_dir , deterministic_run ):
686- tmp_dir . gen ( "bar" , "bar content" )
687- deterministic_run . deps . append ( "bar" )
688- with pytest . raises ( StageFileAlreadyExistsError ):
689- deterministic_run . run ( )
628+ def test_rerun_callback ( dvc ):
629+ def run_callback ():
630+ return dvc . run (
631+ cmd = ( "echo content > out" ), outs = [ "out" ], deps = [], overwrite = False
632+ )
690633
634+ assert run_callback () is not None
691635
692- def test_run_deterministic_remove_dep (deterministic_run ):
693- deterministic_run .deps = ["copy.py" ]
636+ with mock .patch ("dvc.prompt.confirm" , return_value = True ):
637+ assert run_callback () is not None
638+
639+
640+ def test_rerun_changed_dep (tmp_dir , run_copy ):
641+ tmp_dir .gen ("foo" , "foo content" )
642+ assert run_copy ("foo" , "out" ) is not None
643+
644+ tmp_dir .gen ("foo" , "changed content" )
694645 with pytest .raises (StageFileAlreadyExistsError ):
695- deterministic_run . run ( )
646+ run_copy ( "foo" , "out" , overwrite = False )
696647
697648
698- def test_run_deterministic_changed_out (deterministic_run ):
699- os .unlink (deterministic_run .out_file )
649+ def test_rerun_changed_stage (tmp_dir , run_copy ):
650+ tmp_dir .gen ("foo" , "foo content" )
651+ assert run_copy ("foo" , "out" ) is not None
652+
653+ tmp_dir .gen ("bar" , "bar content" )
700654 with pytest .raises (StageFileAlreadyExistsError ):
701- deterministic_run .run ()
655+ run_copy ("bar" , "out" , overwrite = False )
656+
702657
658+ def test_rerun_changed_out (tmp_dir , run_copy ):
659+ tmp_dir .gen ("foo" , "foo content" )
660+ assert run_copy ("foo" , "out" ) is not None
703661
704- def test_run_deterministic_changed_cmd (deterministic_run ):
705- deterministic_run .cmd += " arg"
662+ Path ("out" ).write_text ("modification" )
706663 with pytest .raises (StageFileAlreadyExistsError ):
707- deterministic_run . run ( )
664+ run_copy ( "foo" , "out" , overwrite = False )
708665
709666
710667class TestRunCommit (TestDvc ):
0 commit comments