If no extract repository is given, then error if there are multiple configured repositories.

This commit is contained in:
Dan Helfman 2019-02-18 13:22:14 -08:00
parent 766a03375a
commit c41ffb5ceb
2 changed files with 24 additions and 0 deletions

View File

@ -114,10 +114,27 @@ def guard_configuration_contains_repository(repository, configurations):
Given a repository path and a dict mapping from config filename to corresponding parsed config
dict, ensure that the repository is declared exactly once in all of the configurations.
If no repository is given, then error if there are multiple configured repositories.
Raise ValueError if the repository is not found in a configuration, or is declared multiple
times.
'''
if not repository:
count = len(
tuple(
config_repository
for config in configurations.values()
for config_repository in config['repositories']
)
)
if count > 1:
raise ValueError(
'Can\'t determine which repository to extract. Use --repository option to disambiguate'.format(
repository
)
)
return
count = len(

View File

@ -104,6 +104,13 @@ def test_guard_configuration_contains_repository_does_not_raise_when_repository_
)
def test_guard_configuration_contains_repository_errors_when_repository_assumed_to_match_config_twice():
with pytest.raises(ValueError):
module.guard_configuration_contains_repository(
repository=None, configurations={'config.yaml': {'repositories': ['repo', 'repo2']}}
)
def test_guard_configuration_contains_repository_errors_when_repository_missing_from_config():
with pytest.raises(ValueError):
module.guard_configuration_contains_repository(