def test_dot_muncher_with_dot_at_end():
    buf = mutable_string("  525920")
    buf[7:] = "0."
    print(buf)
    results = dot_muncher(buf)
    assert list(results) == [
        0x00, 0x00, 0x5b, 0x6d, 0x5b, 0x7b, 0x6d, 0x7e | 0x80
    ]
Exemple #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: string
        """
        self._text_buffer = observable(mutable_string(value),
                                       observer=self._flush)
def test_dot_muncher_without_dots():
    buf = mutable_string("Hello world")
    results = dot_muncher(buf)
    assert list(results) == [
        0x37, 0x6f, 0x06, 0x06, 0x1d, 0x00, 0x08, 0x1d, 0x05, 0x06, 0x3d
    ]
def test_regular_empty_buf():
    buf = mutable_string("")
    results = regular(buf)
    assert list(results) == []
def test_regular_with_multiple_dot():
    buf = mutable_string("127.0.0.1")
    results = regular(buf)
    assert list(results) == [
        0x30, 0x6d, 0x70, 0x80, 0x7e, 0x80, 0x7e, 0x80, 0x30
    ]
def test_regular_with_dot():
    buf = mutable_string("3.14159")
    results = regular(buf)
    assert list(results) == [0x79, 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
def test_dot_muncher_empty_buf():
    buf = mutable_string("")
    results = dot_muncher(buf)
    assert list(results) == []
def test_dot_muncher_with_multiple_dot():
    buf = mutable_string("127.0.0.1")
    results = dot_muncher(buf)
    assert list(results) == [
        0x30, 0x6d, 0x70 | 0x80, 0x7e | 0x80, 0x7e | 0x80, 0x30
    ]
def test_dot_muncher_with_dot():
    buf = mutable_string("3.14159")
    results = dot_muncher(buf)
    assert list(results) == [0x79 | 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
Exemple #10
0
def test_getslice():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    assert buf[2:4] == "ll"
    assert bell.called == 1
Exemple #11
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
Exemple #12
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
Exemple #13
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