示例#1
0
def test_py2():
    """Test python2.x methods."""
    value = Color("{red}this is a test.{/red}")

    assert "\033[31m \033[39m" == Color("{red} {/red}", "latin-1")
    assert "\033[31mabc\033[39m" == Color("{red}\x80abc{/red}", errors="ignore")

    assert "\033[31mthis is a test.\033[39m" == value.decode()
    assert "\033[31mth3s 3s 1 t2st.\033[39m" == value.translate(string.maketrans("aeioum", "123456").decode("latin-1"))
示例#2
0
def test_py2():
    """Test python2.x methods."""
    value = Color('this is a test.')

    assert ' ' == Color(' ', 'latin-1')
    assert 'abc' == Color('\x80abc', errors='ignore')

    assert 'this is a test.' == value.decode()
    assert 'th3s 3s 1 t2st.' == value.translate(string.maketrans('aeiou', '12345').decode('latin-1'))
示例#3
0
def test_py3():
    """Test python3.x methods."""
    value = Color("{red}this is a test.{/red}")

    if hasattr(Color, "casefold"):
        assert "\033[31mss\033[39m" == Color("{red}ß{/red}").casefold()

    actual = Color("{red}{name} was born in {country}{/red}").format_map(_Default(name="Guido"))
    assert "\033[31mGuido was born in country\033[39m" == actual

    assert not Color("{red}var{/red}").isidentifier()
    assert not Color("var-").isidentifier()
    assert not Color("{red}var{/red}").isprintable()
    assert not Color("{red}\0{/red}").isprintable()

    assert "\033[31mth3s 3s 1 t2st.\033[39m" == value.translate(Color.maketrans("aeiou", "12345"))
示例#4
0
def test_py3():
    """Test python3.x methods."""
    value = Color('this is a test.')

    # assert '' == Color(b'', 'latin-1')  bytes has no .format().
    # assert 'abc' == Color(b'\x80abc', errors='ignore')

    if hasattr(Color, 'casefold'):
        assert 'ss' == Color('ß').casefold()

    assert 'Guido was born in country' == Color('{name} was born in {country}').format_map(_Default(name='Guido'))

    assert Color('var').isidentifier()
    assert not Color('var-').isidentifier()
    assert Color('var').isprintable()
    assert not Color('\0').isprintable()

    assert 'th3s 3s 1 t2st.' == value.translate(Color.maketrans('aeiou', '12345'))