home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_charmapcodec.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.2 KB  |  44 lines

  1. """ Python character mapping codec test
  2.  
  3. This uses the test codec in testcodec.py and thus also tests the
  4. encodings package lookup scheme.
  5.  
  6. Written by Marc-Andre Lemburg (mal@lemburg.com).
  7.  
  8. (c) Copyright 2000 Guido van Rossum.
  9.  
  10. """#"
  11.  
  12. def check(a, b):
  13.     if a != b:
  14.         print '*** check failed: %s != %s' % (repr(a), repr(b))
  15.     else:
  16.         print '%s == %s: OK' % (a, b)
  17.  
  18. # test codec's full path name (see test/testcodec.py)
  19. codecname = 'test.testcodec'
  20.  
  21. check(unicode('abc', codecname), u'abc')
  22. check(unicode('xdef', codecname), u'abcdef')
  23. check(unicode('defx', codecname), u'defabc')
  24. check(unicode('dxf', codecname), u'dabcf')
  25. check(unicode('dxfx', codecname), u'dabcfabc')
  26.  
  27. check(u'abc'.encode(codecname), 'abc')
  28. check(u'xdef'.encode(codecname), 'abcdef')
  29. check(u'defx'.encode(codecname), 'defabc')
  30. check(u'dxf'.encode(codecname), 'dabcf')
  31. check(u'dxfx'.encode(codecname), 'dabcfabc')
  32.  
  33. check(unicode('ydef', codecname), u'def')
  34. check(unicode('defy', codecname), u'def')
  35. check(unicode('dyf', codecname), u'df')
  36. check(unicode('dyfy', codecname), u'df')
  37.  
  38. try:
  39.     unicode('abc\001', codecname)
  40. except UnicodeError:
  41.     print '\\001 maps to undefined: OK'
  42. else:
  43.     print '*** check failed: \\001 does not map to undefined'
  44.