Esempio n. 1
0
def test_styled_sequence_move_and_relative_move_work(moveto, rmoveto,
                                                     expected_pos, method):
    sc, sh, text_plane = styled_text()
    msg = "01234566789"
    if method == "merged":
        mark_seq = Mark(moveto=moveto, rmoveto=rmoveto)
    elif method == "sequence":
        mark_seq = [Mark(moveto=moveto), Mark(rmoveto=rmoveto)]

    # let's trhow in some color -
    r = random.Random(hash((moveto, rmoveto, method)))
    pos = r.randrange(0, 5)
    attr = r.choice(["color", "background"])
    color = r.choice(["yellow", "red", "green", "blue"])

    aa = StyledSequence(msg, {
        pos: Mark(attributes={attr: color}),
        5: mark_seq,
    }, text_plane)
    aa.render()
    sc.update()
    yield None
    # TODO: these should be aliased in TM.Context class.
    assert sc.data[5,
                   0].value == TM.values.EMPTY if expected_pos != (5,
                                                                   0) else True
    assert sc.data[expected_pos].value == '5'
Esempio n. 2
0
def test_styled_sequence_is_rendered():
    sc, sh, text_plane = styled_text()
    msg = "Hello World!"
    aa = StyledSequence(msg, {}, text_plane)
    aa.render()
    sc.update()
    yield None
    for i, char in enumerate(msg):
        assert sc.data[i, 0].value == char
Esempio n. 3
0
def test_styled_sequence_retrives_marks_from_text_plane():
    sc, sh, text_plane = styled_text()
    text_plane.marks[1, 0] = Mark(attributes={"color": TM.Color("yellow")})
    msg = "Hello World!"
    aa = StyledSequence(msg, {}, text_plane)
    aa.render()
    sc.update()
    yield None
    assert sc.data[0, 0].foreground == TM.DEFAULT_FG
    for i, letter in enumerate(msg[1:], 1):
        assert sc.data[i, 0].foreground == TM.Color("yellow")
Esempio n. 4
0
def test_styled_sequence_is_rendered_with_attribute(attrname, value):
    sc, sh, text_plane = styled_text()
    msg = "Hello World!"
    aa = StyledSequence(msg, {0: Mark(attributes={attrname: value})},
                        text_plane)
    aa.render()
    sc.update()
    yield None
    # TODO: these should be aliased in TM.Context class.
    if attrname == "color":
        attrname = "foreground"
    for i, char in enumerate(msg):
        assert getattr(sc.data[i, 0], attrname) == value
Esempio n. 5
0
def test_styled_sequence_can_handle_pretransformers():
    sc, sh, text_plane = styled_text()
    msg = "0123456789"
    tt = TM.Transformer(
        foreground=lambda pos: TM.Color((pos[0] * 25 % 256, 0, 0)),
        background=lambda pos: TM.Color((0, 0, (255 - pos[0] * 25) % 256)),
    )
    aa = StyledSequence(msg, {0: TM.Mark(attributes={"pretransformer": tt})},
                        text_plane)
    aa.render()
    sc.update()
    yield None
    assert sc.data[0, 0].foreground == TM.Color((0, 0, 0))
    assert sc.data[0, 0].background == TM.Color((0, 0, 255))
    assert sc.data[9, 0].foreground == TM.Color((225, 0, 0))
    assert sc.data[9, 0].background == TM.Color((0, 0, 30))
Esempio n. 6
0
def test_styled_sequence_pops_attributes(pos1, attrname, value, pos2, default):
    sc, sh, text_plane = styled_text()
    msg = "Hello World!"
    aa = StyledSequence(
        msg, {
            pos1: Mark(attributes={attrname: value}),
            pos2: Mark(pop_attributes={attrname: None})
        }, text_plane)
    aa.render()
    sc.update()
    yield None
    # TODO: these should be aliased in TM.Context class.
    if attrname == "color":
        attrname = "foreground"
    for i, char in enumerate(msg):
        if pos1 <= i < pos2:
            assert getattr(sc.data[i, 0], attrname) == value
        else:
            assert getattr(sc.data[i, 0], attrname) == default
Esempio n. 7
0
def test_styled_sequence_adds_attributes_at_mark(attrname, value, position,
                                                 attr2, value2):
    sc, sh, text_plane = styled_text()
    msg = "Hello World!"
    aa = StyledSequence(
        msg, {
            0: Mark(attributes={attrname: value}),
            position: Mark(attributes={attr2: value2})
        }, text_plane)
    aa.render()
    sc.update()
    yield None
    # TODO: these should be aliased in TM.Context class.
    if attrname == "color":
        attrname = "foreground"
    for i, char in enumerate(msg):
        assert getattr(sc.data[i, 0], attrname) == value
        if i >= position:
            assert getattr(sc.data[i, 0], attr2) == value2
        else:
            assert getattr(sc.data[i, 0], attr2) != value2