2 new revisions:

Revision: d8ada4ce4047
Branch:   default
Author:   Tatu Kairi <[email protected]>
Date:     Fri Apr 25 13:57:09 2014 UTC
Log: Fixed regression from RF 2.8.2 where `Grep File` in Operating System l...
http://code.google.com/p/robotframework/source/detail?r=d8ada4ce4047

Revision: 6fda92d678a2
Branch:   default
Author:   Tatu Kairi <[email protected]>
Date:     Fri Apr 25 13:57:43 2014 UTC
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=6fda92d678a2

==============================================================================
Revision: d8ada4ce4047
Branch:   default
Author:   Tatu Kairi <[email protected]>
Date:     Fri Apr 25 13:57:09 2014 UTC
Log: Fixed regression from RF 2.8.2 where `Grep File` in Operating System library cannot open UTF-16 files properly

Update issue 1665
Status: Review
Cc: [email protected]

Implementation and tests done. Ready for review.
http://code.google.com/p/robotframework/source/detail?r=d8ada4ce4047

Modified:
 /atest/robot/standard_libraries/operating_system/get_file.txt
 /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
 /atest/testdata/standard_libraries/operating_system/get_file.txt
 /src/robot/libraries/OperatingSystem.py

=======================================
--- /atest/robot/standard_libraries/operating_system/get_file.txt Fri Apr 25 12:01:03 2014 UTC +++ /atest/robot/standard_libraries/operating_system/get_file.txt Fri Apr 25 13:57:09 2014 UTC
@@ -37,9 +37,6 @@

 Get Utf-16 File with Default Encoding
     Check testcase    ${TESTNAME}
-
-Get Utf-16 File with UTF-16 Encoding
-    Check testcase    ${TESTNAME}

 Get File with Default Encoding and error handlers
     Check testcase    ${TESTNAME}
@@ -67,12 +64,18 @@

 Grep File non Ascii
     ${tc}=    Check testcase    ${TESTNAME}
-    Log    ${tc.kws[1].kws[0].msgs}
Check Log Message ${tc.kws[0].kws[0].msgs[1]} 1 out of 5 lines matched Check Log Message ${tc.kws[1].kws[0].msgs[1]} 1 out of 5 lines matched

+Grep File with UTF-16 files
+    ${tc}=    Check testcase    ${TESTNAME}
+    Log    ${tc.kws[0].kws[0].msgs}
+ Check Log Message ${tc.kws[0].kws[0].msgs[1]} 3 out of 4 lines matched + Check Log Message ${tc.kws[1].kws[0].msgs[1]} 1 out of 2 lines matched + Check Log Message ${tc.kws[2].kws[0].msgs[1]} 4 out of 5 lines matched + Check Log Message ${tc.kws[3].kws[0].msgs[1]} 2 out of 3 lines matched
+
 Grep File With Encoding Error Handlers
     ${tc}=    Check testcase    ${TESTNAME}
-    Log    ${tc.kws[0].kws[1].kws[0].msgs}
- Check Log Message ${tc.kws[0].kws[0].kws[0].msgs[1]} 1 out of 5 lines matched - Check Log Message ${tc.kws[0].kws[1].kws[0].msgs[1]} 1 out of 5 lines matched + Check Log Message ${tc.kws[0].kws[0].msgs[1]} 1 out of 5 lines matched + Check Log Message ${tc.kws[1].kws[0].msgs[1]} 1 out of 5 lines matched
=======================================
--- /atest/testdata/standard_libraries/operating_system/files/utf-16BE.txt Thu Apr 24 15:55:18 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/files/utf-16BE.txt Fri Apr 25 13:57:09 2014 UTC
@@ -1,1 +1,2 @@
  H y v ä ä   ü ö t ä
+ f ö ö   b a r
=======================================
--- /atest/testdata/standard_libraries/operating_system/files/utf-16BEBOM.txt Thu Apr 24 15:55:18 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/files/utf-16BEBOM.txt Fri Apr 25 13:57:09 2014 UTC
@@ -1,1 +1,3 @@
 þÿ H y v ä ä   ü ö t ä
+ f ö ö b a r + f ö ö b a r
=======================================
--- /atest/testdata/standard_libraries/operating_system/files/utf-16LE.txt Thu Apr 24 15:55:18 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/files/utf-16LE.txt Fri Apr 25 13:57:09 2014 UTC
@@ -1,1 +1,4 @@
H y v ä ä ü ö t ä + f ö ö b a r + f ö ö b a r + f ö ö b a r ======================================= --- /atest/testdata/standard_libraries/operating_system/files/utf-16LEBOM.txt Thu Apr 24 15:55:18 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/files/utf-16LEBOM.txt Fri Apr 25 13:57:09 2014 UTC
@@ -1,1 +1,5 @@
ÿþH y v ä ä ü ö t ä + f ö ö b a r + f ö ö b a r + f ö ö b a r + f ö ö b a r ======================================= --- /atest/testdata/standard_libraries/operating_system/get_file.txt Fri Apr 25 12:01:03 2014 UTC +++ /atest/testdata/standard_libraries/operating_system/get_file.txt Fri Apr 25 13:57:09 2014 UTC
@@ -64,19 +64,12 @@
 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 File with Default Encoding and error handlers
     :FOR    ${file}    ${handler}     ${expected}    IN
- ... ${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\x00\n\x00f\x00\x00\x00 \x00b\x00a\x00r
     ...     ${latin-1file}       ignore     Hyv t
- ... ${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\x00\n\x00f\x00\ufffd\x00\ufffd\x00 \x00b\x00a\x00r
     ...     ${latin-1file}       replace    Hyv�� ��t�
\ Verify Get File with error handler ${file} ${handler} ${expected}

@@ -106,12 +99,18 @@
     fää     fää        ${TESTFILE}
     ö       föö bär    ${TESTFILE}
     A       A Fåå      ${TESTFILE}
+
+Grep File with UTF-16 files
+    [Template]    Verify Grep File With UTF-16 files
+    ${utf-16 LE file}             UTF-16-LE    föö bar\nföö bar\nföö bar
+    ${utf-16 BE file}             UTF-16-BE    föö bar
+ ${utf-16 LE with BOM file} UTF-16 föö bar\nföö bar\nföö bar\nföö bar
+    ${utf-16 BE with BOM file}    UTF-16    föö bar\nföö bar

 Grep File With Encoding Error Handlers
-    :FOR    ${error handler}    ${expected}    IN    ignore     f bar
- ... replace f\ufffd\ufffd bar - \ ${ret}= Grep File ${latin-1 long file} f*a encoding_errors=${error handler}
-    \     Should Be Equal    ${ret}    ${expected}
+    [Template]    Verify Grep File with error handler
+    ignore     f bar
+    replace    f\ufffd\ufffd bar


 *** Keywords ***
@@ -124,13 +123,18 @@
     [Arguments]  ${pattern}  ${expected}    ${test file}=${utf-8 long file}
     ${content} =  Grep File  ${test file}  ${pattern}
     Should Be Equal  ${content}  ${expected}
-
-Verify UTF-16 File
-    [Arguments]    ${utf-16 file}    ${encoding}
-    ${file}=    Get File    ${utf-16 file}    ${encoding}
-    Should Be Equal    ${file}    Hyvää üötä

 Verify Get File with error handler
     [Arguments]    ${file}    ${error handler}    ${expected}
     ${ret}=    Get File    ${file}    encoding_errors=${error handler}
     Should Be Equal    ${ret}    ${expected}
+
+Verify Grep File with error handler
+    [Arguments]    ${error handler}    ${expected}
+ ${ret}= Grep File ${latin-1 long file} f*a encoding_errors=${error handler}
+    Should Be Equal    ${ret}    ${expected}
+
+Verify Grep File With UTF-16 files
+    [Arguments]     ${file}     ${encoding}    ${expected}
+    ${ret}=    Grep File     ${file}    f*a    ${encoding}
+    Should Be Equal    ${ret}    ${expected}
=======================================
--- /src/robot/libraries/OperatingSystem.py     Fri Apr 25 12:01:03 2014 UTC
+++ /src/robot/libraries/OperatingSystem.py     Fri Apr 25 13:57:09 2014 UTC
@@ -13,14 +13,15 @@
 #  limitations under the License.

 from __future__ import with_statement
+import codecs
+import fnmatch
+import glob
 import os
+import shutil
+import subprocess
 import sys
 import tempfile
 import time
-import glob
-import fnmatch
-import shutil
-import subprocess

 try:
     from robot.version import get_version
@@ -375,10 +376,10 @@
         lines = []
         total_lines = 0
         self._link("Reading file '%s'", path)
-        with open(path, 'rU') as f:
-            for line in f:
+ with codecs.open(path, encoding=encoding, errors=encoding_errors) as f:
+            for line in f.readlines():
                 total_lines += 1
- line = unicode(line, encoding, encoding_errors).rstrip('\n')
+                line = line.strip('\r').rstrip('\n')
                 if fnmatch.fnmatchcase(line, pattern):
                     lines.append(line)
self._info('%d out of %d lines matched' % (len(lines), total_lines))

==============================================================================
Revision: 6fda92d678a2
Branch:   default
Author:   Tatu Kairi <[email protected]>
Date:     Fri Apr 25 13:57:43 2014 UTC
Log:      merge
http://code.google.com/p/robotframework/source/detail?r=6fda92d678a2


--

--- 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to