【RF库测试】Encode String To Bytes&Decode Bytes To String& should be string&should be unicode string &should not be string

场景1:判断类型

r
${d} set variable xbaxcbxbcxf5xcdxa8xb9xfd #核减通过
Run Keyword And Continue On Failure should be byte string ${d}
should be string ${d}
Should Be Unicode String ${d}
Run Keyword And Continue On Failure Should Not Be String ${d}
${e} set variable 核减通过
Run Keyword And Continue On Failure should be byte string ${e}
should be string ${e}
Should Be Unicode String ${e}
Run Keyword And Continue On Failure Should Not Be String ${e}

总结:两个变量均为string 和 unicode string类型,而非byte string类型;

场景2:Encode String To Bytes

e
${d} set variable xbaxcbxbcxf5xcdxa8xb9xfd
${dUTF8} Encode String To Bytes ${d} UTF-8
${dASCII} Encode String To Bytes ${d} ASCII errors=ignore
${e} set variable 核减通过
${eUTF8} Encode String To Bytes ${e} UTF-8
${eASCII} Run Keyword And Continue On Failure Encode String To Bytes ${e} ASCII
Run Keyword And Continue On Failure should be equal ${eUTF8} ${dUTF8}
Run Keyword And Continue On Failure should be equal ${eASCII} ${dASCII}

执行结果:

Starting test: ZXJF.清结算 一期.互联网核减.e
20170712 11:33:08.790 : INFO : ${d} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:33:08.790 : INFO : ${dUTF8} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:33:08.790 : INFO : ${dASCII} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:33:08.790 : INFO : ${e} = 核减通过
20170712 11:33:08.790 : INFO : ${eUTF8} = xe6xa0xb8xe5x87x8fxe9x80x9axe8xbfx87
20170712 11:33:08.806 : FAIL : UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
20170712 11:33:08.806 : INFO : ${eASCII} = None
20170712 11:33:08.806 : INFO :
Argument types are:
<type 'str'>
<type 'str'>
20170712 11:33:08.806 : FAIL : xe6xa0xb8xe5x87x8fxe9x80x9axe8xbfx87 != xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:33:08.806 : INFO :
Argument types are:
<type 'NoneType'>
<type 'str'>
20170712 11:33:08.806 : FAIL : None != xbaxcbxbcxf5xcdxa8xb9xfd
Ending test: ZXJF.清结算 一期.互联网核减.e

场景3:Decode Bytes To String

t
${d} set variable xbaxcbxbcxf5xcdxa8xb9xfd
${dUTF8} Decode Bytes To String ${d} UTF-8
${dASCII} Decode Bytes To String ${d} ASCII errors=ignore
${e} set variable 核减通过
${eUTF8} Run Keyword And Continue On Failure Decode Bytes To String ${e} UTF-8
${eASCII} Run Keyword And Continue On Failure Decode Bytes To String ${e} ASCII errors=ignore
Run Keyword And Continue On Failure should be equal ${eUTF8} ${dUTF8}
Run Keyword And Continue On Failure should be equal ${eASCII} ${dASCII}

执行结果: 

Starting test: ZXJF.清结算 一期.互联网核减.t
20170712 11:31:33.780 : INFO : ${d} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:31:33.780 : INFO : ${dUTF8} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:31:33.780 : INFO : ${dASCII} = xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:31:33.780 : INFO : ${e} = 核减通过
20170712 11:31:33.780 : FAIL : UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
20170712 11:31:33.796 : INFO : ${eUTF8} = None
20170712 11:31:33.796 : FAIL : UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
20170712 11:31:33.796 : INFO : ${eASCII} = None
20170712 11:31:33.796 : INFO :
Argument types are:
<type 'NoneType'>
<type 'unicode'>
20170712 11:31:33.796 : FAIL : None != xbaxcbxbcxf5xcdxa8xb9xfd
20170712 11:31:33.796 : INFO :
Argument types are:
<type 'NoneType'>
<type 'unicode'>
20170712 11:31:33.812 : FAIL : None != xbaxcbxbcxf5xcdxa8xb9xfd
Ending test: ZXJF.清结算 一期.互联网核减.t

原文地址:https://www.cnblogs.com/apple2016/p/7154514.html