对于这个 doctest:
r'''
>>> uuid_hex_to_binary('8ed2d35f-2911-4c10-ad68-587c96b4686e')
'\x8e\xd2\xd3\x5f\x29\x11\x4c\x10\xad\x68\x58\x7c\x96\xb4\x68\x6e'
'''
我得到这个结果:
Failed example:
uuid_hex_to_binary('8ed2d35f-2911-4c10-ad68-587c96b4686e')
Expected:
'\x8e\xd2\xd3\x5f\x29\x11\x4c\x10\xad\x68\x58\x7c\x96\xb4\x68\x6e'
Got:
'\x8e\xd2\xd3_)\x11L\x10\xadhX|\x96\xb4hn'
测试应该通过,因为字符串是等价的。但是,在“Got:”字符串中,它已将一些\xHH
转义转换为相应的 ascii 字符,但对于“Expected:”字符串并没有这样做。
如果我在文档字符串的请求下更改r'''
为'''
,我会改为:
Failed example:
uuid_hex_to_binary('8ed2d35f-2911-4c10-ad68-587c96b4686e')
Expected:
'???_)L?hX|??hn'
Got:
'\x8e\xd2\xd3_)\x11L\x10\xadhX|\x96\xb4hn'
如何让两个字符串在 doctest 中匹配?