示例#1
0
def test_get_file(tmp_dir):
    tmp_dir.gen({"foo": "foo contents"})

    Repo.get_url("foo", "foo_imported")

    assert (tmp_dir / "foo_imported").is_file()
    assert (tmp_dir / "foo_imported").read_text() == "foo contents"
示例#2
0
def test_get_url_to_dir(tmp_dir, tmp_path_factory, dname):
    tmp_dir.gen({"src": {"foo": "foo contents"}, "dir": {"subdir": {}}})

    Repo.get_url(os.path.join("src", "foo"), dname)

    assert (tmp_dir / dname).is_dir()
    assert (tmp_dir / dname / "foo").read_text() == "foo contents"
示例#3
0
def test_get_url_to_dir(tmp_dir, dname):
    tmp_dir.gen({"foo": "foo contents", "dir": {"subdir": {}}})

    Repo.get_url("foo", dname)

    assert (tmp_dir / dname).is_dir()
    assert (tmp_dir / dname / "foo").read_text() == "foo contents"
示例#4
0
文件: get_url.py 项目: ye-man/dvc
 def run(self):
     try:
         Repo.get_url(self.args.url, out=self.args.out)
         return 0
     except DvcException:
         logger.exception("failed to get '{}'".format(self.args.url))
         return 1
示例#5
0
    def run(self):
        from dvc.repo import Repo

        try:
            Repo.get_url(self.args.url, out=self.args.out)
            return 0
        except DvcException:
            logger.exception(f"failed to get '{self.args.url}'")
            return 1
示例#6
0
def test_get_file(repo_dir):
    src = repo_dir.FOO
    dst = repo_dir.FOO + "_imported"

    Repo.get_url(src, dst)

    assert os.path.exists(dst)
    assert os.path.isfile(dst)
    assert filecmp.cmp(repo_dir.FOO, dst, shallow=False)
示例#7
0
def test_get_url_to_dir(dname, repo_dir):
    src = repo_dir.DATA

    makedirs(dname, exist_ok=True)

    Repo.get_url(src, dname)

    dst = os.path.join(dname, os.path.basename(src))

    assert os.path.isdir(dname)
    assert filecmp.cmp(repo_dir.DATA, dst, shallow=False)
示例#8
0
def test_get_url_from_non_local_path_to_dir_and_file(repo_dir, dst):
    file_name = "from"
    file_content = "data"
    base_info = RemoteS3.path_cls(get_aws_url())
    from_info = base_info / file_name

    s3 = boto3.client("s3")
    s3.create_bucket(Bucket=from_info.bucket)
    s3.put_object(Bucket=from_info.bucket,
                  Key=from_info.path,
                  Body=file_content)

    Repo.get_url(from_info.url, dst)

    result_path = os.path.join(dst, file_name) if os.path.isdir(dst) else dst

    assert os.path.exists(result_path)
    assert os.path.isfile(result_path)
    with open(result_path, "r") as fd:
        assert fd.read() == file_content
示例#9
0
def test_get_url_nonexistent(tmp_dir):
    with pytest.raises(DependencyDoesNotExistError):
        Repo.get_url("nonexistent")