gimp-help-2 r2566 - in branches/xml2po-support: . tools
- From: romanofski svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp-help-2 r2566 - in branches/xml2po-support: . tools
- Date: Sun, 28 Sep 2008 11:44:18 +0000 (UTC)
Author: romanofski
Date: Sun Sep 28 11:44:17 2008
New Revision: 2566
URL: http://svn.gnome.org/viewvc/gimp-help-2?rev=2566&view=rev
Log:
2008-09-28 Roman Joost <romanofski gimp org>
* tools/split_xml_multi_lang.txt
* tools/split-xml-multi-lang.py
* tools/split_xml_multi_lang.py: renamed to be valid filename
(recommended by PEP8), added doctest which can be run by the
--test option
Added:
branches/xml2po-support/tools/split_xml_multi_lang.py
- copied, changed from r2565, /branches/xml2po-support/tools/split-xml-multi-lang.py
branches/xml2po-support/tools/split_xml_multi_lang.txt
Removed:
branches/xml2po-support/tools/split-xml-multi-lang.py
Modified:
branches/xml2po-support/ChangeLog
Copied: branches/xml2po-support/tools/split_xml_multi_lang.py (from r2565, /branches/xml2po-support/tools/split-xml-multi-lang.py)
==============================================================================
--- /branches/xml2po-support/tools/split-xml-multi-lang.py (original)
+++ branches/xml2po-support/tools/split_xml_multi_lang.py Sun Sep 28 11:44:17 2008
@@ -25,13 +25,16 @@
import os
import os.path
import codecs
-#import getopt
import optparse
import re
import xml.dom.minidom
import logging
import profile
+import unittest
+import doctest
+
+
# Configure logging package
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s %(message)s")
Logger = logging.getLogger("splitxml")
@@ -82,6 +85,7 @@
class XmlNode(object):
"""FIXME"""
+
def __init__(self, node):
self.logger = logging.getLogger("splitxml.node")
assert isinstance(node, xml.dom.minidom.Node)
@@ -492,12 +496,24 @@
doc.printfiles(options.destdir)
+def runtests():
+ """Runs registered automated tests."""
+ testrunner = unittest.TextTestRunner()
+ suite = unittest.TestSuite()
+ suite.addTest(
+ doctest.DocFileSuite("split_xml_multi_lang.txt",
+ optionflags = doctest.NORMALIZE_WHITESPACE |
+ doctest.ELLIPSIS |
+ doctest.REPORT_NDIFF)
+ )
+ testrunner.run(suite)
+
+
# Main program start
if __name__ == '__main__':
- if "--profile" in sys.argv:
+ if "--profile" in sys.argv:
profile.run("main()")
+ if "--test" in sys.argv:
+ runtests()
else:
main()
-# pydoc doesn't like the following "raise" statement
-#else:
-# raise NotImplementedError
Added: branches/xml2po-support/tools/split_xml_multi_lang.txt
==============================================================================
--- (empty file)
+++ branches/xml2po-support/tools/split_xml_multi_lang.txt Sun Sep 28 11:44:17 2008
@@ -0,0 +1,63 @@
+==========================
+Split XML Multilang Script
+==========================
+
+
+This test, tests the functionaility of the multilang split script. The
+central class is MultiLangDoc, which will be tested in the following
+paragraphs.
+
+
+MultiLangDoc
+============
+
+Setup
+-----
+
+The class provides functionality for reading and parsing multi-lang
+DocBook source files. It has the ability to split the parsed document
+into a by-language sorted single language documents. To test the class,
+we need an XML testfile first, which we grab out of the GIMP Manual
+source tree:
+
+>>> import os
+>>> import os.path
+>>> roothelpdir = os.path.dirname(os.getcwd())
+>>> testxmlfile = os.path.join(roothelpdir,
+... 'src', 'toolbox', 'toolbox-color-area.xml')
+
+We also need a destination directory, which we create temporary:
+
+>>> import tempfile
+>>> destdir = tempfile.mkdtemp()
+
+Now we can create the multilangdoc object:
+
+>>> from split_xml_multi_lang import MultiLangDoc
+>>> mld = MultiLangDoc(testxmlfile, destdir)
+>>> mld
+<split_xml_multi_lang.MultiLangDoc object at 0x...>
+>>> mld.filename == testxmlfile
+True
+>>> mld.destdir == destdir
+True
+
+
+Processing
+----------
+
+Once the xmlfile is parsed, we can process it. That means, we provide in
+which languages the document should be splitted.
+
+The default language which is used by processing is English. The
+attribute is set after processing:
+
+>>> mld.languages
+Traceback (most recent call last):
+AttributeError: 'MultiLangDoc' object has no attribute 'languages'
+
+If the languages parameter is an empty list, the processing is only done
+for English:
+
+>>> mld.process([])
+{u'en': <DOM Element: sect1 at -0x...>}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]