feat(config): add workers field and --workers CLI flag
Add parallel download worker-count configuration through all three config layers: Config dataclass (workers=3 default), YAML parsing with InvalidWorkersError validation, and -w/--workers CLI flag with three-layer resolution (CLI > config > hardcoded 3). 6 new tests. Closes #12
This commit is contained in:
11 files changed
+329
-2
No files matched your search
@@ -10,6 +10,7 @@ from librofm_downloader.config import (
|
||||
CredentialsInConfigError,
|
||||
MissingFieldError,
|
||||
InvalidFormatError,
|
||||
InvalidWorkersError,
|
||||
)
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
@@ -167,6 +168,50 @@ class TestDefaults:
|
||||
assert config.download_covers is True
|
||||
|
||||
|
||||
class TestWorkersDefault:
|
||||
"""workers field defaults to 3 when not specified in YAML."""
|
||||
|
||||
def test_default_workers_is_3(self):
|
||||
"""When workers is absent from YAML, Config.workers defaults to 3."""
|
||||
config = load_config(
|
||||
config_path=FIXTURES / "config_minimal.yaml",
|
||||
secrets_path=FIXTURES / "secrets_only_creds.yaml",
|
||||
)
|
||||
assert config.workers == 3
|
||||
|
||||
|
||||
class TestWorkersFromYaml:
|
||||
"""workers field is parsed from config.yaml when present."""
|
||||
|
||||
def test_workers_5_from_yaml(self):
|
||||
"""workers: 5 in config.yaml produces Config(workers=5)."""
|
||||
config = load_config(
|
||||
config_path=FIXTURES / "config_with_overrides.yaml",
|
||||
secrets_path=FIXTURES / "secrets_only_creds.yaml",
|
||||
)
|
||||
assert config.workers == 5
|
||||
|
||||
|
||||
class TestWorkersValidation:
|
||||
"""workers < 1 raises InvalidWorkersError."""
|
||||
|
||||
def test_workers_zero_raises_error(self):
|
||||
"""workers: 0 in YAML raises InvalidWorkersError."""
|
||||
with pytest.raises(InvalidWorkersError, match="Must be an integer >= 1"):
|
||||
load_config(
|
||||
config_path=FIXTURES / "config_workers_zero.yaml",
|
||||
secrets_path=FIXTURES / "secrets_only_creds.yaml",
|
||||
)
|
||||
|
||||
def test_workers_negative_raises_error(self):
|
||||
"""workers: -1 in YAML raises InvalidWorkersError."""
|
||||
with pytest.raises(InvalidWorkersError, match="Must be an integer >= 1"):
|
||||
load_config(
|
||||
config_path=FIXTURES / "config_workers_negative.yaml",
|
||||
secrets_path=FIXTURES / "secrets_only_creds.yaml",
|
||||
)
|
||||
|
||||
|
||||
class TestInvalidFormat:
|
||||
"""Invalid format values are rejected with a clear error."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user