gpt4 book ai didi

python - Doctest NORMALIZE_WHITESPACE 不起作用

转载 作者:太空狗 更新时间:2023-10-29 22:16:14 24 4
gpt4 key购买 nike

Failed example:
p.parse_name('Adams, Michael')
# doctest: +NORMALIZE_WHITESPACE
Expected:
{'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}
Got:
{'first_name': 'Michael', 'last_name': 'Adams', 'initials': 'MA'}

文档字符串是 -

>>> p.parse_name('Adams, Michael') 
... # doctest: +NORMALIZE_WHITESPACE
{'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}

最佳答案

来自 the docs :

When specified, all sequences of whitespace (blanks and newlines) are treated as equal. Any sequence of whitespace within the expected output will match any sequence of whitespace within the actual output

',' 不包含空格序列,因此不被视为等于 ', '


您可能想阅读 warnings section文档的:

Python doesn’t guarantee that the key-value pairs will be printed in any particular order, so a test like

>>> foo()
{"Hermione": "hippogryph", "Harry": "broomstick"}

is vulnerable! One workaround is to do

>>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
True

关于python - Doctest NORMALIZE_WHITESPACE 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17640416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com