コード例 #1
0
 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)
コード例 #2
0
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, [])
コード例 #3
0
 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()
コード例 #4
0
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, [])
コード例 #5
0
ファイル: blockgui.py プロジェクト: shroffk/pymalcolm
 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)
コード例 #6
0
ファイル: test_blockmodel.py プロジェクト: shroffk/pymalcolm
 def setUp(self):
     self.process = MagicMock()
     self.block = Hello(self.process, dict(mri="hello"))[0]
     self.m = BlockModel(self.process, self.block)