對於此文檔測試:Python的文檔測試字符串轉義問題
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'
我怎樣才能得到這兩個字符串在文檔測試匹配?