コード例 #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
コード例 #2
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, 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)
コード例 #5
0
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]
コード例 #6
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]
コード例 #7
0
def test_dot_muncher_with_consecutive_dot():
    buf = mutable_string("No...")
    results = dot_muncher(buf)
    assert list(results) == [0x76, 0x1d | 0x80, 0x80, 0x80]
コード例 #8
0
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]
コード例 #10
0
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]
コード例 #18
0
def test_regular_skips_unknown():
    buf = mutable_string("B&B")
    results = regular(buf, notfound=None)
    assert list(results) == [0x7f, 0x7f]
コード例 #19
0
ファイル: test_util.py プロジェクト: xwJohn/luma.core
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]
コード例 #24
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]
コード例 #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]
コード例 #28
0
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]
コード例 #30
0
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]
コード例 #32
0
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]
コード例 #34
0
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
コード例 #36
0
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
コード例 #38
0
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
コード例 #40
0
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]