Пример #1
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)
Пример #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)
Пример #3
0
    def test_lock_released(self):
        b = Block()
        b.name = "blockname"
        b.lock.acquire = MagicMock(wrap=b.lock.acquire)
        b.lock.release = MagicMock(wrap=b.lock.release)
        lock_methods = MagicMock()
        lock_methods.attach_mock(b.lock.acquire, "acquire")
        lock_methods.attach_mock(b.lock.release, "release")

        with b.lock:
            with b.lock_released():
                pass

        self.assertEquals(
            [call.acquire(), call.release(), call.acquire(), call.release()],
            lock_methods.method_calls)
Пример #4
0
    def test_lock_released(self):
        b = Block()
        b.name = "blockname"
        b.lock.acquire = MagicMock(wrap=b.lock.acquire)
        b.lock.release = MagicMock(wrap=b.lock.release)
        lock_methods = MagicMock()
        lock_methods.attach_mock(b.lock.acquire, "acquire")
        lock_methods.attach_mock(b.lock.release, "release")

        with b.lock:
            with b.lock_released():
                pass

        self.assertEquals(
            [call.acquire(),
             call.release(),
             call.acquire(),
             call.release()], lock_methods.method_calls)
Пример #5
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"))
Пример #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"))