Skip to content

Commit

Permalink
feat(utils): update new_component to not be included in the main doc
Browse files Browse the repository at this point in the history
Only NeuroML docs can be included in other NeuroML docs. Components are
LEMS constructs and so must be included in the LEMS simulation file.
  • Loading branch information
sanjayankur31 committed Oct 15, 2024
1 parent 30aae2b commit c89421e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 6 additions & 5 deletions pyneuroml/utils/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@


def add_new_component(
nmldoc: NeuroMLDocument,
component_id: str,
component_type: str,
component_filename: Optional[str] = None,
Expand Down Expand Up @@ -52,8 +51,8 @@ def add_new_component(
the component in
:type component_filename: str
:param **kwargs: parameters to pass to the Component
:returns: the Component Object
:rtype: Component
:returns: the Component Object, and the name of the XML file it was serialised in
:rtype: tuple(Component, str)
"""
newmodel = Model()
newcomp = Component(id_=component_id, type_=component_type, **kwargs)
Expand All @@ -70,6 +69,8 @@ def add_new_component(
logger.info(
"Component file included in NeuroML document. Note that new components will not validate against the NeuroML schema."
)
nmldoc.add(IncludeType, href=component_filename)
logger.info(
f"Please also remember to include {component_filename} in the LEMS simulation file"
)

return newcomp
return newcomp, component_filename
10 changes: 4 additions & 6 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,9 @@ def test_translate_cell_to_coords(self):

def test_adding_new_components(self):
"""Test add_new_component method."""
newdoc = neuroml.utils.component_factory("NeuroMLDocument", id="test_doc") # type: neuroml.NeuroMLDocument
new_comp = add_new_component(
newdoc, "newcomp", "sometype", param1="5v", param2="something"
new_comp, new_comp_file = add_new_component(
"newcomp", "sometype", param1="5v", param2="something"
)
self.assertIsNotNone(new_comp)
self.assertEqual(1, len(newdoc.includes))
self.assertIsFile("component_newcomp.xml")
os.unlink("component_newcomp.xml")
self.assertIsFile(new_comp_file)
os.unlink(new_comp_file)

0 comments on commit c89421e

Please sign in to comment.