Example #1
0
    def test_cb_subscribed(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)
        cb = MagicMock()

        v.subscribe(cb)
        v.value = 2
        cb.assert_called_with(2)
Example #2
0
    def test_cb_unsusbcribed(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)
        cb = MagicMock()

        v.subscribe(cb)
        v.unsubscribe(cb)
        v.value = 2
        self.assertFalse(cb.called)
Example #3
0
    def test_clone_cb(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)
        cb = MagicMock()
        cb_clone = MagicMock()

        v.subscribe(cb)
        v_clone = v.clone()
        v_clone.subscribe(cb_clone)
        v_clone.value = 3

        self.assertFalse(cb.called)
        cb_clone.assert_called_with(3)
Example #4
0
    def test_cb_subscribed_no_change(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)
        cb = MagicMock()
        v.value = 2
        v.subscribe(cb)

        # The callback must be called only if the value has really changed
        v.value = 2
        self.assertFalse(cb.called)
        v.value = 3
        cb.assert_called_with(3)
        cb.reset_mock()

        v.value = 3
        self.assertFalse(cb.called)