Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions sumatra/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ def register(self, component):
if not hasattr(component, attr):
raise TypeError("%s is missing required attribute %s" % (component, attr))
if hasattr(component, "name"):
name = component.name
names = [component.name]
elif hasattr(component, "names"):
names = component.names
else:
name = component.__name__
self._components[base_class][name] = component
names = [component.__name__]
for name in names:
self._components[base_class][name] = component
return
raise TypeError("%s is not a Sumatra component." % component)

Expand Down
2 changes: 1 addition & 1 deletion sumatra/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class YAMLParameterSet(ParameterSet):
Handles parameter files in YAML format, as parsed by the
PyYAML module
"""
name = ".yaml"
names = (".yaml", ".yml")

def __init__(self, initialiser):
"""
Expand Down
8 changes: 8 additions & 0 deletions test/unittests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ def setUp(self):
if yaml_loaded:
with open("test_file.yaml", "w") as f:
f.write(init2)
with open("test_file.yml", "w") as f:
f.write(init2)

def tearDown(self):
os.remove("test_file.simple")
Expand Down Expand Up @@ -548,6 +550,12 @@ def test__build_parameters_yaml(self):
self.assertEqual(P.as_dict(), {'x': 2, 'y': {'a': 3, 'b': 4}})
self.assertIsInstance(P, YAMLParameterSet)

@unittest.skipUnless(yaml_loaded, "PyYAML not available")
def test__build_parameters_yml(self):
P = build_parameters("test_file.yml")
self.assertEqual(P.as_dict(), {'x': 2, 'y': {'a': 3, 'b': 4}})
self.assertIsInstance(P, YAMLParameterSet)


# these tests should now be applied to commands.parse_arguments and/or commands.parse_command_line_parameter()
#def test__build_parameters__should_add_new_command_line_parameters_to_the_file_parameters(self):
Expand Down
Loading