[Python-Dev] Known doctest bug with unicode?

Jeroen Ruigrok van der Werven asmodai at in-nomine.org
Fri Apr 18 16:27:05 CEST 2008

# vim: set fileencoding=utf-8 :

kanamap = {
    u'あ': 'a'

def transpose(word):
    """Convert a word in kana to its equivalent Hepburn romanisation.
    >>> transpose(u'あ')
    transposed = ''
    for character in word:
        transposed += kanamap[character]
    return transposed

if __name__ == '__main__':
    import doctest


[16:24] [ruigrok at akuma] (1) {20} % python trans.py
File "trans.py", line 11, in __main__.transpose
Failed example:
Exception raised:
    Traceback (most recent call last):
      File "doctest.py", line 1212, in __run
        compileflags, 1) in test.globs
      File "<doctest __main__.transpose[0]>", line 1, in <module>
      File "trans.py", line 16, in transpose
        transposed += kanamap[character]
    KeyError: u'\xe3'
1 items had failures:
   1 of   1 in __main__.transpose
***Test Failed*** 1 failures.

normal interpreter:

>>> fromm trans import transpose
>>> transpose(u'あ')

Jeroen Ruigrok van der Werven <asmodai(-at-)in-nomine.org> / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
They have learned nothing, and forgotten nothing...

More information about the Python-Dev mailing list