2001-01-10 06:21:11 -04:00
|
|
|
""" Python character mapping codec test
|
|
|
|
|
|
|
|
This uses the test codec in testcodec.py and thus also tests the
|
|
|
|
encodings package lookup scheme.
|
2001-01-06 11:09:57 -04:00
|
|
|
|
|
|
|
Written by Marc-Andre Lemburg (mal@lemburg.com).
|
|
|
|
|
|
|
|
(c) Copyright 2000 Guido van Rossum.
|
|
|
|
|
|
|
|
"""#"
|
|
|
|
|
|
|
|
def check(a, b):
|
|
|
|
if a != b:
|
|
|
|
print '*** check failed: %s != %s' % (repr(a), repr(b))
|
2001-01-10 06:21:11 -04:00
|
|
|
else:
|
2001-08-23 15:57:01 -03:00
|
|
|
print '%s == %s: OK' % (a, b)
|
2001-01-06 11:09:57 -04:00
|
|
|
|
2001-01-10 06:21:11 -04:00
|
|
|
# test codec's full path name (see test/testcodec.py)
|
2001-01-17 11:07:00 -04:00
|
|
|
codecname = 'test.testcodec'
|
2001-01-17 22:22:22 -04:00
|
|
|
|
2001-01-10 06:21:11 -04:00
|
|
|
check(unicode('abc', codecname), u'abc')
|
|
|
|
check(unicode('xdef', codecname), u'abcdef')
|
|
|
|
check(unicode('defx', codecname), u'defabc')
|
|
|
|
check(unicode('dxf', codecname), u'dabcf')
|
|
|
|
check(unicode('dxfx', codecname), u'dabcfabc')
|
|
|
|
|
|
|
|
check(u'abc'.encode(codecname), 'abc')
|
|
|
|
check(u'xdef'.encode(codecname), 'abcdef')
|
|
|
|
check(u'defx'.encode(codecname), 'defabc')
|
|
|
|
check(u'dxf'.encode(codecname), 'dabcf')
|
|
|
|
check(u'dxfx'.encode(codecname), 'dabcfabc')
|
|
|
|
|
|
|
|
check(unicode('ydef', codecname), u'def')
|
|
|
|
check(unicode('defy', codecname), u'def')
|
|
|
|
check(unicode('dyf', codecname), u'df')
|
|
|
|
check(unicode('dyfy', codecname), u'df')
|
|
|
|
|
|
|
|
try:
|
|
|
|
unicode('abc\001', codecname)
|
|
|
|
except UnicodeError:
|
|
|
|
print '\\001 maps to undefined: OK'
|
|
|
|
else:
|
|
|
|
print '*** check failed: \\001 does not map to undefined'
|