3 new revisions:

Revision: 13894b5798ff
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 02:35:50 2012
Log:      tidy: documentation cleanup
http://code.google.com/p/robotframework/source/detail?r=13894b5798ff

Revision: b1548f21605f
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 03:38:38 2012
Log:      tidy: code cleanup
http://code.google.com/p/robotframework/source/detail?r=b1548f21605f

Revision: 56e33dc909d6
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 04:06:17 2012
Log:      tidy: ug section
http://code.google.com/p/robotframework/source/detail?r=56e33dc909d6

==============================================================================
Revision: 13894b5798ff
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 02:35:50 2012
Log:      tidy: documentation cleanup
http://code.google.com/p/robotframework/source/detail?r=13894b5798ff

Modified:
 /src/robot/tidy.py

=======================================
--- /src/robot/tidy.py  Wed Jan 18 20:50:06 2012
+++ /src/robot/tidy.py  Tue Jan 24 02:35:50 2012
@@ -14,53 +14,58 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-"""robot.tidy: Clean up and change format of Robot Framework test data files.
+"""robot.tidy -- Robot Framework test data clean-up tool.

 Usage: python -m robot.tidy [options] inputfile
+   or: python -m robot.tidy [options] inputfile > outputfile
or: python -m robot.tidy --inplace [options] inputfile [more input files]
    or: python -m robot.tidy --recursive [options] directory

+This tool can be used to clean up and change format of Robot Framework test
+data files. By default, the output is written to the standard output stream,
+but it can be redirected to a file. Alternatively, files can be modified
+in-place using --inplace or --recursive options.
+
+All output files are written using UTF-8 encoding. Outputs written to the
+console use the current console encoding.
+
 Options:
-i --inplace Tidy given file(s) so that original file(s) are overwritten
-                 (or removed, if the format is changed) When this option is
+ (or removed, if the format is changed). When this option is used, it is possible to give multiple input files. Examples:
-                 robotidy.py --inplace tests.html
-                 robotidy.py --inplace --format txt *.html
+                 python -m robot.tidy --inplace tests.html
+                 python -m robot.tidy --inplace --format txt *.html
-r --recursive Process given directory recursively. Files in the directory
-                 are processed in place similarly as when '--inplace'
-                 option is used.
+ are processed in place similarly as when --inplace option is
+                 used.
  -f --format txt|html|tsv
-                 Output file format. If omitted, format of the input
+                 Output file format. If omitted, the format of the input
                  file is used.
- -p --use-pipes  Use pipe (`|`) as a cell separator in txt format.
+ -p --use-pipes  Use pipe (`|`) as a cell separator in the txt format.
  -h --help       Show this help.

-
-This tool has two main usages:
-
-1) Clean up the test data.
-
-Old test cases created with HTML editors or hand-written text files can
-be normalized using tidy. Tidy always writes consistent headers, consistent
-order for settings, and consistent amount of whitespace between cells and
-tables.
+Cleaning up the test data
+=========================
+
+Test case files created with HTML editors or written by hand can be normalized
+using tidy. Tidy always writes consistent headers, consistent order for
+settings, and consistent amount of whitespace between cells and tables.

 Examples:
-  robotidy.py messed_up_tests.html > cleaned_tests.html
-  robotidy.py --inplace tests.txt
-
-2) Change format between HTML, TSV and TXT.
-
-Robot Framework supports test data in HTML, TSV and TXT formats and this tools -makes changing between formats trivial. Input format is always determined from
-the extension of the input file. Output format can be set with '--format'
-option.
+  python -m robot.tidy messed_up_tests.html > cleaned_tests.html
+  python -m robot.tidy --inplace tests.txt
+
+Changing test data format
+=========================
+
+Robot Framework supports test data in HTML, TSV and TXT formats and this tool +makes changing between the formats trivial. Input format is always determined
+based on the extension of the input file. Output format can be set using
+--format option.

 Examples:
-  robotidy.py --format tsv tests_in_html.html > tests_in_tsv.tsv
-  robotidy.py --format txt --recursive mytests
-
-All output is written using UTF-8 encoding.
+  python -m robot.tidy --format tsv tests_in_html.html > tests_in_tsv.tsv
+  python -m robot.tidy --format txt --recursive mytests
 """
 import os
 import sys

==============================================================================
Revision: b1548f21605f
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 03:38:38 2012
Log:      tidy: code cleanup
http://code.google.com/p/robotframework/source/detail?r=b1548f21605f

Modified:
 /src/robot/tidy.py

=======================================
--- /src/robot/tidy.py  Tue Jan 24 02:35:50 2012
+++ /src/robot/tidy.py  Tue Jan 24 03:38:38 2012
@@ -61,18 +61,22 @@
Robot Framework supports test data in HTML, TSV and TXT formats and this tool makes changing between the formats trivial. Input format is always determined
 based on the extension of the input file. Output format can be set using
---format option.
+the --format option.

 Examples:
   python -m robot.tidy --format tsv tests_in_html.html > tests_in_tsv.tsv
   python -m robot.tidy --format txt --recursive mytests
 """
+
 import os
 import sys
 from StringIO import StringIO

+if 'robot' not in sys.modules:
+    import pythonpathsetter   # running tidy.py as script
+
 from robot.utils import ArgumentParser
-from robot.errors import DataError
+from robot.errors import DataError, Information
 from robot.parsing import ResourceFile, TestDataDirectory, TestCaseFile
 from robot.parsing.populators import FromFilePopulator

@@ -83,52 +87,55 @@
         self._options = options

     def file(self, path):
-        data = self._create_datafile(path)
         output = StringIO()
+        data = self._create_datafile(path)
         data.save(output=output, **self._options)
         return output.getvalue()

     def directory(self, path):
-        self._save_recursively(self._create_data_directory(path))
+        self._save_directory(TestDataDirectory(source=path).populate())

     def inplace(self, path):
-        data = self._create_datafile(path)
-        self._remove_original(data)
+        self._save_file(self._create_datafile(path))
+
+    def _save_file(self, data):
+        source = data.initfile if self._is_directory(data) else data.source
+        if source:
+            os.remove(source)
         data.save(**self._options)

-    def _create_data_directory(self, path):
-        return TestDataDirectory(source=path).populate()
-
-    def _remove_original(self, data):
-        initfile = getattr(data, 'initfile', None)
-        source = initfile or data.source
-        os.remove(source)
-
-    def _save_recursively(self, data):
-        init_file = getattr(data, 'initfile', None)
-        if init_file or not hasattr(data, 'initfile'):
-            data.save(**self._options)
-        if os.path.isfile(data.source):
-            os.remove(data.source)
-        if init_file:
-            os.remove(init_file)
+    def _save_directory(self, data):
+        if not self._is_directory(data):
+            self._save_file(data)
+            return
+        if data.initfile:
+            self._save_file(data)
         for child in data.children:
-            self._save_recursively(child)
+            self._save_directory(child)
+
+    def _is_directory(self, data):
+        return hasattr(data, 'initfile')

     def _create_datafile(self, source):
-        if os.path.splitext(os.path.basename(source))[0] == '__init__':
-            data = TestDataDirectory()
-            data.source = os.path.dirname(source)
-            data.initfile = source
-            FromFilePopulator(data).populate(source)
-            return data
+        if self._is_init_file(source):
+            return self._create_init_file(source)
         try:
             return TestCaseFile(source=source).populate()
         except DataError:
             try:
                 return ResourceFile(source=source).populate()
             except DataError:
-                raise DataError("Invalid data source '%s'" % source)
+                raise DataError("Invalid data source '%s'." % source)
+
+    def _is_init_file(self, source):
+        return os.path.splitext(os.path.basename(source))[0] == '__init__'
+
+    def _create_init_file(self, source):
+        data = TestDataDirectory()
+        data.source = os.path.dirname(source)
+        data.initfile = source
+        FromFilePopulator(data).populate(source)
+        return data


 class TidyCommandLine(object):
@@ -151,25 +158,31 @@
     def _parse_args(self, args):
         options, sources = self._parser.parse_args(args, help='help')
         if options['inplace'] and options['recursive']:
- raise DataError('--recursive and --inplace can not be used together') + raise DataError('--recursive and --inplace can not be used together.')
         if not options['inplace'] and len(sources) > 1:
-            raise DataError('Expected exactly 1 input file')
+            raise DataError('Expected exactly 1 input file.')
         if not sources:
-            raise DataError('Expected at least 1 input file')
+            raise DataError('Expected at least 1 input file.')
         if options['recursive'] and not os.path.isdir(sources[0]):
-            raise DataError("Invalid data source '%s'" % sources[0])
+ raise DataError('--recursive requires input to be a directory.')
         format = options['format']
         if format and format not in ['txt', 'tsv', 'html']:
-            raise DataError("Invalid value for format option: %s" % format)
+            raise DataError("Invalid format: %s." % format)
         return options, sources


+def console(msg):
+    print msg
+
+
 if __name__ == '__main__':
     try:
         output = TidyCommandLine(__doc__).run(sys.argv[1:])
         if output:
-            print output
+            console(output)
     except DataError, err:
-        print __doc__
-        sys.exit(unicode(err))
+        console('%s\n\n%sUse --help for usage.' % unicode(err))
+        sys.exit(1)
+    except Information, msg:
+        console(unicode(msg))
     sys.exit(0)

==============================================================================
Revision: 56e33dc909d6
Author:   Robot Framework Developers <[email protected]>
Date:     Tue Jan 24 04:06:17 2012
Log:      tidy: ug section
http://code.google.com/p/robotframework/source/detail?r=56e33dc909d6

Modified:
 /doc/userguide/src/SupportingTools/SupportingTools.txt

=======================================
--- /doc/userguide/src/SupportingTools/SupportingTools.txt Wed Jan 18 03:20:34 2012 +++ /doc/userguide/src/SupportingTools/SupportingTools.txt Tue Jan 24 04:06:17 2012
@@ -1,11 +1,3 @@
-Test data editing tool (RIDE)
------------------------------
-
-RIDE is a standalone tool for editing test data. It helps in
-creating, editing and maintaining of Robot Framework test data.
-The project pages are at https://github.com/robotframework/RIDE/.
-
-
 Library documentation tool
 --------------------------

@@ -18,13 +10,78 @@
 Test data tidying tool
 ----------------------

-:prog:`robot.tidy` is a tool for cleaning up test data files and for changing
-format of data files between HTML, TSV and TXT. This tool is installed with
-Robot Framework, and can be invoked from the commandline with::
-
-    python -m robot.tidy [options] input_file[s]
-
-Run `python -m robot.tidy --help` for more information.
+This tool can be used to clean up and change format of Robot Framework test
+data files. By default, the output is written to the standard output stream,
+but it can be redirected to a file. Alternatively, files can be modified
+in-place using :opt:`--inplace` or :opt:`--recursive` options.
+
+Synopsis
+~~~~~~~~
+
+::
+
+    python -m robot.tidy [options] inputfile
+    python -m robot.tidy [options] inputfile > outputfile
+    python -m robot.tidy --inplace [options] inputfile [more input files]
+    python -m robot.tidy --recursive [options] directory
+
+Options
+~~~~~~~
+
+ -i, --inplace Tidy given file(s) so that original file(s) are overwritten + (or removed, if the format is changed). When this option is + used, it is possible to give multiple input files. Examples::
+
+                      python -m robot.tidy --inplace tests.html
+                      python -m robot.tidy --inplace --format txt *.html
+
+ -r, --recursive Process given directory recursively. Files in the directory
+                  are processed in place similarly as when :opt:`--inplace`
+                  option is used.
+ -f, --format <txt|html|tsv>
+                  Output file format. If omitted, the format of the input
+                  file is used.
+ -p, --use-pipes Use a pipe character (|) as a cell separator in the txt format.
+ -h, --help       Show this help.
+
+Cleaning up the test data
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Test case files created with HTML editors or written by hand can be normalized
+using tidy. Tidy always writes consistent headers, consistent order for
+settings, and consistent amount of whitespace between cells and tables.
+
+Examples::
+
+  python -m robot.tidy messed_up_tests.html > cleaned_tests.html
+  python -m robot.tidy --inplace tests.txt
+
+Changing test data format
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Robot Framework supports test data in HTML, TSV and TXT formats and this tool +makes changing between the formats trivial. Input format is always determined
+based on the extension of the input file. Output format can be set using
+the :opt:`--format` option.
+
+Examples::
+
+  python -m robot.tidy --format tsv tests_in_html.html > tests_in_tsv.tsv
+  python -m robot.tidy --format txt --recursive mytests
+
+Output encoding
+~~~~~~~~~~~~~~~
+
+All output files are written using UTF-8 encoding. Outputs written to the
+console use the current console encoding.
+
+
+Test data editing tool (RIDE)
+-----------------------------
+
+RIDE is a standalone tool for editing test data. It helps in
+creating, editing and maintaining of Robot Framework test data.
+The project pages are at https://github.com/robotframework/RIDE/.


 Other tools

Reply via email to