Beispiel #1
0
 def test_reset_removes_any_subscribers(self):
     observer = Observer()
     callback = mock.Mock()
     observer.subscribe(callback)
     observer.reset()
     observer.notify()
     callback.assert_not_called()
Beispiel #2
0
 def test_can_pass_arguments_to_objects(self):
     observer = Observer()
     callback = mock.Mock()
     observer.subscribe(callback)
     observer.notify("0000")
     arg_list = callback.call_args[0]
     # This is because we are using args and kwargs
     expected = ("0000", )
     self.assertEqual(arg_list, expected)
Beispiel #3
0
 def test_can_notify_multiple_objects(self):
     observer = Observer()
     callback1 = mock.Mock()
     observer.subscribe(callback1)
     callback2 = mock.Mock()
     observer.subscribe(callback2)
     observer.notify()
     callback1.assert_called()
     callback2.assert_called()
Beispiel #4
0
class ControlButton(PyQt5.QtWidgets.QLabel):
    def __init__(self, image, height, callback, parent=None):
        super(ControlButton, self).__init__(parent)
        self._signal = Observer()
        self._signal.subscribe(callback)
        pixmap = PyQt5.QtGui.QPixmap(image)
        self.setPixmap(pixmap.scaledToHeight(height))

    def onMouseRelease(self, _):
        self._signal.notify()
Beispiel #5
0
class TextSetting(LineEdit):
    def __init__(self, label="", parent=None):
        super(TextSetting, self).__init__(label, parent)
        self._signal = Observer()

    def get_value(self):
        return self.text()

    def connect(self, function):
        self._signal.subscribe(function)

    def focusInEvent(self, e):
        super(TextSetting, self).focusInEvent(e)
        self._signal.notify(self.mapToGlobal(PyQt5.QtCore.QPoint(0, 0)).y())
Beispiel #6
0
 def test_throws_error_if_object_expects_different_arguments_to_notify(
         self):
     observer = Observer()
     observer.subscribe(lambda arg1, arg2: print(arg1, arg2))
     self.assertRaises(ValueError, observer.notify, "0000")
Beispiel #7
0
 def test_callback_called_by_notify(self):
     observer = Observer()
     callback = mock.Mock()
     observer.subscribe(callback)
     observer.notify()
     callback.assert_called()