2 new revisions:
Revision: d362949b5b97
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Fri Apr 25 12:01:03 2014 UTC
Log: Implemented encoding_errors for `Grep File` with tests and
documentati...
http://code.google.com/p/robotframework/source/detail?r=d362949b5b97
Revision: e451b22b94bd
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Fri Apr 25 12:02:55 2014 UTC
Log: merge
http://code.google.com/p/robotframework/source/detail?r=e451b22b94bd
==============================================================================
Revision: d362949b5b97
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Fri Apr 25 12:01:03 2014 UTC
Log: Implemented encoding_errors for `Grep File` with tests and
documentation
Update issue 1655
Status: Review
`Grep File` is now also done with implementation, tests and kw
documentation.
Issue is ready for review.
http://code.google.com/p/robotframework/source/detail?r=d362949b5b97
Added:
/atest/testdata/standard_libraries/operating_system/files/latin-1_multiple_rows.txt
/atest/testdata/standard_libraries/operating_system/files/utf-8_multiple_rows.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/latin-1_multiple_rows.txt
Fri Apr 25 12:01:03 2014 UTC
@@ -0,0 +1,5 @@
+fää
+bär
+föö bar
+
+A Fåå
=======================================
--- /dev/null
+++
/atest/testdata/standard_libraries/operating_system/files/utf-8_multiple_rows.txt
Fri Apr 25 12:01:03 2014 UTC
@@ -0,0 +1,5 @@
+foo
+bar
+foo bar
+
+A Foo
=======================================
--- /atest/robot/standard_libraries/operating_system/get_file.txt Thu Apr
24 15:55:18 2014 UTC
+++ /atest/robot/standard_libraries/operating_system/get_file.txt Fri Apr
25 12:01:03 2014 UTC
@@ -41,29 +41,38 @@
Get Utf-16 File with UTF-16 Encoding
Check testcase ${TESTNAME}
-Get Utf-16 File with Default Encoding and error handler 'ignore'
+Get File with Default Encoding and error handlers
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}
Check Log Message ${tc.kws[0].msgs[1]} ${RESULT}
Grep File
- ${tc} = Check testcase ${TESTNAME}
- Check Log Message ${tc.kws[1].kws[0].msgs[1]} 5 out of 5 lines
matched
- Check Log Message ${tc.kws[2].kws[0].msgs[1]} 2 out of 5 lines
matched
- Check Log Message ${tc.kws[3].kws[0].msgs[1]} 1 out of 5 lines
matched
- Check Log Message ${tc.kws[4].kws[0].msgs[1]} 0 out of 5 lines
matched
- Check Log Message ${tc.kws[5].kws[0].msgs[1]} 3 out of 5 lines
matched
- Check Log Message ${tc.kws[6].kws[0].msgs[1]} 3 out of 5 lines
matched
- Check Log Message ${tc.kws[7].kws[0].msgs[1]} 1 out of 5 lines
matched
- Check Log Message ${tc.kws[8].kws[0].msgs[1]} 4 out of 5 lines
matched
- Check Log Message ${tc.kws[9].kws[0].msgs[1]} 2 out of 5 lines
matched
- Check Log Message ${tc.kws[10].kws[0].msgs[1]} 1 out of 5 lines
matched
- Check Log Message ${tc.kws[12].kws[0].msgs[1]} 0 out of 0 lines
matched
+ ${tc}= Check testcase ${TESTNAME}
+ Check Log Message ${tc.kws[0].kws[0].msgs[1]} 5 out of 5 lines
matched
+ Check Log Message ${tc.kws[1].kws[0].msgs[1]} 2 out of 5 lines
matched
+ Check Log Message ${tc.kws[2].kws[0].msgs[1]} 1 out of 5 lines
matched
+ Check Log Message ${tc.kws[3].kws[0].msgs[1]} 0 out of 5 lines
matched
+ Check Log Message ${tc.kws[4].kws[0].msgs[1]} 3 out of 5 lines
matched
+ Check Log Message ${tc.kws[5].kws[0].msgs[1]} 3 out of 5 lines
matched
+ Check Log Message ${tc.kws[6].kws[0].msgs[1]} 1 out of 5 lines
matched
+ Check Log Message ${tc.kws[7].kws[0].msgs[1]} 4 out of 5 lines
matched
+ Check Log Message ${tc.kws[8].kws[0].msgs[1]} 2 out of 5 lines
matched
+ Check Log Message ${tc.kws[9].kws[0].msgs[1]} 1 out of 5 lines
matched
+
+Grep File with empty file
+ ${tc}= Check testcase ${TESTNAME}
+ Check Log Message ${tc.kws[1].kws[0].msgs[1]} 0 out of 0 lines
matched
Grep File non Ascii
- Check testcase ${TESTNAME}
+ ${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 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
=======================================
--- /atest/testdata/standard_libraries/operating_system/get_file.txt Thu
Apr 24 15:55:18 2014 UTC
+++ /atest/testdata/standard_libraries/operating_system/get_file.txt Fri
Apr 25 12:01:03 2014 UTC
@@ -5,11 +5,13 @@
Variables files/result.py
*** Variables ***
-${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-8file} ${CURDIR}${/}files${/}utf-8.txt
+${asciifile} ${CURDIR}${/}files${/}ascii.txt
+${latin-1file} ${CURDIR}${/}files${/}latin-1.txt
+${latin-1 long file}
${CURDIR}${/}files${/}latin-1_multiple_rows.txt
+${utf-8 long file} ${CURDIR}${/}files${/}utf-8_multiple_rows.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
@@ -70,43 +72,47 @@
${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
+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
+ ... ${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
+ ... ${latin-1file} replace Hyv�� ��t�
+ \ Verify Get File with error handler ${file} ${handler}
${expected}
Log Latin-1 With Latin-1 Encoding
${file} = Log File ${latin-1file} Latin-1
Grep File
- Create File ${TESTFILE} foo\nbar\nfoo bar\n\nA Foo
- Grep And Check File ${EMPTY} foo\nbar\nfoo bar\n\nA Foo
- Grep And Check File foo foo\nfoo bar
- Grep And Check File foo? foo bar
- Grep And Check File ?foo ${EMPTY}
- Grep And Check File ?oo foo\nfoo bar\nA Foo
- Grep And Check File [Ff]oo foo\nfoo bar\nA Foo
- Grep And Check File f*a foo bar
- Grep And Check File ? foo\nbar\nfoo bar\nA Foo
- Grep And Check File ???? foo bar\nA Foo
- Grep And Check File foo bar foo bar
+ [Template] Grep And Check File
+ ${EMPTY} foo\nbar\nfoo bar\n\nA Foo
+ foo foo\nfoo bar
+ foo? foo bar
+ ?foo ${EMPTY}
+ ?oo foo\nfoo bar\nA Foo
+ [Ff]oo foo\nfoo bar\nA Foo
+ f*a foo bar
+ ? foo\nbar\nfoo bar\nA Foo
+ ???? foo bar\nA Foo
+ foo bar foo bar
+
+Grep File with empty file
Create File ${TESTFILE} ${EMPTY}
- Grep And Check File * ${EMPTY}
+ Grep And Check File * ${EMPTY} ${TESTFILE}
Grep File non Ascii
- Create File ${TESTFILE} fää\nbär\nföö bär\n\nA Fåå
- Grep And Check File fää fää
- Grep And Check File ö föö bär
- Grep And Check File A A Fåå
+ [Setup] Create File ${TESTFILE} fää\nbär\nföö bär\n\nA Fåå
+ [Template] Grep And Check File
+ fää fää ${TESTFILE}
+ ö föö bär ${TESTFILE}
+ A A Fåå ${TESTFILE}
+
+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}
+
*** Keywords ***
Get And Check File
@@ -115,16 +121,16 @@
Should Be Equal ${content} ${expected}
Grep And Check File
- [Arguments] ${pattern} ${expected}
- ${content} = Grep File ${TESTFILE} ${pattern}
+ [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-16file} ${encoding}
- ${file}= Get File ${utf-16file} ${encoding}
+ [Arguments] ${utf-16 file} ${encoding}
+ ${file}= Get File ${utf-16 file} ${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}
+Verify Get File with error handler
+ [Arguments] ${file} ${error handler} ${expected}
+ ${ret}= Get File ${file} encoding_errors=${error handler}
+ Should Be Equal ${ret} ${expected}
=======================================
--- /src/robot/libraries/OperatingSystem.py Thu Apr 24 15:55:18 2014 UTC
+++ /src/robot/libraries/OperatingSystem.py Fri Apr 25 12:01:03 2014 UTC
@@ -345,16 +345,18 @@
with open(path, 'rb') as f:
return f.read()
- def grep_file(self, path, pattern, encoding='UTF-8'):
+ def grep_file(self, path, pattern, encoding='UTF-8',
encoding_errors='strict'):
"""Returns the lines of the specified file that match the
`pattern`.
This keyword reads a file from the file system using the defined
- `path` and `encoding` similarly as `Get File`. A difference is
- that only the lines that match the given `pattern` are returned.
- Lines are returned as a single string catenated back together with
- newlines and the number of matched lines is automatically logged.
+ `path`, `encoding` and `encoding_errors` similarly as `Get File`. A
+ difference is that only the lines that match the given `pattern`
are
+ returned. Lines are returned as a single string catenated back
together
+ with newlines and the number of matched lines is automatically
logged.
Possible trailing newline is never returned.
+ `encoding_errors` argument is new in Robot Framework 2.8.5.
+
A line matches if it contains the `pattern` anywhere in it and
it *does not need to match the pattern fully*. The pattern
matching syntax is explained in `introduction`, and in this
@@ -376,7 +378,7 @@
with open(path, 'rU') as f:
for line in f:
total_lines += 1
- line = unicode(line, encoding).rstrip('\n')
+ line = unicode(line, encoding,
encoding_errors).rstrip('\n')
if fnmatch.fnmatchcase(line, pattern):
lines.append(line)
self._info('%d out of %d lines matched' % (len(lines),
total_lines))
==============================================================================
Revision: e451b22b94bd
Branch: default
Author: Tatu Kairi <tatu.ka...@eficode.com>
Date: Fri Apr 25 12:02:55 2014 UTC
Log: merge
http://code.google.com/p/robotframework/source/detail?r=e451b22b94bd
--
---
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.