2 new revisions:
Revision: 4f0ce4db43c6
Branch: default
Author: Pekka Klärck
Date: Tue Dec 18 05:07:49 2012
Log: tidy: a little bit cleaner error message
http://code.google.com/p/robotframework/source/detail?r=4f0ce4db43c6
Revision: a510fb8ac0d6
Branch: default
Author: Pekka Klärck
Date: Tue Dec 18 05:38:43 2012
Log: Tidy: Support custom line separators....
http://code.google.com/p/robotframework/source/detail?r=a510fb8ac0d6
==============================================================================
Revision: 4f0ce4db43c6
Branch: default
Author: Pekka Klärck
Date: Tue Dec 18 05:07:49 2012
Log: tidy: a little bit cleaner error message
http://code.google.com/p/robotframework/source/detail?r=4f0ce4db43c6
Modified:
/src/robot/tidy.py
/utest/tidy/test_argument_validation.py
=======================================
--- /src/robot/tidy.py Tue Nov 20 01:00:04 2012
+++ /src/robot/tidy.py Tue Dec 18 05:07:49 2012
@@ -200,8 +200,8 @@
return None
format = os.path.splitext(args[1])[1][1:]
format = format.upper()
- if format not in ['TXT', 'TSV', 'HTML']:
- raise DataError("Invalid format: '%s'." % format)
+ if format not in ('TXT', 'TSV', 'HTML'):
+ raise DataError("Invalid format '%s'." % format)
return format
def _validate_spacecount(self, spacecount):
=======================================
--- /utest/tidy/test_argument_validation.py Mon Oct 8 01:42:05 2012
+++ /utest/tidy/test_argument_validation.py Tue Dec 18 05:07:49 2012
@@ -8,11 +8,11 @@
class TestArgumentValidation(unittest.TestCase):
def test_invalid_explicit_format(self):
- self._validate(format='invalid', error="Invalid
format: 'INVALID'.")
+ self._validate(format='invalid', error="Invalid format 'INVALID'.")
def test_invalid_implicit_format(self):
- self._validate(args=['x.txt', 'y.inv'], error="Invalid
format: 'INV'.")
- self._validate(args=['x.txt', 'inv'], error="Invalid format: ''.")
+ self._validate(args=['x.txt', 'y.inv'], error="Invalid
format 'INV'.")
+ self._validate(args=['x.txt', 'inv'], error="Invalid format ''.")
def test_invalid_space_count(self):
error = '--spacecount must be an integer greater than 1.'
==============================================================================
Revision: a510fb8ac0d6
Branch: default
Author: Pekka Klärck
Date: Tue Dec 18 05:38:43 2012
Log: Tidy: Support custom line separators.
Update issue 1309
Status: Done
Implemented, tested, and documented.
http://code.google.com/p/robotframework/source/detail?r=a510fb8ac0d6
Added:
/atest/robot/tidy/line_separator.txt
Modified:
/atest/robot/tidy/TidyLib.py
/doc/userguide/src/SupportingTools/Tidy.rst
/src/robot/tidy.py
/utest/tidy/test_argument_validation.py
=======================================
--- /dev/null
+++ /atest/robot/tidy/line_separator.txt Tue Dec 18 05:38:43 2012
@@ -0,0 +1,34 @@
+*** Settings ***
+Force Tags pybot jybot regression
+Resource tidy_resource.txt
+Test Setup Create Directory ${TEMP}
+Test Teardown Remove Directory ${TEMP} recursive=True
+Test Template Output should be correct and have correct line separators
+
+
+*** Test Cases ***
+Default
+ ${EMPTY} golden.txt ${\n}
+ -f tsv golden.tsv ${\n}
+ --format html golden.html ${\n}
+
+Native
+ --lineseparator native golden.txt ${\n}
+ --LineSep Native -f tsv golden.tsv ${\n}
+ -l NATIVE --format html golden.html ${\n}
+
+Windows
+ --lineseparator windows golden.txt \r\n
+ --LineSep Windows -f tsv golden.tsv \r\n
+ -l WINDOWS --format html golden.html \r\n
+
+Unix
+ --lineseparator unix golden.txt \n
+ --LineSep Unix -f tsv golden.tsv \n
+ -l UNIX --format html golden.html \n
+
+*** Keywords ***
+Output should be correct and have correct line separators
+ [Arguments] ${options} ${expected file} ${expected separator}
+ Run tidy with golden file and check result ${options} ${expected
file}
+ Output should have correct line separators ${expected separator}
=======================================
--- /atest/robot/tidy/TidyLib.py Mon Oct 8 01:13:20 2012
+++ /atest/robot/tidy/TidyLib.py Tue Dec 18 05:38:43 2012
@@ -79,5 +79,15 @@
return abspath(join(DATA_DIR, path.replace('/', os.sep)))
def _read(self, path):
- with open(self._path(path)) as f:
+ with open(self._path(path), 'rb') as f:
return f.read().decode('UTF-8')
+
+ def output_should_have_correct_line_separators(self, expected,
path=TEMP_FILE):
+ content = self._read(path)
+ expected = str(expected)
+ if expected not in content:
+ raise AssertionError('Output did not contain %r' % expected)
+ if expected == '\n' and '\r' in content:
+ raise AssertionError('Output contains \\r')
+ if '\r\r' in content:
+ raise AssertionError('Output contains \\r\\r')
=======================================
--- /doc/userguide/src/SupportingTools/Tidy.rst Mon Oct 15 03:52:11 2012
+++ /doc/userguide/src/SupportingTools/Tidy.rst Tue Dec 18 05:38:43 2012
@@ -50,6 +50,14 @@
-s, --spacecount <number>
The number of spaces between cells in the txt format.
New in Robot Framework 2.7.3.
+ -l, --lineseparator <native|windows|unix>
+ Line separator to use in outputs. The default
is 'native'.
+
+ - *native*: use operating system's native line separators
+ - *windows*: use Windows line separators (CRLF)
+ - *unix*: use Unix line separators (LF)
+
+ New in Robot Framework 2.7.6.
-h, --help Show this help.
Alternative execution
=======================================
--- /src/robot/tidy.py Tue Dec 18 05:07:49 2012
+++ /src/robot/tidy.py Tue Dec 18 05:38:43 2012
@@ -47,6 +47,12 @@
-s --spacecount number
The number of spaces between cells in the txt format.
New in Robot Framework 2.7.3.
+ -l --lineseparator native|windows|unix
+ Line separator to use in outputs. The default is 'native'.
+ native: use operating system's native line separators
+ windows: use Windows line separators (CRLF)
+ unix: use Unix line separators (LF)
+ New in Robot Framework 2.7.6.
-h -? --help Show this help.
Cleaning up the test data
@@ -108,7 +114,7 @@
def file(self, path, output=None):
data = self._parse_data(path)
- outfile = open(output, 'w') if output else StringIO()
+ outfile = open(output, 'wb') if output else StringIO()
try:
self._save_file(data, outfile)
if not output:
@@ -165,9 +171,10 @@
Application.__init__(self, USAGE, arg_limits=(1,))
def main(self, arguments, recursive=False, inplace=False, format='txt',
- usepipes=False, spacecount=4):
+ usepipes=False, spacecount=4, lineseparator=os.linesep):
tidy = Tidy(format=format, pipe_separated=usepipes,
- txt_separating_spaces=spacecount)
+ txt_separating_spaces=spacecount,
+ line_separator=lineseparator)
if recursive:
tidy.directory(arguments[0])
elif inplace:
@@ -180,6 +187,7 @@
def validate(self, opts, args):
self._validate_mode_and_arguments(args, **opts)
opts['format'] = self._validate_format(args, **opts)
+ opts['lineseparator'] = self._validate_line_sep(**opts)
if not opts['spacecount']:
opts.pop('spacecount')
else:
@@ -204,6 +212,15 @@
raise DataError("Invalid format '%s'." % format)
return format
+ def _validate_line_sep(self, lineseparator, **others):
+ if not lineseparator:
+ return os.linesep
+ values = {'native': os.linesep, 'windows': '\r\n', 'unix': '\n'}
+ try:
+ return values[lineseparator.lower()]
+ except KeyError:
+ raise DataError("Invalid line separator '%s'." % lineseparator)
+
def _validate_spacecount(self, spacecount):
try:
spacecount = int(spacecount)
=======================================
--- /utest/tidy/test_argument_validation.py Tue Dec 18 05:07:49 2012
+++ /utest/tidy/test_argument_validation.py Tue Dec 18 05:38:43 2012
@@ -1,8 +1,9 @@
import unittest
+import os
from robot.errors import DataError
from robot.tidy import TidyCommandLine
-from robot.utils.asserts import assert_raises_with_msg
+from robot.utils.asserts import assert_raises_with_msg, assert_equals
class TestArgumentValidation(unittest.TestCase):
@@ -49,15 +50,26 @@
self._validate(recursive=True,
error='--recursive requires exactly one directory
as argument.')
+ def test_line_separator(self):
+ for input, expected in [(None, os.linesep), ('Native', os.linesep),
+ ('windows', '\r\n'), ('UNIX', '\n')]:
+ opts, _ = self._validate(lineseparator=input)
+ assert_equals(opts['lineseparator'], expected)
+
+ def test_invalid_line_separator(self):
+ self._validate(lineseparator='invalid',
+ error="Invalid line separator 'invalid'.")
+
def _validate(self, inplace=False, recursive=False, format=None,
- spacecount=None, args=['a_file.txt'], error=None):
- opts = {'inplace': inplace, 'recursive': recursive,
- 'format': format, 'spacecount': spacecount}
+ spacecount=None, lineseparator=None, args=['a_file.txt'],
+ error=None):
+ opts = {'inplace': inplace, 'recursive': recursive, 'format':
format,
+ 'spacecount': spacecount, 'lineseparator': lineseparator}
validate = lambda: TidyCommandLine().validate(opts, args)
if error:
assert_raises_with_msg(DataError, error, validate)
else:
- validate()
+ return validate()
if __name__ == '__main__':