Ejemplo n.º 1
0
    def text(self, value):
        """
        Updates the display with the given value.

        :param value: The value to render onto the device. Any characters which
            cannot be rendered will be converted into the ``undefined``
            character supplied in the constructor. Newline characters '\n' work
            as expected but no other control characters (e.g. \r) are honored.
        :type value: str
        """
        self._text_buffer = observable(mutable_string(value),
                                       observer=self._flush)
Ejemplo n.º 2
0
    def text(self, value):
        """
        Updates the seven-segment display with the given value. If there is not
        enough space to show the full text, an ``OverflowException`` is raised.

        :param value: The value to render onto the device. Any characters which
            cannot be rendered will be converted into the ``undefined``
            character supplied in the constructor.
        :type value: str
        """
        self._text_buffer = observable(mutable_string(value),
                                       observer=self._flush)
Ejemplo n.º 3
0
    def color(self, value):
        if not isinstance(value, list):
            value = [value] * self.device.width

        assert (len(value) == self.device.width)
        self._colors = observable(value, observer=self._color_chg)
Ejemplo n.º 4
0
def test_repr():
    bell = test_bell()
    buf = observable(bytearray("hello", "utf-8"), bell.ding)
    assert repr(buf) == "bytearray(b'hello')"
    assert bell.called == 1
Ejemplo n.º 5
0
def test_delitem():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    del buf[4]
    assert str(buf) == "hell"
    assert bell.called == 2
Ejemplo n.º 6
0
def test_getslice():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    assert buf[2:4] == "ll"
    assert bell.called == 1
Ejemplo n.º 7
0
def test_setslice():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    buf[1:4] = "ipp"
    assert str(buf) == "hippo"
    assert bell.called == 2
Ejemplo n.º 8
0
def test_setitem():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    buf[0] = "y"
    assert str(buf) == "yello"
    assert bell.called == 2
Ejemplo n.º 9
0
def test_getattribute():
    bell = test_bell()
    buf = observable(bytearray("hello", "utf-8"), bell.ding)
    assert list(iter(buf.decode("utf-8"))) == list("hello")
    assert bell.called == 1
Ejemplo n.º 10
0
def test_iteration():
    bell = test_bell()
    buf = observable(bytearray("hello", "utf-8"), bell.ding)
    assert list(iter(buf)) == [ord(ch) for ch in "hello"]
    assert bell.called == 1
Ejemplo n.º 11
0
def test_length():
    bell = test_bell()
    buf = observable(bytearray("hello", "utf-8"), bell.ding)
    assert len(buf) == 5
    assert bell.called == 1