示例#1
0
def test_new_argerror():
    """ markup.decoder.text.TextDecoder() checks arguments """
    with raises(TypeError):
        _decoder.TextDecoder()  # pylint: disable = no-value-for-parameter

    with raises(RuntimeError):
        _decoder.TextDecoder(_test.badstr)
示例#2
0
def test_decode_badstring():
    """
    markup.decoder.text.TextDecoder().decode() raises errors on bad input
    """
    inst = _decoder.TextDecoder('utf-8')
    with raises(TypeError):
        inst.decode(b'xxx', _test.badstr)
示例#3
0
def test_weakref():
    """ markup.decoder.text.TextDecoder() accepts and clears weakrefs """
    inst = _decoder.TextDecoder('foo')
    ref = _weakref.ref(inst)

    assert ref().encoding == 'foo'
    del inst
    assert ref() is None
示例#4
0
def test_setencoding():
    """ markup.decoder.text.TextDecoder() accepts encoding """
    inst = _decoder.TextDecoder('foo')
    inst.encoding = 'bar'

    assert inst.encoding == 'bar'

    with raises(RuntimeError):
        inst.encoding = _test.badstr
示例#5
0
def test_attribute():
    """ markup.decoder.text.TextDecoder().attribute() decodes to unicode """
    inst = _decoder.TextDecoder('utf-8')

    result = inst.attribute(b'Andr\xc3\xa9')
    assert result == u'Andr\xe9'

    with raises(ValueError):
        inst.attribute(b'Andr\xe9')
示例#6
0
def test_attribute_slash():
    """
    markup.decoder.text.TextDecoder().attribute() unslashes decoded value
    """
    inst = _decoder.TextDecoder('utf-8')
    result = inst.attribute(b'A\\n\\\\d\\r\xc3\xa9')
    assert result == u'An\\dr\xe9'

    result = inst.attribute(b'"A\\n\\\\d\\r\\\xc3\xa9')
    assert result == u'An\\dr\\'
示例#7
0
def test_attribute_strip():
    """ markup.decoder.text.TextDecoder().attribute() strips decoded value """
    inst = _decoder.TextDecoder('utf-8')

    result = inst.attribute(b'"Andr\xc3\xa9')
    assert result == u'Andr'

    result = inst.attribute(b"'Andr\xc3\xa9")
    assert result == u'Andr'

    result = inst.attribute(b"")
    assert result == u''

    result = inst.attribute(b"''")
    assert result == u''

    result = inst.attribute(b"'x'")
    assert result == u'x'
示例#8
0
def test_decode_strict_error():
    """ markup.decoder.text.TextDecoder().decode() raises on strict error """
    inst = _decoder.TextDecoder('utf-8')
    with raises(UnicodeDecodeError):
        inst.decode(b'Andr\xe9')
示例#9
0
def test_decode_arg_error():
    """ markup.decoder.text.TextDecoder().decode() checks arguments """
    inst = _decoder.TextDecoder('utf-8')
    with raises(TypeError):
        inst.decode()  # pylint: disable = no-value-for-parameter
示例#10
0
def test_decode():
    """ markup.decoder.text.TextDecoder().decode() decodes to unicode """
    inst = _decoder.TextDecoder('utf-8')
    result = inst.decode(b'Andr\xc3\xa9')
    assert result == u'Andr\xe9'
示例#11
0
def test_normalize():
    """ markup.decoder.text.TextDecoder().normalize() just passes through """
    inst = _decoder.TextDecoder('foo')
    mocked = object()
    result = inst.normalize(mocked)
    assert result is mocked
示例#12
0
def test_init():
    """ markup.decoder.text.TextDecoder() inits properly """
    inst = _decoder.TextDecoder('foo')
    assert isinstance(inst, _abstract.Decoder)
    assert inst.encoding == 'foo'