💅 refactor

This commit is contained in:
Mr. Outis
2019-12-25 01:04:52 -06:00
parent 75ad14aaa2
commit 4a25612282
3 changed files with 17 additions and 24 deletions
+8 -3
View File
@@ -9,12 +9,13 @@ try:
except ImportError:
from contextlib import GeneratorContextManager as GCM
from dvc.utils.compat import urlparse, builtin_str
import ruamel.yaml
from voluptuous import Schema, Required, Invalid
from dvc.utils.compat import urlparse, builtin_str
from dvc.repo import Repo
from dvc.exceptions import SummonError, FileMissingError
from dvc.exceptions import DvcException, FileMissingError
from dvc.external_repo import external_repo
@@ -36,6 +37,10 @@ SUMMON_SCHEMA = Schema(
)
class SummonError(DvcException):
pass
def get_url(path, repo=None, rev=None, remote=None):
"""Returns an url of a resource specified by path in repo"""
with _make_repo(repo, rev=rev) as _repo:
@@ -109,7 +114,7 @@ def summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml", args=None):
cause=exc.cause,
)
_pull_dependencies(_repo, info.get("deps"))
_pull_dependencies(_repo, info.get("deps", []))
_args = copy.deepcopy(info.get("args", {}))
_args.update(args or {})
-4
View File
@@ -353,7 +353,3 @@ class PathMissingError(DvcException):
" neighther as an output nor a git-handled file."
)
super(PathMissingError, self).__init__(msg.format(path, repo))
class SummonError(DvcException):
pass
+9 -17
View File
@@ -8,12 +8,12 @@ import ruamel.yaml
import pytest
from dvc import api
from dvc.api import SummonError
from dvc.exceptions import FileMissingError
from dvc.main import main
from dvc.path_info import URLInfo
from dvc.remote.config import RemoteConfig
from dvc.utils.compat import fspath
from dvc.exceptions import SummonError
from tests.remotes import Azure, GCP, HDFS, Local, OSS, S3, SSH
@@ -148,27 +148,21 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
]
}
different_objects = copy.deepcopy(objects)
different_objects["objects"][0]["summon"]["args"]["x"] = 100
other_objects = copy.deepcopy(objects)
other_objects["objects"][0]["summon"]["args"]["x"] = 100
dup_objects = copy.deepcopy(objects)
dup_objects["objects"] *= 2
dvcsummon_yaml = ruamel.yaml.dump(objects)
different_yaml = ruamel.yaml.dump(different_objects)
dup_yaml = ruamel.yaml.dump(dup_objects)
invalid_yaml = ruamel.yaml.dump({"name": "sum"})
not_yaml = "a: - this is not a valid YAML file"
with monkeypatch.context() as m:
m.chdir(fspath(erepo_dir))
erepo_dir.dvc_gen("number", "100", commit="Add number.dvc")
erepo_dir.scm_gen("dvcsummon.yaml", dvcsummon_yaml)
erepo_dir.scm_gen("different.yaml", different_yaml)
erepo_dir.scm_gen("dup.yaml", dup_yaml)
erepo_dir.scm_gen("invalid.yaml", invalid_yaml)
erepo_dir.scm_gen("not_yaml.yaml", not_yaml)
erepo_dir.scm_gen("dvcsummon.yaml", ruamel.yaml.dump(objects))
erepo_dir.scm_gen("other.yaml", ruamel.yaml.dump(other_objects))
erepo_dir.scm_gen("dup.yaml", ruamel.yaml.dump(dup_objects))
erepo_dir.scm_gen("invalid.yaml", ruamel.yaml.dump({"name": "sum"}))
erepo_dir.scm_gen("not_yaml.yaml", "a: - this is not a YAML file")
erepo_dir.scm_gen(
"calculator.py",
"def add_to_num(x): return x + int(open('number').read())",
@@ -179,9 +173,7 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
assert api.summon("sum", repo=repo_url) == 101
assert api.summon("sum", repo=repo_url, args={"x": 2}) == 102
assert (
api.summon("sum", repo=repo_url, summon_file="different.yaml") == 200
)
assert api.summon("sum", repo=repo_url, summon_file="other.yaml") == 200
try:
api.summon("sum", repo=repo_url, summon_file="missing.yaml")