检查Python 2和Python 3的doctest

时间:2014-12-17 07:44:40

标签: python python-2.7 python-3.x unicode doctest

Python 2和Python 3以不同的顺序和不同的编码提供相同的dict。

来自代码:https://github.com/alvations/nltk/blob/develop/nltk/translate/util.py

运行代码,更改doctest的输出会打破另一个:

alvas@ubi:~/git/nltk/nltk/translate$ python3 util.py
**********************************************************************
File "util.py", line 34, in __main__.read_phrase_table
Failed example:
    print(x)
Expected:
    {'es gibt': {'there is': 1.0}, 'gibt': {'gives': 1.0}, 'klein': {'little': 0.8, 'small': 0.8}, 'ist': {'is': 1.0, "'s": 1.0}, 'alt': {'old': 0.8}, 'das ist': {'this is': 0.8, 'it is': 0.2}, 'ein': {'a': 1.0, 'an': 1.0}, 'altes': {'old': 0.2}, 'das': {'this': 0.1, 'it': 0.1, 'the': 0.4}, 'die': {'the': 0.3}, 'der': {'the': 0.3}, 'haus': {'house': 1.0}, 'kleines': {'little': 0.2, 'small': 0.2}, 'es ist': {'this is': 0.2, 'it is': 0.8}}
Got:
    {'altes': {'old': 0.2}, 'kleines': {'little': 0.2, 'small': 0.2}, 'das ist': {'this is': 0.8, 'it is': 0.2}, 'alt': {'old': 0.8}, 'ein': {'an': 1.0, 'a': 1.0}, 'der': {'the': 0.3}, 'haus': {'house': 1.0}, 'es ist': {'this is': 0.2, 'it is': 0.8}, 'es gibt': {'there is': 1.0}, 'klein': {'little': 0.8, 'small': 0.8}, 'die': {'the': 0.3}, 'ist': {'is': 1.0, "'s": 1.0}, 'gibt': {'gives': 1.0}, 'das': {'it': 0.1, 'the': 0.4, 'this': 0.1}}
**********************************************************************
1 items had failures:
   1 of   4 in __main__.read_phrase_table
***Test Failed*** 1 failures.
alvas@ubi:~/git/nltk/nltk/translate$ python util.py
**********************************************************************
File "util.py", line 34, in __main__.read_phrase_table
Failed example:
    print(x)
Expected:
    {'es gibt': {'there is': 1.0}, 'gibt': {'gives': 1.0}, 'klein': {'little': 0.8, 'small': 0.8}, 'ist': {'is': 1.0, "'s": 1.0}, 'alt': {'old': 0.8}, 'das ist': {'this is': 0.8, 'it is': 0.2}, 'ein': {'a': 1.0, 'an': 1.0}, 'altes': {'old': 0.2}, 'das': {'this': 0.1, 'it': 0.1, 'the': 0.4}, 'die': {'the': 0.3}, 'der': {'the': 0.3}, 'haus': {'house': 1.0}, 'kleines': {'little': 0.2, 'small': 0.2}, 'es ist': {'this is': 0.2, 'it is': 0.8}}
Got:
    {u'es gibt': {u'there is': 1.0}, u'klein': {u'small': 0.8, u'little': 0.8}, u'die': {u'the': 0.3}, u'der': {u'the': 0.3}, u'haus': {u'house': 1.0}, u'ist': {u'is': 1.0, u"'s": 1.0}, u'kleines': {u'small': 0.2, u'little': 0.2}, u'gibt': {u'gives': 1.0}, u'es ist': {u'this is': 0.2, u'it is': 0.8}, u'das': {u'this': 0.1, u'the': 0.4, u'it': 0.1}, u'alt': {u'old': 0.8}, u'ein': {u'a': 1.0, u'an': 1.0}, u'altes': {u'old': 0.2}, u'das ist': {u'this is': 0.8, u'it is': 0.2}}
**********************************************************************
File "util.py", line 36, in __main__.read_phrase_table
Failed example:
    print(x['es gibt'])
Expected:
    {'there is': 1.0}
Got:
    {u'there is': 1.0}
**********************************************************************
1 items had failures:
   2 of   4 in __main__.read_phrase_table
***Test Failed*** 2 failures.

运行doctest以停止测试失败时如何解决这种差异?

0 个答案:

没有答案