Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor factory fixes #258

Merged
merged 3 commits into from
Jun 4, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions labgrid/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@ def _convert_to_named_list(self, data):
"""

# resolve syntactic sugar (list of dicts each containing a dict of key -> args)
result = []
if isinstance(data, list):
for idx, item in enumerate(data):
if not isinstance(item, dict):
raise InvalidConfigError(
"invalid list item type {} (should be dict)".format(type(item)))
if len(item) < 1:
raise InvalidConfigError("invalid empty dict as list item")
if len(item) > 1:
elif len(item) > 1:
if 'cls' in item:
continue
item = item.copy()
else:
raise InvalidConfigError("missing 'cls' key in {}".format(item))
# only one pair left
(key, value), = item.items()
if key == 'cls':
continue
else:
item.clear()
item['cls'] = key
item.update(value)
result = data
# only one pair left
(key, value), = item.items()
if key == 'cls':
item = item.copy()
else:
item = {'cls': key}
item.update(value)
result.append(item)
elif isinstance(data, dict):
result = []
for cls, args in data.items():
args.setdefault('cls', cls)
result.append(args)
Expand All @@ -94,7 +94,7 @@ def normalize_config(self, config):
name = item.pop('name', None)
bindings = item.pop('bindings', {})
args = item # remaining args
drivers.setdefault(resource, {})[name] = (args, bindings)
drivers.setdefault(driver, {})[name] = (args, bindings)
return resources, drivers

def make_resource(self, target, resource, name, args):
Expand Down