Skip to content

Commit

Permalink
Added tests and fixed saving to new name
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Feb 3, 2017
1 parent 7d44e30 commit 4d4917c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
9 changes: 6 additions & 3 deletions malcolm/controllers/managercontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ def do_save(self, layout_name=None):
filename = os.path.join(self.params.configDir, layout_name + ".json")
text = json_encode(structure, indent=2)
open(filename, "w").write(text)
self._set_layout_names(layout_name)
self.layout_name.set_value(layout_name)
self._set_layout_names()
self.load_structure = structure

def _set_layout_names(self):
def _set_layout_names(self, extra_name=None):
names = []
if extra_name:
names.append(extra_name)
for f in os.listdir(self.params.configDir):
if os.path.isfile(os.path.join(self.params.configDir, f)):
if os.path.isfile(os.path.join(self.params.configDir, f)) and \
f.endswith(".json"):
names.append(f.split(".json")[0])
self.layout_name.meta.set_choices(names)

Expand Down
2 changes: 1 addition & 1 deletion malcolm/parts/builtin/childpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def save(self, task):
for k in self.child:
attr = self.child[k]
if isinstance(attr, Attribute) and "config" in attr.meta.tags:
part_structure[k] = serialize_object(attr)
part_structure[k] = serialize_object(attr.value)
return part_structure

def _get_flowgraph_ports(self, direction="out"):
Expand Down
21 changes: 19 additions & 2 deletions tests/test_parts/test_builtin/test_childpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import setup_malcolm_paths

import unittest
from mock import Mock, call
from mock import Mock, call, ANY
from time import sleep

# logging
Expand All @@ -19,6 +19,7 @@
from malcolm.controllers.runnablecontroller import RunnableController
from malcolm.controllers.defaultcontroller import DefaultController
from malcolm.core.vmetas.stringmeta import StringMeta
from malcolm.compat import OrderedDict

sm = RunnableController.stateMachine

Expand All @@ -40,7 +41,7 @@ def create_attributes(self):
# TODO this is yet to be documented
in_tag = "inport:pos:"
in_name = "inport%s" % self.name
in_port = StringMeta(in_name, [in_tag]).make_attribute()
in_port = StringMeta(in_name, [in_tag, "config"]).make_attribute()
in_port.meta.set_writeable_in(sm.READY)
yield in_name, in_port, in_port.set_value

Expand Down Expand Up @@ -187,5 +188,21 @@ def test_get_flowgraph_ports(self):
count = len(self.p1._get_flowgraph_ports('in'))
self.assertEqual(count, 1)

def test_load_save(self):
structure1 = self.p1.save(ANY)
expected = dict(inportConnector="")
self.assertEqual(structure1, expected)
self.p1.child.inportConnector = "blah"
structure2 = self.p1.save(ANY)
expected = dict(inportConnector="blah")
self.assertEqual(structure2, expected)
task = Mock()
task.put_async.return_value = ["future"]
self.p1.load(task, dict(partchild1=dict(inportConnector="blah_again")))
task.put_async.assert_called_once_with(
self.p1.child["inportConnector"], "blah_again")
task.wait_all.assert_called_once_with(["future"])


if __name__ == "__main__":
unittest.main(verbosity=2)

0 comments on commit 4d4917c

Please sign in to comment.