Esempio n. 1
0
 def test_put_changes_value(self):
     b = Block()
     b.on_changed = Mock(wraps=b.on_changed)
     c = CounterController(Mock(), b, 'block')
     b.on_changed.reset_mock()
     c.counter.put(32)
     self.assertEqual(c.counter.value, 32)
     c.block.on_changed.assert_called_once_with([["counter", "value"], 32],
                                                True)
Esempio n. 2
0
 def test_add_attribute(self):
     b = Block()
     b.name = 'block'
     b.on_changed = MagicMock(side_effect=b.on_changed)
     attr = MagicMock()
     b.add_attribute("attr", attr)
     attr.set_parent.assert_called_once_with(b, "attr")
     self.assertEqual({"attr":attr}, b.attributes)
     self.assertIs(attr, b.attr)
     b.on_changed.assert_called_with(
         [[attr.name], attr.to_dict.return_value], True)
Esempio n. 3
0
 def test_add_method_registers(self):
     b = Block()
     b.on_changed = MagicMock(side_effect=b.on_changed)
     m = MagicMock()
     b.add_method("mymethod", m)
     self.assertEqual(list(b.methods), ["mymethod"])
     self.assertFalse(m.called)
     b.on_changed.assert_called_with([[m.name], m.to_dict.return_value], True)
     m.return_value = 42
     self.assertEqual(b.mymethod(), 42)
     m.assert_called_once_with()
Esempio n. 4
0
 def test_add_attribute(self):
     b = Block()
     b.name = 'block'
     b.on_changed = MagicMock(side_effect=b.on_changed)
     attr = MagicMock()
     b.add_attribute("attr", attr)
     attr.set_parent.assert_called_once_with(b, "attr")
     self.assertEqual({"attr": attr}, b.attributes)
     self.assertIs(attr, b.attr)
     b.on_changed.assert_called_with(
         [[attr.name], attr.to_dict.return_value], True)
Esempio n. 5
0
 def test_add_method_registers(self):
     b = Block()
     b.on_changed = MagicMock(side_effect=b.on_changed)
     m = MagicMock()
     b.add_method("mymethod", m)
     self.assertEqual(list(b.methods), ["mymethod"])
     self.assertFalse(m.called)
     b.on_changed.assert_called_with([[m.name], m.to_dict.return_value],
                                     True)
     m.return_value = 42
     self.assertEqual(b.mymethod(), 42)
     m.assert_called_once_with()
Esempio n. 6
0
 def test_replace_children(self):
     b = Block()
     b.name = "blockname"
     b.methods["m1"] = 2
     b.attributes["a1"] = 3
     setattr(b, "m1", 2)
     setattr(b, "a1", 3)
     attr_meta = StringMeta(description="desc")
     attr = Attribute(attr_meta)
     b.add_attribute('attr', attr)
     method = Method(description="desc")
     b.add_method('method', method)
     b.on_changed = MagicMock(wrap=b.on_changed)
     b.replace_children({'attr': attr, 'method': method})
     self.assertEqual(b.attributes, dict(attr=attr))
     self.assertEqual(b.methods, dict(method=method))
     b.on_changed.assert_called_once_with([[], b.to_dict()], True)
     self.assertFalse(hasattr(b, "m1"))
     self.assertFalse(hasattr(b, "a1"))
Esempio n. 7
0
 def test_replace_children(self):
     b = Block()
     b.name = "blockname"
     b.methods["m1"] = 2
     b.attributes["a1"] = 3
     setattr(b, "m1", 2)
     setattr(b, "a1", 3)
     attr_meta = StringMeta(description="desc")
     attr = Attribute(attr_meta)
     b.add_attribute('attr', attr)
     method = Method(description="desc")
     b.add_method('method', method)
     b.on_changed = MagicMock(wrap=b.on_changed)
     b.replace_children({'attr':attr, 'method':method})
     self.assertEqual(b.attributes, dict(attr=attr))
     self.assertEqual(b.methods, dict(method=method))
     b.on_changed.assert_called_once_with(
         [[], b.to_dict()], True)
     self.assertFalse(hasattr(b, "m1"))
     self.assertFalse(hasattr(b, "a1"))