def setUp(self):
     self.process = MagicMock()
     part = HelloPart(self.process, None)
     self.block = DefaultController("hello",
                                    self.process,
                                    parts={
                                        "hello": part
                                    }).block
     self.block.name = "hello"
     self.m = BlockModel(self.process, self.block)
class TestBlockModel(unittest.TestCase):
    def setUp(self):
        self.process = MagicMock()
        part = HelloPart(self.process, None)
        self.block = DefaultController("hello",
                                       self.process,
                                       parts={
                                           "hello": part
                                       }).block
        self.block.name = "hello"
        self.m = BlockModel(self.process, self.block)

    def test_init(self):
        self.assertEqual(self.process.q.put.call_count, 2)
        req = self.process.q.put.call_args_list[0][0][0]
        self.assertEqual(req.endpoint, ['hello', 'reset'])
        req = self.process.q.put.call_args_list[1][0][0]
        self.assertEqual(req.endpoint, ['hello'])
        self.assertEqual(self.m.root_item.endpoint, ('hello', ))
        self.assertEqual(len(self.m.root_item.children), 0)

    def test_find_item(self):
        m1, m2 = MagicMock(), MagicMock()
        BlockItem.items[("foo", "bar")] = m1
        BlockItem.items[("foo", )] = m2
        item, path = self.m.find_item(('foo', 'bar', 'bat'))
        self.assertEqual(item, m1)
        self.assertEqual(path, ['bat'])

    def test_update_root(self):
        d = self.block.to_dict()
        self.m.handle_changes([[[], d]])
        b_item = self.m.root_item
        self.assertEqual(len(b_item.children), 6)
        m_item = b_item.children[5]
        self.assertEqual(m_item.endpoint, ('hello', 'say_hello'))
        self.assertEqual(len(m_item.children), 2)
        n_item = m_item.children[0]
        self.assertEqual(n_item.endpoint,
                         ('hello', 'say_hello', 'takes', 'elements', 'name'))
        self.assertEqual(n_item.children, [])
        n_item = m_item.children[1]
        self.assertEqual(n_item.endpoint,
                         ('hello', 'say_hello', 'takes', 'elements', 'sleep'))
        self.assertEqual(n_item.children, [])
 def __init__(self, process, block):
     QTreeView.__init__(self)
     model = BlockModel(process, block)
     self.setModel(model)
     self.setColumnWidth(0, 160)
     self.setColumnWidth(1, 180)
     self.setColumnWidth(2, 25)
     self.resize(QSize(370, 800))
     self.setItemDelegateForColumn(1, Delegate())
     self.setEditTriggers(self.AllEditTriggers)
     self.expanded.connect(self.write_expanded)
     self.collapsed.connect(self.write_collapsed)
     self.show()
class TestBlockModel(unittest.TestCase):
    def setUp(self):
        self.process = MagicMock()
        self.block = Hello(self.process, dict(mri="hello"))[0]
        self.m = BlockModel(self.process, self.block)

    def test_init(self):
        self.assertEqual(self.process.q.put.call_count, 1)
        req = self.process.q.put.call_args_list[0][0][0]
        self.assertEqual(req.endpoint, ['hello'])
        self.assertEqual(self.m.root_item.endpoint, ('hello',))
        self.assertEqual(len(self.m.root_item.children), 0)

    def test_find_item(self):
        m1, m2 = MagicMock(), MagicMock()
        BlockItem.items[("foo", "bar")] = m1
        BlockItem.items[("foo",)] = m2
        item, path = self.m.find_item(('foo', 'bar', 'bat'))
        self.assertEqual(item, m1)
        self.assertEqual(path, ['bat'])

    def test_update_root(self):
        d = self.block.to_dict()
        self.m.handle_changes([[[], d]])
        b_item = self.m.root_item
        self.assertEqual(len(b_item.children), 6)
        m_item = b_item.children[5]
        self.assertEqual(m_item.endpoint, ('hello', 'greet'))
        self.assertEqual(len(m_item.children), 2)
        n_item = m_item.children[0]
        self.assertEqual(n_item.endpoint,
                         ('hello', 'greet', 'takes', 'elements', 'name'))
        self.assertEqual(n_item.children, [])
        n_item = m_item.children[1]
        self.assertEqual(n_item.endpoint,
                         ('hello', 'greet', 'takes', 'elements', 'sleep'))
        self.assertEqual(n_item.children, [])
Exemple #5
0
 def __init__(self, process, block):
     QTreeView.__init__(self)
     model = BlockModel(process, block)
     self.setModel(model)
     self.setWindowTitle("%s: imalcolm" % model.block_path[0])
     root = os.path.join(os.path.dirname(__file__), "..", "..")
     icon_path = os.path.join(root, "docs", "malcolm-logo.svg")
     self.setWindowIcon(QIcon(icon_path))
     self.setColumnWidth(0, 160)
     self.setColumnWidth(1, 180)
     self.setColumnWidth(2, 25)
     self.resize(QSize(370, 500))
     self.setItemDelegateForColumn(1, Delegate())
     self.setEditTriggers(self.AllEditTriggers)
     self.expanded.connect(self.write_expanded)
     self.collapsed.connect(self.write_collapsed)
Exemple #6
0
 def setUp(self):
     self.process = MagicMock()
     self.block = Hello(self.process, dict(mri="hello"))[0]
     self.m = BlockModel(self.process, self.block)