示例#1
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"))
示例#2
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'))