示例#1
0
def test_mutablestring():
    f = util.mutable_string('bar')
    f[1] = '2'
    assert f == 'b2r'
    assert repr(f) == repr('b2r')
    assert len(f) == 3
    assert hash(f) is not None
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
    ]
示例#3
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)
示例#4
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)
def test_regular_without_dots():
    buf = mutable_string("Hello world")
    results = regular(buf, notfound='_')
    assert list(results) == [0x37, 0x6f, 0x06, 0x06, 0x1d, 0x00, 0x08, 0x1d, 0x05, 0x06, 0x3d]
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_dot_muncher_with_consecutive_dot():
    buf = mutable_string("No...")
    results = dot_muncher(buf)
    assert list(results) == [0x76, 0x1d | 0x80, 0x80, 0x80]
def test_dot_muncher_skips_unknown():
    buf = mutable_string("B&B")
    results = dot_muncher(buf, notfound=None)
    assert list(results) == [0x7f, 0x7f]
示例#9
0
def test_dot_muncher_with_notfound():
    buf = mutable_string("B&B")
    results = dot_muncher(buf, notfound='_')
    assert list(results) == [0x7f, 0x08, 0x7f]
def test_dot_muncher_with_dot_at_start():
    buf = mutable_string(".PDF")
    results = dot_muncher(buf)
    assert list(results) == [0x80, 0x67, 0x7e, 0x47]
示例#11
0
def test_regular_with_notfound():
    buf = mutable_string("B&B")
    results = regular(buf, notfound='_')
    assert list(results) == [0x7f, 0x08, 0x7f]
示例#12
0
def test_getslice():
    bell = test_bell()
    buf = observable(mutable_string("hello"), bell.ding)
    assert buf[2:4] == "ll"
    assert bell.called == 1
示例#13
0
def test_regular_empty_buf():
    buf = mutable_string("")
    results = regular(buf)
    assert list(results) == []
示例#14
0
def test_regular_skips_unknown():
    buf = mutable_string("B&B")
    results = regular(buf, notfound=None)
    assert list(results) == [0x7f, 0x7f]
示例#15
0
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]
示例#16
0
def test_regular_with_dot():
    buf = mutable_string("3.14159")
    results = regular(buf)
    assert list(results) == [0x79, 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
示例#17
0
def test_regular_without_dots():
    buf = mutable_string("Hello world")
    results = regular(buf, notfound='_')
    assert list(results) == [0x37, 0x6f, 0x06, 0x06, 0x1d, 0x00, 0x14, 0x1d, 0x05, 0x06, 0x3d]
def test_regular_skips_unknown():
    buf = mutable_string("B&B")
    results = regular(buf, notfound=None)
    assert list(results) == [0x7f, 0x7f]
示例#19
0
def test_mutablestring_unicode():
    f = util.mutable_string(u'bazül')
    f[4] = 'L'
    assert f == u'baz\xfcL'
    assert repr(f) == repr(u'baz\xfcL')
    assert len(f) == 5
示例#20
0
def test_dot_muncher_with_dot_at_start():
    buf = mutable_string(".PDF")
    results = dot_muncher(buf)
    assert list(results) == [0x80, 0x67, 0x7e, 0x47]
示例#21
0
def test_dot_muncher_empty_buf():
    buf = mutable_string("")
    results = dot_muncher(buf)
    assert list(results) == []
示例#22
0
def test_mutablestring():
    f = util.mutable_string('bar')
    f[1] = '2'
    assert f == 'b2r'
    assert repr(f) == "'b2r'"
    assert len(f) == 3
示例#23
0
def test_dot_muncher_skips_unknown():
    buf = mutable_string("B&B")
    results = dot_muncher(buf, notfound=None)
    assert list(results) == [0x7f, 0x7f]
def test_degrees_utf8():
    buf = mutable_string(u"29.12\xb0C")
    results = dot_muncher(buf)
    assert list(results) == [0x6d, 0x7b | 0x80, 0x30, 0x6d, 0x63, 0x4e]
示例#25
0
def test_dot_muncher_with_consecutive_dot():
    buf = mutable_string("No...")
    results = dot_muncher(buf)
    assert list(results) == [0x76, 0x1d | 0x80, 0x80, 0x80]
示例#26
0
def test_dot_muncher_without_dots():
    buf = mutable_string("Hello world")
    results = dot_muncher(buf)
    assert list(results) == [
        0x67, 0x3f, 0x05, 0x05, 0x4e, 0x00, 0x08, 0x4e, 0x06, 0x05, 0x6e
    ]
示例#27
0
def test_dot_muncher_without_dots():
    buf = mutable_string("Hello world")
    results = dot_muncher(buf)
    assert list(results) == [0x67, 0x3f, 0x05, 0x05, 0x4e, 0x00, 0x08, 0x4e, 0x06, 0x05, 0x6e]
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]
示例#29
0
def test_dot_muncher_with_dot():
    buf = mutable_string("3.14159")
    results = dot_muncher(buf)
    assert list(results) == [0x7a, 0x60 | 0x80, 0x63, 0x60, 0x5b, 0x7b]
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]
示例#31
0
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, 0x3e, 0x5b, 0x7b, 0x3e, 0x7d | 0x80]
def test_dot_muncher_empty_buf():
    buf = mutable_string("")
    results = dot_muncher(buf)
    assert list(results) == []
示例#33
0
def test_dot_muncher_with_multiple_dot():
    buf = mutable_string("127.0.0.1")
    results = dot_muncher(buf)
    assert list(results) == [0x60, 0x3e, 0x70, 0x7d | 0x80, 0x7d | 0x80, 0x60 | 0x80]
def test_dot_muncher_with_notfound():
    buf = mutable_string("B&B")
    results = dot_muncher(buf, notfound='_')
    assert list(results) == [0x7f, 0x08, 0x7f]
示例#35
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
def test_regular_with_dot():
    buf = mutable_string("3.14159")
    results = regular(buf)
    assert list(results) == [0x79, 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
示例#37
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
def test_regular_empty_buf():
    buf = mutable_string("")
    results = regular(buf)
    assert list(results) == []
示例#39
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
def test_regular_with_notfound():
    buf = mutable_string("B&B")
    results = regular(buf, notfound='_')
    assert list(results) == [0x7f, 0x08, 0x7f]
示例#41
0
def test_degrees_utf8():
    buf = mutable_string(u"29.12\xb0C")
    results = dot_muncher(buf)
    assert list(results) == [0x6d, 0x7b | 0x80, 0x30, 0x6d, 0x63, 0x4e]