def test_codec_wrapped_exception(self):
        import _codecs

        def search_function(encoding):
            def f(input, errors="strict"):
                raise to_raise

            if encoding == 'test.failingenc':
                return (f, f, None, None)
            return None

        _codecs.register(search_function)
        to_raise = RuntimeError('should be wrapped')
        exc = raises(RuntimeError, b"hello".decode, "test.failingenc")
        assert str(
            exc.value) == ("decoding with 'test.failingenc' codec failed "
                           "(RuntimeError: should be wrapped)")
        exc = raises(RuntimeError, u"hello".encode, "test.failingenc")
        assert str(
            exc.value) == ("encoding with 'test.failingenc' codec failed "
                           "(RuntimeError: should be wrapped)")
        #
        to_raise.attr = "don't wrap"
        exc = raises(RuntimeError, u"hello".encode, "test.failingenc")
        assert exc.value == to_raise
        #
        to_raise = RuntimeError("Should", "Not", "Wrap")
        exc = raises(RuntimeError, u"hello".encode, "test.failingenc")
        assert exc.value == to_raise
Exemple #2
0
 def test_codec_wrong_result(self):
     import _codecs
     def search_function(encoding):
         def f(input, errors="strict"):
             return 42
         if encoding == 'test.mytestenc':
             return (f, f, None, None)
         return None
     _codecs.register(search_function)
     raises(TypeError, b"hello".decode, "test.mytestenc")
     raises(TypeError, u"hello".encode, "test.mytestenc")
Exemple #3
0
 def test_codec_wrong_result(self):
     import _codecs
     def search_function(encoding):
         def f(input, errors="strict"):
             return 42
         print encoding
         if encoding == 'test.mytestenc':
             return (f, f, None, None)
         return None
     _codecs.register(search_function)
     raises(TypeError, "hello".decode, "test.mytestenc")
     raises(TypeError, u"hello".encode, "test.mytestenc")
Exemple #4
0
 def test_one_arg_encoder(self):
     import _codecs
     def search_function(encoding):
         def encode_one(u):
             return (b'foo', len(u))
         def decode_one(u):
             return (u'foo', len(u))
         if encoding == 'onearg':
             return (encode_one, decode_one, None, None)
         return None
     _codecs.register(search_function)
     assert u"hello".encode("onearg") == b'foo'
     assert b"hello".decode("onearg") == u'foo'
     assert _codecs.encode(u"hello", "onearg") == b'foo'
     assert _codecs.decode(b"hello", "onearg") == u'foo'
Exemple #5
0
def test_register():
    '''
    TODO: test that functions passed in are actually used
    '''
    #sanity check - basically just ensure that functions can be registered
    def garbage_func0(): pass
    def garbage_func1(param1): pass
    codecs.register(garbage_func0)
    codecs.register(garbage_func1)
    
    #negative cases
    AssertError(TypeError, codecs.register)
    AssertError(TypeError, codecs.register, None)
    AssertError(TypeError, codecs.register, ())
    AssertError(TypeError, codecs.register, [])
    AssertError(TypeError, codecs.register, 1)
    AssertError(TypeError, codecs.register, "abc")
    AssertError(TypeError, codecs.register, 3.14)
Exemple #6
0
def test_register():
    '''
    TODO: test that functions passed in are actually used
    '''
    #sanity check - basically just ensure that functions can be registered
    def garbage_func0(): pass
    def garbage_func1(param1): pass
    codecs.register(garbage_func0)
    codecs.register(garbage_func1)
    
    #negative cases
    AssertError(TypeError, codecs.register)
    AssertError(TypeError, codecs.register, None)
    AssertError(TypeError, codecs.register, ())
    AssertError(TypeError, codecs.register, [])
    AssertError(TypeError, codecs.register, 1)
    AssertError(TypeError, codecs.register, "abc")
    AssertError(TypeError, codecs.register, 3.14)
Exemple #7
0
def test_codecs_lookup():
    l = []
    def my_func(encoding, cache = l):
        l.append(encoding)
    
    codecs.register(my_func)
    allchars = ''.join([chr(i) for i in xrange(1, 256)])
    try:
        codecs.lookup(allchars)
        AssertUnreachable()
    except LookupError:
        pass
        
    lowerchars = allchars.lower().replace(' ', '-')
    for i in xrange(1, 255):
        if l[0][i] != lowerchars[i]:
            Assert(False, 'bad chars at index %d: %r %r' % (i, l[0][i], lowerchars[i]))
            
    AssertError(TypeError, codecs.lookup, '\0')
    AssertError(TypeError, codecs.lookup, 'abc\0')
    AreEqual(len(l), 1)
Exemple #8
0
def test_codecs_lookup():
    l = []
    def my_func(encoding, cache = l):
        l.append(encoding)
    
    codecs.register(my_func)
    allchars = ''.join([chr(i) for i in xrange(1, 256)])
    try:
        codecs.lookup(allchars)
        AssertUnreachable()
    except LookupError:
        pass
        
    lowerchars = allchars.lower().replace(' ', '-')
    for i in xrange(1, 255):
        if l[0][i] != lowerchars[i]:
            Assert(False, 'bad chars at index %d: %r %r' % (i, l[0][i], lowerchars[i]))
            
    AssertError(TypeError, codecs.lookup, '\0')
    AssertError(TypeError, codecs.lookup, 'abc\0')
    AreEqual(len(l), 1)
Exemple #9
0
# https://github.com/praashie/flatmate
"""Generate documentation of the FL Python environment"""

import sys
import _codecs as codecs

sys.path.append("Z:/usr/lib/python3.6/")

from encodings import utf_8

codecs.register(lambda encoding: utf_8.getregentry())

import _io as io

_f = None


def p(text):
    print(text)
    if _f:
        print(text, file=_f)


def indent_str(s, indent='    '):
    return '\n'.join([indent + line for line in s.splitlines()])


def write_module(module, modulename, write_path):
    global _f
    with io.open(write_path + '/' + modulename + '.txt', 'w',
                 encoding="ascii") as f: