Allow override required parameters

This commit is contained in:
Mikhail Gordeev 2022-02-09 01:19:03 +03:00
parent 8223824307
commit 1fd5fc07a5
2 changed files with 27 additions and 3 deletions

View File

@ -216,6 +216,12 @@ class CB:
msg = f'Could not read config file `{e.filename}`: {e.strerror}'
raise Error(msg)
def lazy_get_raises(key):
if key in override:
return override[key]
else:
return cfg[key]
self.mkimage_profiles_git = self.expand_path(
cfg.get('mkimage_profiles_git', '')
)
@ -260,9 +266,9 @@ class CB:
self.key = '{:X}'.format(self.key)
try:
self._remote = self.expand_path(cfg['remote'])
self._images = cfg['images']
self._branches = cfg['branches']
self._remote = self.expand_path(lazy_get_raises('remote'))
self._images = lazy_get_raises('images')
self._branches = lazy_get_raises('branches')
for _, branch in self._branches.items():
branch['arches'] = {k: {} if v is None else v
for k, v in branch['arches'].items()}

View File

@ -60,6 +60,24 @@ class TestErrors(TestCase):
self.kwargs.update(config=self.config)
self.assertRaisesRegex(Error, regex, CB, **self.kwargs)
def test_override_required_parameters_in_config(self):
self.config = tempfile.mktemp(prefix='cb_conf')
config_override = {
'remote': '/var/empty',
'images': {},
'branches': {},
}
with open('tests/minimal_config.yaml') as f:
cfg = yaml.safe_load(f)
for parameter in ['remote', 'images', 'branches']:
with open(self.config, 'w') as f:
yaml.safe_dump(update(cfg, {parameter: None}), f)
self.kwargs.update(config=self.config)
self.kwargs.update(config_override=config_override)
CB(**self.kwargs)
def test_run_already_running(self):
self.kwargs.update(config='tests/minimal_config.yaml')
cb = CB(**self.kwargs) # noqa F841