def test_wdir_non_default_is_not_ignored(): stage = Stage(None, "path", cmd="mycmd") d = dict(TEST_STAGE_DICT, wdir="..") with mock.patch.object(stage, "dumpd", return_value=d): assert stage.compute_md5() == "2ceba15e87f6848aa756502c1e6d24e9"
def test_read_params_unsupported_format(tmp_dir, dvc): tmp_dir.gen("params.yaml", b"\0\1\2\3\4\5\6\7") dep = ParamsDependency(Stage(dvc), None, ["foo"]) with pytest.raises(BadParamFileError): dep.read_params()
def test_save_info_missing_config(dvc): dep = ParamsDependency(Stage(dvc), None, ["foo"]) with pytest.raises(MissingParamsError): dep.save_info()
def test_params_error(dvc, params): with pytest.raises(ValueError): loads_params(Stage(dvc), params)
def test_dumpd_without_info(dvc): dep = ParamsDependency(Stage(dvc), None, list(PARAMS.keys())) assert dep.dumpd() == { "path": "params.yaml", "params": list(PARAMS.keys()), }
def test_cmd_str(self): d = {Stage.PARAM_CMD: "cmd"} Stage.validate(d)
def test_empty_list(self): d = {Stage.PARAM_DEPS: []} Stage.validate(d) d = {Stage.PARAM_OUTS: []} Stage.validate(d)
def reproduce( self, target=None, single_item=False, force=False, dry=False, interactive=False, pipeline=False, all_pipelines=False, ignore_build_cache=False, no_commit=False, downstream=False, recursive=False, ): import networkx as nx from dvc.stage import Stage if not target and not all_pipelines: raise ValueError() if not interactive: config = self.config core = config.config[config.SECTION_CORE] interactive = core.get(config.SECTION_CORE_INTERACTIVE, False) targets = [] if recursive and os.path.isdir(target): G = self.graph(from_directory=target)[1] dir_targets = [ os.path.join(self.root_dir, n) for n in nx.dfs_postorder_nodes(G) ] targets.extend(dir_targets) elif pipeline or all_pipelines: if pipeline: stage = Stage.load(self, target) node = relpath(stage.path, self.root_dir) pipelines = [self._get_pipeline(node)] else: pipelines = self.pipelines() for G in pipelines: for node in G.nodes(): if G.in_degree(node) == 0: targets.append(os.path.join(self.root_dir, node)) else: targets.append(target) ret = [] with self.state: for target in targets: stages = _reproduce( self, target, single_item=single_item, force=force, dry=dry, interactive=interactive, ignore_build_cache=ignore_build_cache, no_commit=no_commit, downstream=downstream, ) ret.extend(stages) return ret
def test_run_args_from_cli(self): ret = main(["run", "echo", "foo"]) stage = Stage.load(self.dvc, fname="Dvcfile") self.assertEqual(ret, 0) self.assertEqual(stage.cmd, "echo foo")
def _get_output(self): stage = Stage(self.dvc) return LocalOutput(stage, "path")
def _get_dep(dvc, path): return _get(Stage(dvc), path, None)
def test_str_workdir_outside_repo(erepo_dir): stage = Stage(erepo_dir.dvc) output = LocalOutput(stage, "path", cache=False) assert relpath("path", erepo_dir.dvc.root_dir) == str(output)
def test_path_conversion(dvc): stage = Stage(dvc, "path") stage.wdir = os.path.join("..", "..") assert stage.dumpd()["wdir"] == "../.."
def test_meta_ignored(): stage = Stage(None, "path", cmd="mycmd") d = dict(TEST_STAGE_DICT, meta={"author": "Suor"}) with mock.patch.object(stage, "dumpd", return_value=d): assert stage.compute_md5() == "e9521a22111493406ea64a88cda63e0b"
def test_cmd_none(self): d = {Stage.PARAM_CMD: None} Stage.validate(d)
def test_run_args_with_spaces(self): ret = main(["run", "echo", "foo bar"]) stage = Stage.load(self.dvc, fname="Dvcfile") self.assertEqual(ret, 0) self.assertEqual(stage.cmd, 'echo "foo bar"')
def test_no_cmd(self): d = {} Stage.validate(d)
def test_get_info_nonexistent_file(dvc): dep = DependencyPARAMS(Stage(dvc), None, ["foo"]) assert dep._get_info() == {}
def test_none(self): d = {Stage.PARAM_DEPS: None} Stage.validate(d) d = {Stage.PARAM_OUTS: None} Stage.validate(d)
def test_get_info_unsupported_format(tmp_dir, dvc): tmp_dir.gen("params.yaml", b"\0\1\2\3\4\5\6\7") dep = DependencyPARAMS(Stage(dvc), None, ["foo"]) with pytest.raises(BadParamFileError): dep._get_info()
def test_save_info_missing_param(tmp_dir, dvc): tmp_dir.gen("params.yaml", "bar: baz") dep = ParamsDependency(Stage(dvc), None, ["foo"]) with pytest.raises(MissingParamsError): dep.save_info()
def test_get_info_nested(tmp_dir, dvc): tmp_dir.gen( "params.yaml", yaml.dump({"some": {"path": {"foo": ["val1", "val2"]}}}) ) dep = DependencyPARAMS(Stage(dvc), None, ["some.path.foo"]) assert dep._get_info() == {"some.path.foo": ["val1", "val2"]}
def test_dumpd_with_info(dvc): dep = ParamsDependency(Stage(dvc), None, PARAMS) assert dep.dumpd() == { "path": "params.yaml", "params": PARAMS, }
def test_save_info_missing_params(dvc): dep = DependencyPARAMS(Stage(dvc), None, ["foo"]) with pytest.raises(MissingParamsError): dep.save_info()
def test_read_params_nonexistent_file(dvc): dep = ParamsDependency(Stage(dvc), None, ["foo"]) assert dep.read_params() == {}
def _get_output(self): stage = Stage(self.dvc) return self._get_cls()(stage, "path", cache=False)
def test_read_params_nested(tmp_dir, dvc): tmp_dir.gen( "params.yaml", yaml.dump({"some": {"path": {"foo": ["val1", "val2"]}}}) ) dep = ParamsDependency(Stage(dvc), None, ["some.path.foo"]) assert dep.read_params() == {"some.path.foo": ["val1", "val2"]}
def _validate_fail(self, d): with self.assertRaises(StageFileFormatError): Stage.validate(d)
def lock_stage(self, target, unlock=False): stage = Stage.load(self, target) stage.locked = False if unlock else True stage.dump() return stage
def test_wdir_default_ignored(): stage = Stage(None, "path", cmd="mycmd") d = dict(TEST_STAGE_DICT, wdir=".") with mock.patch.object(stage, "dumpd", return_value=d): assert stage.compute_md5() == "e9521a22111493406ea64a88cda63e0b"