Example #1
0
    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(mri='mainBlock',
                                                        name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)
    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock",
                                                     configDir="/tmp")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)
    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)
Example #4
0
    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(
            mri='mainBlock', name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)
Example #5
0
class TestChildPart(unittest.TestCase):
    def checkState(self, state):
        self.assertEqual(self.c.state.value, state)

    def makeChildBlock(self, blockMri):
        params = PortsPart.MethodMeta.prepare_input_map(name='Connector')
        port_part = PortsPart(self.p, params)

        partName = 'part%s' % blockMri
        params = DefaultController.MethodMeta.prepare_input_map(mri=blockMri)
        controller = DefaultController(self.p, [port_part], params)

        params = ChildPart.MethodMeta.prepare_input_map(mri=blockMri,
                                                        name=partName)
        part = ChildPart(self.p, params)

        return part, controller

    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(mri='mainBlock',
                                                        name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)

    def tearDown(self):
        self.p.stop()

    def test_init(self):
        # check instantiation of object tree via logger names
        self.assertEqual(self.c._logger.name, 'RunnableController(mainBlock)')
        self.assertEqual(self.c.parts['partchild1']._logger.name,
                         'RunnableController(mainBlock).partchild1')
        self.assertEqual(self.c.parts['partchild2']._logger.name,
                         'RunnableController(mainBlock).partchild2')
        self.assertEqual(self.c.parts['partchild3']._logger.name,
                         'RunnableController(mainBlock).partchild3')

        self.assertEqual(self.c1.parts['Connector']._logger.name,
                         'DefaultController(child1).Connector')
        self.assertEqual(self.c2.parts['Connector']._logger.name,
                         'DefaultController(child2).Connector')
        self.assertEqual(self.c3.parts['Connector']._logger.name,
                         'DefaultController(child3).Connector')

        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c1.block.outportConnector, '')

    def test_reset(self):
        # TODO cover the clause 'state == RESETTING'
        self.c.disable()
        self.checkState(sm.DISABLED)
        self.c.reset()
        self.checkState(sm.IDLE)

    def test_pre_layout(self):
        outports = self.p1.pre_layout(None)
        self.assertEqual(len(outports), 1)

    def test_layout(self):
        self.c.edit()
        self.checkState(sm.EDITABLE)

        new_layout = Table(self.c.layout.meta)
        new_layout.name = ["partchild1", "partchild2", "partchild3"]
        new_layout.mri = ["part1", "part2", "part3"]
        new_layout.x = [10, 11, 12]
        new_layout.y = [20, 21, 22]
        new_layout.visible = [True, True, True]
        self.b.layout = new_layout
        self.assertEqual(self.c.parts['partchild1'].x, 10)
        self.assertEqual(self.c.parts['partchild1'].y, 20)
        self.assertEqual(self.c.parts['partchild1'].visible, True)
        self.assertEqual(self.c.parts['partchild2'].x, 11)
        self.assertEqual(self.c.parts['partchild2'].y, 21)
        self.assertEqual(self.c.parts['partchild2'].visible, True)
        self.assertEqual(self.c.parts['partchild3'].x, 12)
        self.assertEqual(self.c.parts['partchild3'].y, 22)
        self.assertEqual(self.c.parts['partchild3'].visible, True)

        new_layout.visible = [True, False, True]
        self.b.layout = new_layout
        self.assertEqual(self.c.parts['partchild1'].visible, True)
        self.assertEqual(self.c.parts['partchild2'].visible, False)
        self.assertEqual(self.c.parts['partchild3'].visible, True)

    def test_sever_all_inports(self):
        self.c1.block.inportConnector = 'Connector'
        self.c2.block.inportConnector = 'Connector'
        self.c3.block.inportConnector = 'Connector3'

        task = Task("Task1", self.p)
        self.p1.sever_all_inports(task)
        task.wait_all([], 5)
        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c2.block.inportConnector, 'Connector')
        self.assertEqual(self.c3.block.inportConnector, 'Connector3')

    def test_sever_inports_connected_to(self):
        self.c1.block.inportConnector = 'Connector'

        self.assertEqual(self.c1.block.inportConnector, 'Connector')

        task = Task("Task1", self.p)
        out_port = {'Connector': 'pos'}
        self.p1.sever_inports_connected_to(task, out_port)
        self.assertEqual(self.c1.block.inportConnector, '')

    def test_get_flowgraph_ports(self):
        count = len(self.p1._get_flowgraph_ports('out'))
        self.assertEqual(count, 1)
        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"])
class TestRunnableController(unittest.TestCase):
    def checkState(self, state, child=True, parent=True):
        if child:
            self.assertEqual(self.b_child.state, state)
        if parent:
            self.assertEqual(self.b.state, state)

    def checkSteps(self, configured, completed, total):
        self.assertEqual(self.b.configuredSteps, configured)
        self.assertEqual(self.b.completedSteps, completed)
        self.assertEqual(self.b.totalSteps, total)
        self.assertEqual(self.b_child.configuredSteps, configured)
        self.assertEqual(self.b_child.completedSteps, completed)
        self.assertEqual(self.b_child.totalSteps, total)

    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock",
                                                     configDir="/tmp")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock', configDir="/tmp")
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)

    def tearDown(self):
        self.p.stop()

    def test_init(self):
        # the following block attributes should be created by a call to
        # set_attributes via _set_block_children in __init__
        self.assertEqual(self.b['totalSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['completedSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['configuredSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['axesToMove'].meta.typeid,
                         'malcolm:core/StringArrayMeta:1.0')

        # the following hooks should be created via _find_hooks in __init__
        self.assertEqual(
            self.c.hook_names, {
                self.c.Reset: "Reset",
                self.c.Disable: "Disable",
                self.c.ReportOutports: "ReportOutports",
                self.c.Layout: "Layout",
                self.c.Load: "Load",
                self.c.Save: "Save",
                self.c.Validate: "Validate",
                self.c.ReportStatus: "ReportStatus",
                self.c.Configure: "Configure",
                self.c.PostConfigure: "PostConfigure",
                self.c.Run: "Run",
                self.c.PostRunReady: "PostRunReady",
                self.c.PostRunIdle: "PostRunIdle",
                self.c.Seek: "Seek",
                self.c.Pause: "Pause",
                self.c.Resume: "Resume",
                self.c.Abort: "Abort",
            })

        # check instantiation of object tree via logger names
        self.assertEqual(self.c._logger.name, 'RunnableController(mainBlock)')
        self.assertEqual(self.c.parts['part1']._logger.name,
                         'RunnableController(mainBlock).part1')
        self.assertEqual(self.c.parts['part2']._logger.name,
                         'RunnableController(mainBlock).part2')

    def test_edit(self):
        self.b.edit()
        self.checkState(self.sm.EDITABLE, child=False)

    def test_reset(self):
        self.b.disable()
        self.checkState(self.sm.DISABLED)
        self.b.reset()
        self.checkState(self.sm.IDLE)

    def test_set_axes_to_move(self):
        self.c.set_axes_to_move(['y'])
        self.assertEqual(self.c.axes_to_move.value, ('y', ))

    def test_validate(self):
        line1 = LineGenerator('y', 'mm', 0, 2, 3)
        line2 = LineGenerator('x', 'mm', 0, 2, 2)
        compound = CompoundGenerator([line1, line2], [], [])
        actual = self.b.validate(generator=compound, axesToMove=['x'])
        self.assertEqual(actual["generator"], compound)
        self.assertEqual(actual["axesToMove"], ('x', ))

    def prepare_half_run(self, duration=0.01, exception=0):
        line1 = LineGenerator('y', 'mm', 0, 2, 3)
        line2 = LineGenerator('x', 'mm', 0, 2, 2)
        compound = CompoundGenerator([line1, line2], [], [], duration)
        self.b.configure(generator=compound,
                         axesToMove=['x'],
                         exceptionStep=exception)

    def test_configure_run(self):
        self.prepare_half_run()
        self.checkSteps(2, 0, 6)
        self.checkState(self.sm.READY)

        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(4, 2, 6)

        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(6, 4, 6)

        self.b.run()
        self.checkState(self.sm.IDLE)

    def test_abort(self):
        self.prepare_half_run()
        self.b.run()
        self.b.abort()
        self.checkState(self.sm.ABORTED)

    def test_pause_seek_resume(self):
        self.prepare_half_run()
        self.checkSteps(configured=2, completed=0, total=6)
        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(4, 2, 6)
        self.b.pause(completedSteps=1)
        self.checkState(self.sm.READY)
        self.checkSteps(2, 1, 6)
        self.b.run()
        self.checkSteps(4, 2, 6)
        self.b.completedSteps = 5
        self.checkSteps(6, 5, 6)
        self.b.run()
        self.checkState(self.sm.IDLE)

    def test_resume_in_run(self):
        self.prepare_half_run(duration=0.5)
        w = self.p.spawn(self.b.run)
        time.sleep(0.85)
        self.b.pause()
        self.checkState(self.sm.PAUSED)
        self.checkSteps(2, 1, 6)
        self.b.resume()
        # return to PRERUN should continue original run to completion and
        # READY state
        then = time.time()
        w.wait()
        self.assertAlmostEqual(time.time() - then, 0.5, delta=0.4)
        self.checkState(self.sm.READY)

    def test_run_exception(self):
        self.prepare_half_run(exception=1)
        with self.assertRaises(ResponseError):
            self.b.run()
        self.checkState(self.sm.FAULT)

    def test_run_stop(self):
        self.prepare_half_run(duration=0.5)
        w = self.p.spawn(self.b.run)
        time.sleep(0.5)
        self.b.abort()
        with self.assertRaises(AbortedError):
            w.get()
        self.checkState(self.sm.ABORTED)
class TestRunnableController(unittest.TestCase):

    def checkState(self, state, child=True, parent=True):
        if child:
            self.assertEqual(self.b_child.state, state)
        if parent:
            self.assertEqual(self.b.state, state)

    def checkSteps(self, configured, completed, total):
        self.assertEqual(self.b.configuredSteps, configured)
        self.assertEqual(self.b.completedSteps, completed)
        self.assertEqual(self.b.totalSteps, total)
        self.assertEqual(self.b_child.configuredSteps, configured)
        self.assertEqual(self.b_child.completedSteps, completed)
        self.assertEqual(self.b_child.totalSteps, total)

    def setUp(self):
        self.maxDiff = 5000

        self.p = Process('process1', SyncFactory('threading'))

        # Make a ticker block to act as our child
        params = Ticker.MethodMeta.prepare_input_map(mri="childBlock")
        self.b_child = Ticker(self.p, params)[-1]

        # Make an empty part for our parent
        params = Part.MethodMeta.prepare_input_map(name='part1')
        part1 = Part(self.p, params)

        # Make a RunnableChildPart to control the ticker
        params = RunnableChildPart.MethodMeta.prepare_input_map(
            mri='childBlock', name='part2')
        part2 = RunnableChildPart(self.p, params)

        # create a root block for the RunnableController block to reside in
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, [part1, part2], params)
        self.b = self.c.block
        self.sm = self.c.stateMachine

        # start the process off
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.b["state"], self.sm.IDLE, timeout=1)

        self.checkState(self.sm.IDLE)

    def tearDown(self):
        self.p.stop()

    def test_init(self):
        # the following block attributes should be created by a call to
        # set_attributes via _set_block_children in __init__
        self.assertEqual(self.b['totalSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['layout'].meta.typeid,
                         'malcolm:core/TableMeta:1.0')
        self.assertEqual(self.b['completedSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['configuredSteps'].meta.typeid,
                         'malcolm:core/NumberMeta:1.0')
        self.assertEqual(self.b['axesToMove'].meta.typeid,
                         'malcolm:core/StringArrayMeta:1.0')
        self.assertEqual(self.b['layoutName'].meta.typeid,
                         'malcolm:core/StringMeta:1.0')

        # the following hooks should be created via _find_hooks in __init__
        self.assertEqual(self.c.hook_names, {
            self.c.Reset: "Reset",
            self.c.Disable: "Disable",
            self.c.ReportOutports: "ReportOutports",
            self.c.Layout: "Layout",
            self.c.Load: "Load",
            self.c.Save: "Save",
            self.c.Validate: "Validate",
            self.c.ReportStatus: "ReportStatus",
            self.c.Configure: "Configure",
            self.c.PostConfigure: "PostConfigure",
            self.c.Run: "Run",
            self.c.PostRunReady: "PostRunReady",
            self.c.PostRunIdle: "PostRunIdle",
            self.c.Seek: "Seek",
            self.c.Pause: "Pause",
            self.c.Resume: "Resume",
            self.c.Abort: "Abort",
        })

        # check instantiation of object tree via logger names
        self.assertEqual(self.c._logger.name,
                         'RunnableController(mainBlock)')
        self.assertEqual(self.c.parts['part1']._logger.name,
                         'RunnableController(mainBlock).part1')
        self.assertEqual(self.c.parts['part2']._logger.name,
                         'RunnableController(mainBlock).part2')

    def test_edit(self):
        self.b.edit()
        self.checkState(self.sm.EDITABLE, child=False)

    def test_reset(self):
        self.b.disable()
        self.checkState(self.sm.DISABLED)
        self.b.reset()
        self.checkState(self.sm.IDLE)

    def test_set_axes_to_move(self):
        self.c.set_axes_to_move(['y'])
        self.assertEqual(self.c.axes_to_move.value, ['y'])

    def test_validate(self):
        line1 = LineGenerator('y', 'mm', 0, 2, 3)
        line2 = LineGenerator('x', 'mm', 0, 2, 2)
        compound = CompoundGenerator([line1, line2], [], [])
        actual = self.b.validate(generator=compound, axesToMove=['x'])
        self.assertEqual(actual["generator"], compound)
        self.assertEqual(actual["axesToMove"], ['x'])

    def prepare_half_run(self, duration=0.01, exception=0):
        line1 = LineGenerator('y', 'mm', 0, 2, 3)
        line2 = LineGenerator('x', 'mm', 0, 2, 2)
        duration = FixedDurationMutator(duration)
        compound = CompoundGenerator([line1, line2], [], [duration])
        self.b.configure(
            generator=compound, axesToMove=['x'], exceptionStep=exception)

    def test_configure_run(self):
        self.prepare_half_run()
        self.checkSteps(2, 0, 6)
        self.checkState(self.sm.READY)

        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(4, 2, 6)

        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(6, 4, 6)

        self.b.run()
        self.checkState(self.sm.IDLE)

    def test_abort(self):
        self.prepare_half_run()
        self.b.run()
        self.b.abort()
        self.checkState(self.sm.ABORTED)

    def test_pause_seek_resume(self):
        self.prepare_half_run()
        self.checkSteps(configured=2, completed=0, total=6)
        self.b.run()
        self.checkState(self.sm.READY)
        self.checkSteps(4, 2, 6)
        self.b.pause(completedSteps=1)
        self.checkState(self.sm.READY)
        self.checkSteps(2, 1, 6)
        self.b.run()
        self.checkSteps(4, 2, 6)
        self.b.completedSteps = 5
        self.checkSteps(6, 5, 6)
        self.b.run()
        self.checkState(self.sm.IDLE)

    def test_resume_in_run(self):
        self.prepare_half_run(duration=0.5)
        w = self.p.spawn(self.b.run)
        time.sleep(0.85)
        self.b.pause()
        self.checkState(self.sm.PAUSED)
        self.checkSteps(2, 1, 6)
        self.b.resume()
        # return to PRERUN should continue original run to completion and
        # READY state
        then = time.time()
        w.wait()
        self.assertAlmostEqual(time.time() - then, 0.5, delta=0.4)
        self.checkState(self.sm.READY)

    def test_run_exception(self):
        self.prepare_half_run(exception=1)
        with self.assertRaises(ResponseError):
            self.b.run()
        self.checkState(self.sm.FAULT)

    def test_run_stop(self):
        self.prepare_half_run(duration=0.5)
        w = self.p.spawn(self.b.run)
        time.sleep(0.5)
        self.b.abort()
        with self.assertRaises(AbortedError):
            w.get()
        self.checkState(self.sm.ABORTED)
Example #8
0
class TestChildPart(unittest.TestCase):

    def checkState(self, state):
        self.assertEqual(self.c.state.value, state)

    def makeChildBlock(self, blockMri):
        params = PortsPart.MethodMeta.prepare_input_map(name='Connector')
        port_part = PortsPart(self.p, params)

        partName = 'part%s' % blockMri
        params = DefaultController.MethodMeta.prepare_input_map(mri=blockMri)
        controller = DefaultController(self.p, [port_part], params)

        params = ChildPart.MethodMeta.prepare_input_map(
            mri=blockMri, name=partName)
        part = ChildPart(self.p, params)

        return part, controller

    def setUp(self):
        self.p = Process('process1', SyncFactory('threading'))

        self.p1, self.c1 = self.makeChildBlock('child1')
        self.p2, self.c2 = self.makeChildBlock('child2')
        self.p3, self.c3 = self.makeChildBlock('child3')

        # create a root block for the child blocks to reside in
        parts = [self.p1, self.p2, self.p3]
        params = RunnableController.MethodMeta.prepare_input_map(
            mri='mainBlock')
        self.c = RunnableController(self.p, parts, params)
        self.b = self.c.block

        params = ChildPart.MethodMeta.prepare_input_map(
            mri='mainBlock', name='mainPart')
        self.part = ChildPart(self.p, params)

        # Get the parent block into idle state
        self.p.start()

        # wait until block is Ready
        task = Task("block_ready_task", self.p)
        task.when_matches(self.c.block["state"], sm.IDLE, timeout=1)

        self.checkState(sm.IDLE)

    def tearDown(self):
        self.p.stop()

    def test_init(self):
        # check instantiation of object tree via logger names
        self.assertEqual(self.c._logger.name,
                         'RunnableController(mainBlock)')
        self.assertEqual(self.c.parts['partchild1']._logger.name,
                         'RunnableController(mainBlock).partchild1')
        self.assertEqual(self.c.parts['partchild2']._logger.name,
                         'RunnableController(mainBlock).partchild2')
        self.assertEqual(self.c.parts['partchild3']._logger.name,
                         'RunnableController(mainBlock).partchild3')

        self.assertEqual(self.c1.parts['Connector']._logger.name,
                         'DefaultController(child1).Connector')
        self.assertEqual(self.c2.parts['Connector']._logger.name,
                         'DefaultController(child2).Connector')
        self.assertEqual(self.c3.parts['Connector']._logger.name,
                         'DefaultController(child3).Connector')

        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c1.block.outportConnector, '')

    def test_reset(self):
        # TODO cover the clause 'state == RESETTING'
        self.c.disable()
        self.checkState(sm.DISABLED)
        self.c.reset()
        self.checkState(sm.IDLE)

    def test_pre_layout(self):
        outports = self.p1.pre_layout(None)
        self.assertEqual(len(outports), 1)

    def test_layout(self):
        self.c.edit()
        self.checkState(sm.EDITABLE)

        new_layout = Table(self.c.layout.meta)
        new_layout.name = ["partchild1", "partchild2", "partchild3"]
        new_layout.mri = ["part1", "part2", "part3"]
        new_layout.x = [10, 11, 12]
        new_layout.y = [20, 21, 22]
        new_layout.visible = [True, True, True]
        self.b.layout = new_layout
        self.assertEqual(self.c.parts['partchild1'].x, 10)
        self.assertEqual(self.c.parts['partchild1'].y, 20)
        self.assertEqual(self.c.parts['partchild1'].visible, True)
        self.assertEqual(self.c.parts['partchild2'].x, 11)
        self.assertEqual(self.c.parts['partchild2'].y, 21)
        self.assertEqual(self.c.parts['partchild2'].visible, True)
        self.assertEqual(self.c.parts['partchild3'].x, 12)
        self.assertEqual(self.c.parts['partchild3'].y, 22)
        self.assertEqual(self.c.parts['partchild3'].visible, True)

        new_layout.visible = [True, False, True]
        self.b.layout= new_layout
        self.assertEqual(self.c.parts['partchild1'].visible, True)
        self.assertEqual(self.c.parts['partchild2'].visible, False)
        self.assertEqual(self.c.parts['partchild3'].visible, True)

    def test_sever_all_inports(self):
        self.c1.block.inportConnector = 'Connector'
        self.c2.block.inportConnector = 'Connector'
        self.c3.block.inportConnector = 'Connector3'

        task = Task("Task1" , self.p)
        self.p1.sever_all_inports(task)
        task.wait_all([],5)
        self.assertEqual(self.c1.block.inportConnector, '')
        self.assertEqual(self.c2.block.inportConnector, 'Connector')
        self.assertEqual(self.c3.block.inportConnector, 'Connector3')

    def test_sever_inports_connected_to(self):
        self.c1.block.inportConnector = 'Connector'

        self.assertEqual(self.c1.block.inportConnector, 'Connector')

        task = Task("Task1" , self.p)
        out_port = {'Connector': 'pos'}
        self.p1.sever_inports_connected_to(task, out_port)
        self.assertEqual(self.c1.block.inportConnector, '')

    def test_get_flowgraph_ports(self):
        count = len(self.p1._get_flowgraph_ports('out'))
        self.assertEqual(count, 1)
        count = len(self.p1._get_flowgraph_ports('in'))
        self.assertEqual(count, 1)