コード例 #1
0
ファイル: test_text_style.py プロジェクト: GinLuc/terminedia
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'
コード例 #2
0
ファイル: test_text_style.py プロジェクト: GinLuc/terminedia
def test_styled_sequence_mark_objects_can_be_sequence(attrname, value, attr2,
                                                      value2):
    sc, sh, text_plane = styled_text()
    msg = "Hello World!"
    aa = StyledSequence(msg, {
        0:
        [Mark(attributes={attrname: value}),
         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
        assert getattr(sc.data[i, 0], attr2) == value2
コード例 #3
0
ファイル: test_text_style.py プロジェクト: GinLuc/terminedia
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
コード例 #4
0
ファイル: test_text_style.py プロジェクト: GinLuc/terminedia
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")
コード例 #5
0
ファイル: test_text_style.py プロジェクト: GinLuc/terminedia
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