Example #1
0
def test_length():
    styled = red('text')
    assert len(styled) == 4

    empty = red('')
    assert len(empty) == 0

    with pytest.raises(TypeError):
        len(red(None))
Example #2
0
def test_bool():
    content = red('text')
    assert bool(content) == True

    empty = red('')
    assert bool(empty) == False

    nothing = red(None)
    assert bool(nothing) == False
Example #3
0
def test_length():
    styled = red('text')
    assert len(styled) == 4

    empty = red('')
    assert len(empty) == 0

    with pytest.raises(TypeError):
        len(red(None))
Example #4
0
def test_bool():
    content = red('text')
    assert bool(content) == True

    empty = red('')
    assert bool(empty) == False

    nothing = red(None)
    assert bool(nothing) == False
Example #5
0
def test_comparsion():
    smaller = red('a')
    greater = red('b')
    assert smaller < greater
    assert smaller <= greater
    assert smaller != greater
    assert not smaller > greater
    assert not smaller >= greater
    assert not smaller == greater

    # different instances should be treated as equal
    equal = red('x')
    twin = red('x')
    assert not equal < twin
    assert not equal > twin
    assert not equal != twin
    assert equal == twin
    assert equal >= twin
    assert equal <= twin
Example #6
0
def test_comparsion():
    smaller = red('a')
    greater = red('b')
    assert smaller < greater
    assert smaller <= greater
    assert smaller != greater
    assert not smaller > greater
    assert not smaller >= greater
    assert not smaller == greater

    # different instances should be treated as equal
    equal = red('x')
    twin = red('x')
    assert not equal < twin
    assert not equal > twin
    assert not equal != twin
    assert equal == twin
    assert equal >= twin
    assert equal <= twin
Example #7
0
def test_slice():
    styled = red('abcd')
    assert str(styled[0]) == '\033[31m' + 'a' + '\033[0m'
    assert str(styled[1]) == '\033[31m' + 'b' + '\033[0m'

    assert str(styled[-1]) == '\033[31m' + 'd' + '\033[0m'
    assert str(styled[-2]) == '\033[31m' + 'c' + '\033[0m'

    assert str(styled[:2]) == '\033[31m' + 'ab' + '\033[0m'
    assert str(styled[2:]) == '\033[31m' + 'cd' + '\033[0m'
    assert str(styled[1:3]) == '\033[31m' + 'bc' + '\033[0m'
Example #8
0
def test_slice():
    styled = red('abcd')
    assert str(styled[0]) == '\033[31m' + 'a' + '\033[0m'
    assert str(styled[1]) == '\033[31m' + 'b' + '\033[0m'

    assert str(styled[-1]) == '\033[31m' + 'd' + '\033[0m'
    assert str(styled[-2]) == '\033[31m' + 'c' + '\033[0m'

    assert str(styled[:2]) == '\033[31m' + 'ab' + '\033[0m'
    assert str(styled[2:]) == '\033[31m' + 'cd' + '\033[0m'
    assert str(styled[1:3]) == '\033[31m' + 'bc' + '\033[0m'
Example #9
0
def test_nested():
    styled = str(red(bold('text')))
    assert (styled == '\033[31;1mtext\033[0m'
            or styled == '\033[1;31mtext\033[0m')
Example #10
0
def test_left_concat():
    styled = red('text')
    combined = 'normal ' + styled
    assert combined == 'normal \033[31mtext\033[0m'
Example #11
0
def test_right_concat():
    styled = red('text')
    combined = styled + ' normal'
    assert combined == '\033[31mtext\033[0m normal'
Example #12
0
def test_split_nested():
    parts = bold(red('a b')).split()
    assert str(parts[0]) == '\033[31;1m' + 'a' + '\033[0m'
    assert str(parts[1]) == '\033[31;1m' + 'b' + '\033[0m'
Example #13
0
def test_nested():
    styled = str(red(bold('text')))
    assert (styled == '\033[31;1mtext\033[0m'
        or styled == '\033[1;31mtext\033[0m')
Example #14
0
def test_iter():
    unstyled = 'abcd'
    styled = red(unstyled)
    for styled_char, unstyled_char in zip(styled, unstyled):
        assert str(styled_char) == '\033[31m' + unstyled_char + '\033[0m'
Example #15
0
def test_str_functions():
    assert red('text').upper() == red('TEXT')
    assert red('TEXT').lower() == red('text')

    # with args
    assert red('text').replace('t', '_') == red('_ex_')

    # format
    assert red('{s}').format(s='text') == red('text')

    # functions that do not return a new str
    assert red('text').isupper() == False
    assert red('TEXT').isupper() == True
    assert red('text').count('t') == 2
Example #16
0
def test_right_concat():
    styled = red('text')
    combined = styled + ' normal'
    assert combined == '\033[31mtext\033[0m normal'
Example #17
0
def test_plus_equals():
    styled = red('text')
    styled += ' normal'
    assert str(styled) == '\033[31mtext\033[0m normal'
Example #18
0
def test_left_concat():
    styled = red('text')
    combined = 'normal ' + styled
    assert combined == 'normal \033[31mtext\033[0m'
Example #19
0
def test_styled_concat():
    styled = red('text')
    also_styled = bold('text')
    s = styled + also_styled
    assert s == '\033[31mtext\033[0m' + '\033[1mtext\033[0m'
Example #20
0
def test_disable():
    disabled = red('text', enabled=False)
    assert str(disabled) == 'text'  # no control chars

    # passed on to new instances
    assert str(disabled.copy_style('abc')) == 'abc'
Example #21
0
def test_join():
    styled = red('-')
    joined = styled.join(['a', 'b'])
    assert joined == 'a' + '\033[31m' + '-' + '\033[0m' + 'b'
Example #22
0
def test_split_nested():
    parts = bold(red('a b')).split()
    assert str(parts[0]) == '\033[31;1m' + 'a' + '\033[0m'
    assert str(parts[1]) == '\033[31;1m' + 'b' + '\033[0m'
Example #23
0
def test_simple():
    styled = str(red('text'))
    assert styled == '\033[31mtext\033[0m'
Example #24
0
def test_multiply():
    styled = red('text')
    assert str(3 * styled) == '\033[31m' + 'texttexttext' + '\033[0m'

    styled *= 3
    assert str(styled) == '\033[31m' + 'texttexttext' + '\033[0m'
Example #25
0
def test_slice_nested():
    styled = red(bold('abcd'))
    assert (str(styled[0]) == '\033[31;1m' + 'a' + '\033[0m'
        or str(styled[0]) == '\033[1;31m' + 'a' + '\033[0m')
Example #26
0
def test_multiply_nested():
    nested = red(bold('text'))
    assert (str(3 * nested) == '\033[31;1mtexttexttext\033[0m'
            or str(3 * nested) == '\033[1;31mtexttexttext\033[0m')
Example #27
0
def test_iter_nested():
    unstyled = 'abcd'
    styled = red(bold(unstyled))
    for styled_char, unstyled_char in zip(styled, unstyled):
        assert (str(styled_char) == '\033[31;1m' + unstyled_char + '\033[0m'
            or str(styled_char) == '\033[1;31m' + unstyled_char + '\033[0m')
Example #28
0
def test_iter():
    unstyled = 'abcd'
    styled = red(unstyled)
    for styled_char, unstyled_char in zip(styled, unstyled):
        assert str(styled_char) == '\033[31m' + unstyled_char + '\033[0m'
Example #29
0
def test_split():
    parts = red('a b').split()
    assert str(parts[0]) == '\033[31m' + 'a' + '\033[0m'
    assert str(parts[1]) == '\033[31m' + 'b' + '\033[0m'
Example #30
0
def test_slice_nested():
    styled = red(bold('abcd'))
    assert (str(styled[0]) == '\033[31;1m' + 'a' + '\033[0m'
            or str(styled[0]) == '\033[1;31m' + 'a' + '\033[0m')
Example #31
0
def test_join():
    styled = red('-')
    joined = styled.join(['a', 'b'])
    assert joined == 'a' + '\033[31m' + '-' + '\033[0m' + 'b'
Example #32
0
def test_simple():
    styled = str(red('text'))
    assert styled == '\033[31mtext\033[0m'
Example #33
0
def test_disable():
    disabled = red('text', enabled=False)
    assert str(disabled) == 'text'  # no control chars

    # passed on to new instances
    assert str(disabled.copy_style('abc')) == 'abc'
Example #34
0
def test_multiply():
    styled = red('text')
    assert str(3 * styled) == '\033[31m' + 'texttexttext' + '\033[0m'

    styled *= 3
    assert str(styled) == '\033[31m' + 'texttexttext' + '\033[0m'
Example #35
0
def test_styled_concat():
    styled = red('text')
    also_styled = bold('text')
    s = styled + also_styled
    assert s == '\033[31mtext\033[0m' + '\033[1mtext\033[0m'
Example #36
0
def test_str_functions():
    assert red('text').upper() == red('TEXT')
    assert red('TEXT').lower() == red('text')

    # with args
    assert red('text').replace('t', '_') == red('_ex_')

    # format
    assert red('{s}').format(s='text') == red('text')

    # functions that do not return a new str
    assert red('text').isupper() == False
    assert red('TEXT').isupper() == True
    assert red('text').count('t') == 2
Example #37
0
def test_plus_equals():
    styled = red('text')
    styled += ' normal'
    assert str(styled) == '\033[31mtext\033[0m normal'
Example #38
0
def test_split():
    parts = red('a b').split()
    assert str(parts[0]) == '\033[31m' + 'a' + '\033[0m'
    assert str(parts[1]) == '\033[31m' + 'b' + '\033[0m'
Example #39
0
def test_multiply_nested():
    nested = red(bold('text'))
    assert (str(3 * nested) == '\033[31;1mtexttexttext\033[0m'
        or str(3 * nested) == '\033[1;31mtexttexttext\033[0m')
Example #40
0
def test_iter_nested():
    unstyled = 'abcd'
    styled = red(bold(unstyled))
    for styled_char, unstyled_char in zip(styled, unstyled):
        assert (str(styled_char) == '\033[31;1m' + unstyled_char + '\033[0m' or
                str(styled_char) == '\033[1;31m' + unstyled_char + '\033[0m')
Example #41
0
def test_equality_ignores_style():
    # for now, test for equality ignores different styles
    assert red('x') == bold('x')
Example #42
0
def test_equality_ignores_style():
    # for now, test for equality ignores different styles
    assert red('x') == bold('x')