2 new revisions:
Revision: 4c558ed47c2e
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Thu Apr 24 15:55:18 2014 UTC
Log: `Get File` in Operating Systems library does not blow up when
dealing ...
http://code.google.com/p/robotframework/source/detail?r=4c558ed47c2e
Revision: c66d2cfd3eb1
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Thu Apr 24 15:55:39 2014 UTC
Log: merge
http://code.google.com/p/robotframework/source/detail?r=c66d2cfd3eb1
==============================================================================
Revision: 4c558ed47c2e
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Thu Apr 24 15:55:18 2014 UTC
Log: `Get File` in Operating Systems library does not blow up when
dealing with UTF-16 encoding
Update issue 1655
Status: Review
Cc: pekka.kla...@gmail.com
This issue is ready for review. Implementation is done with tests. KW
documentation is updated. There seems to be no need to update User Guide.
http://code.google.com/p/robotframework/source/detail?r=4c558ed47c2e
Added:
/atest/testdata/standard_libraries/operating_system/files/utf-16BE.txt
/atest/testdata/standard_libraries/operating_system/files/utf-16BEBOM.txt
/atest/testdata/standard_libraries/operating_system/files/utf-16LE.txt
/atest/testdata/standard_libraries/operating_system/files/utf-16LEBOM.txt
Modified:
/atest/robot/standard_libraries/operating_system/get_file.txt
/atest/testdata/standard_libraries/operating_system/get_file.txt
/src/robot/libraries/OperatingSystem.py
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/operating_system/files/utf-16BE.txt
Thu Apr 24 15:55:18 2014 UTC
@@ -0,0 +1,1 @@
+ H y v ä ä ü ö t ä
=======================================
--- /dev/null
+++
/atest/testdata/standard_libraries/operating_system/files/utf-16BEBOM.txt
Thu Apr 24 15:55:18 2014 UTC
@@ -0,0 +1,1 @@
+þÿ H y v ä ä ü ö t ä
=======================================
--- /dev/null
+++ /atest/testdata/standard_libraries/operating_system/files/utf-16LE.txt
Thu Apr 24 15:55:18 2014 UTC
@@ -0,0 +1,1 @@
+H y v ä ä ü ö t ä
=======================================
--- /dev/null
+++
/atest/testdata/standard_libraries/operating_system/files/utf-16LEBOM.txt
Thu Apr 24 15:55:18 2014 UTC
@@ -0,0 +1,1 @@
+ÿþH y v ä ä ü ö t ä
=======================================
--- /atest/robot/standard_libraries/operating_system/get_file.txt Mon Nov
11 08:18:26 2013 UTC
+++ /atest/robot/standard_libraries/operating_system/get_file.txt Thu Apr
24 15:55:18 2014 UTC
@@ -34,6 +34,18 @@
Get Latin-1 With Latin-1 Encoding
Check testcase ${TESTNAME}
+
+Get Utf-16 File with Default Encoding
+ Check testcase ${TESTNAME}
+
+Get Utf-16 File with UTF-16 Encoding
+ Check testcase ${TESTNAME}
+
+Get Utf-16 File with Default Encoding and error handler 'ignore'
+ Check testcase ${TESTNAME}
+
+Get Utf-16 File with Default Encoding and error handler 'replace'
+ Check testcase ${TESTNAME}
Log Latin-1 With Latin-1 Encoding
${tc} = Check testcase ${TESTNAME}
=======================================
--- /atest/testdata/standard_libraries/operating_system/get_file.txt Mon
Nov 11 08:18:26 2013 UTC
+++ /atest/testdata/standard_libraries/operating_system/get_file.txt Thu
Apr 24 15:55:18 2014 UTC
@@ -8,6 +8,10 @@
${utf-8file} ${CURDIR}${/}files${/}utf-8.txt
${asciifile} ${CURDIR}${/}files${/}ascii.txt
${latin-1file} ${CURDIR}${/}files${/}latin-1.txt
+${utf-16 LE file} ${CURDIR}${/}files${/}utf-16LE.txt #
Little Endian
+${utf-16 BE file} ${CURDIR}${/}files${/}utf-16BE.txt #
Big Endian
+${utf-16 LE with BOM file} ${CURDIR}${/}files${/}utf-16LEBOM.txt #
Little Endian with Byte Order Marker
+${utf-16 BE with BOM file} ${CURDIR}${/}files${/}utf-16BEBOM.txt #
Big Endian with BOM
*** Test Cases ***
Get File
@@ -54,6 +58,31 @@
Get Latin-1 With Latin-1 Encoding
${file} = Get File ${latin-1file} Latin-1
Should Be Equal ${file} ${result}
+
+Get Utf-16 File with Default Encoding
+ [Documentation] FAIL REGEXP: (UnicodeDecodeError|UnicodeError): .*
+ ${file}= Get File ${utf-16LEfile}
+
+Get Utf-16 File with UTF-16 Encoding
+ [Template] Verify UTF-16 File
+ ${utf-16 LE file} UTF-16-LE
+ ${utf-16 BE file} UTF-16-BE
+ ${utf-16 LE with BOM file} UTF-16
+ ${utf-16 BE with BOM file} UTF-16
+
+Get Utf-16 File with Default Encoding and error handler 'ignore'
+ [Template] Verify UTF-16 File with error handler
+ ${utf-16 LE file} ignore H\x00y\x00v\x00\x00\x00
\x00\x00\x00t\x00\x00
+ ${utf-16 BE file} ignore \x00H\x00y\x00v\x00\x00\x00
\x00\x00\x00t\x00
+ ${utf-16 LE with BOM file} ignore H\x00y\x00v\x00\x00\x00
\x00\x00\x00t\x00\x00
+ ${utf-16 BE with BOM file} ignore \x00H\x00y\x00v\x00\x00\x00
\x00\x00\x00t\x00
+
+Get Utf-16 File with Default Encoding and error handler 'replace'
+ [Template] Verify UTF-16 File with error handler
+ ${utf-16 LE file} replace
H\x00y\x00v\x00\ufffd\x00\ufffd\x00 \x00\ufffd\x00\ufffd\x00t\x00\ufffd\x00
+ ${utf-16 BE file} replace
\x00H\x00y\x00v\x00\ufffd\x00\ufffd\x00 \x00\ufffd\x00\ufffd\x00t\x00\ufffd
+ ${utf-16 LE with BOM file} replace
\ufffd\ufffdH\x00y\x00v\x00\ufffd\x00\ufffd\x00
\x00\ufffd\x00\ufffd\x00t\x00\ufffd\x00
+ ${utf-16 BE with BOM file} replace
\ufffd\ufffd\x00H\x00y\x00v\x00\ufffd\x00\ufffd\x00
\x00\ufffd\x00\ufffd\x00t\x00\ufffd
Log Latin-1 With Latin-1 Encoding
${file} = Log File ${latin-1file} Latin-1
@@ -90,3 +119,12 @@
${content} = Grep File ${TESTFILE} ${pattern}
Should Be Equal ${content} ${expected}
+Verify UTF-16 File
+ [Arguments] ${utf-16file} ${encoding}
+ ${file}= Get File ${utf-16file} ${encoding}
+ Should Be Equal ${file} Hyvää üötä
+
+Verify UTF-16 File with error handler
+ [Arguments] ${utf-16 file} ${error handler} ${expected}
+ ${file}= Get File ${utf-16 file} encoding_errors=${error
handler}
+ Should Be Equal ${file} ${expected}
=======================================
--- /src/robot/libraries/OperatingSystem.py Tue Apr 22 08:18:41 2014 UTC
+++ /src/robot/libraries/OperatingSystem.py Thu Apr 24 15:55:18 2014 UTC
@@ -307,7 +307,7 @@
"""
PROCESSES.close_all()
- def get_file(self, path, encoding='UTF-8'):
+ def get_file(self, path, encoding='UTF-8', encoding_errors='strict'):
"""Returns the contents of a specified file.
This keyword reads the specified file and returns the contents.
@@ -317,9 +317,20 @@
`encoding` defines the encoding of the file. By default the value
is
'UTF-8', which means that UTF-8 and ASCII-encoded files are read
correctly.
+
+ `encoding_errors` argument controls what to do if decoding some
bytes
+ fails. All values accepted by `decode` method in Python are valid,
but
+ in practice the following values are most useful:
+
+ - `strict`: fail if characters cannot be decoded (default)
+ - `ignore`: ignore characters that cannot be decoded
+ - `replace`: replace characters that cannot be decoded with
+ a replacement character
+
+ `encoding_errors` argument is new in Robot Framework 2.8.5.
"""
content = self.get_binary_file(path)
- return unicode(content, encoding).replace('\r\n', '\n')
+ return unicode(content, encoding,
encoding_errors).replace('\r\n', '\n')
def get_binary_file(self, path):
"""Returns the contents of a specified file.
==============================================================================
Revision: c66d2cfd3eb1
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Thu Apr 24 15:55:39 2014 UTC
Log: merge
http://code.google.com/p/robotframework/source/detail?r=c66d2cfd3eb1
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.