mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
fs: get_cloud_fs: accept config instead of repo
Config is a more immutable thing and using `repo` is confusing and might be error prone in the bigger picture. Related to #9754
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
import pytest
|
||||
from dvc_http import HTTPFileSystem, HTTPSFileSystem
|
||||
from dvc_s3 import S3FileSystem
|
||||
@@ -63,14 +61,8 @@ def test_remote_url():
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeRepo:
|
||||
config: dict
|
||||
|
||||
|
||||
def test_get_cloud_fs():
|
||||
repo = FakeRepo({})
|
||||
cls, config, path = get_cloud_fs(repo, url="ssh://example.com:/dir/path")
|
||||
cls, config, path = get_cloud_fs({}, url="ssh://example.com:/dir/path")
|
||||
assert cls is SSHFileSystem
|
||||
assert config == {"host": "example.com", "verify": False}
|
||||
assert path == "/dir/path"
|
||||
|
||||
@@ -13,11 +13,11 @@ def test_get_cloud_fs(tmp_dir, dvc):
|
||||
first = f"{base}/first"
|
||||
second = f"{first}/second"
|
||||
|
||||
_, _, path = get_cloud_fs(dvc, name="base")
|
||||
_, _, path = get_cloud_fs(dvc.config, name="base")
|
||||
assert path == base
|
||||
_, _, path = get_cloud_fs(dvc, name="first")
|
||||
_, _, path = get_cloud_fs(dvc.config, name="first")
|
||||
assert path == first
|
||||
_, _, path = get_cloud_fs(dvc, name="second")
|
||||
_, _, path = get_cloud_fs(dvc.config, name="second")
|
||||
assert path == second
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ def test_get_cloud_fs_validate(tmp_dir, dvc):
|
||||
default=False,
|
||||
)
|
||||
|
||||
assert get_cloud_fs(dvc, name="base")[1]["host"] == "example.com"
|
||||
assert get_cloud_fs(dvc, name="first")[1]["host"] == "example.com"
|
||||
assert get_cloud_fs(dvc, name="first")[1]["type"] == ["symlink"]
|
||||
assert get_cloud_fs(dvc.config, name="base")[1]["host"] == "example.com"
|
||||
assert get_cloud_fs(dvc.config, name="first")[1]["host"] == "example.com"
|
||||
assert get_cloud_fs(dvc.config, name="first")[1]["type"] == ["symlink"]
|
||||
|
||||
with pytest.raises(ConfigError):
|
||||
get_cloud_fs(dvc, name="second")
|
||||
get_cloud_fs(dvc.config, name="second")
|
||||
|
||||
@@ -12,7 +12,7 @@ def test_remote_with_hash_jobs(dvc):
|
||||
}
|
||||
dvc.config["core"]["checksum_jobs"] = 200
|
||||
|
||||
cls, config, _ = get_cloud_fs(dvc, name="with_hash_jobs")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="with_hash_jobs")
|
||||
fs = cls(**config)
|
||||
assert fs.hash_jobs == 100
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_remote_with_jobs(dvc):
|
||||
"jobs": 100,
|
||||
}
|
||||
|
||||
cls, config, _ = get_cloud_fs(dvc, name="with_jobs")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="with_jobs")
|
||||
fs = cls(**config)
|
||||
assert fs.jobs == 100
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_remote_without_hash_jobs(dvc):
|
||||
dvc.config["remote"]["without_hash_jobs"] = {"url": "s3://bucket/name"}
|
||||
dvc.config["core"]["checksum_jobs"] = 200
|
||||
|
||||
cls, config, _ = get_cloud_fs(dvc, name="without_hash_jobs")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="without_hash_jobs")
|
||||
fs = cls(**config)
|
||||
assert fs.hash_jobs == 200
|
||||
|
||||
@@ -40,7 +40,7 @@ def test_remote_without_hash_jobs(dvc):
|
||||
def test_remote_without_hash_jobs_default(dvc):
|
||||
dvc.config["remote"]["without_hash_jobs"] = {"url": "s3://bucket/name"}
|
||||
|
||||
cls, config, _ = get_cloud_fs(dvc, name="without_hash_jobs")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="without_hash_jobs")
|
||||
fs = cls(**config)
|
||||
assert fs.hash_jobs == fs.HASH_JOBS
|
||||
|
||||
|
||||
@@ -145,14 +145,14 @@ def test_remote_with_jobs(dvc, base_url, fs_cls):
|
||||
remote_config = {"url": base_url}
|
||||
|
||||
dvc.config["remote"]["dav"] = remote_config
|
||||
cls, config, _ = get_cloud_fs(dvc, name="dav")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="dav")
|
||||
assert config["user"] == user
|
||||
assert f"{scheme}://{user}@example.com" in config["host"]
|
||||
assert cls is fs_cls
|
||||
|
||||
# config from remote takes priority
|
||||
remote_config.update({"user": "admin"})
|
||||
cls, config, _ = get_cloud_fs(dvc, name="dav")
|
||||
cls, config, _ = get_cloud_fs(dvc.config, name="dav")
|
||||
assert config["user"] == "admin"
|
||||
assert f"{scheme}://{user}@example.com" in config["host"]
|
||||
assert cls is fs_cls
|
||||
|
||||
Reference in New Issue
Block a user