From: <sm...@us...> - 2013-11-24 13:05:18
|
Revision: 7732 http://sourceforge.net/p/docutils/code/7732 Author: smerten Date: 2013-11-24 13:05:15 +0000 (Sun, 24 Nov 2013) Log Message: ----------- `XsltParser` accepts XPath extensions. Modified Paths: -------------- trunk/sandbox/docutils_xml/docutils_xml/parsers/xslt.py trunk/sandbox/docutils_xml/global.log trunk/sandbox/docutils_xml/tag.log trunk/sandbox/docutils_xml/test/test_parsers/test_XsltParser.py trunk/sandbox/docutils_xml/version.py Modified: trunk/sandbox/docutils_xml/docutils_xml/parsers/xslt.py =================================================================== --- trunk/sandbox/docutils_xml/docutils_xml/parsers/xslt.py 2013-11-23 11:05:59 UTC (rev 7731) +++ trunk/sandbox/docutils_xml/docutils_xml/parsers/xslt.py 2013-11-24 13:05:15 UTC (rev 7732) @@ -29,6 +29,8 @@ from lxml import etree +import math + ############################################################################### ############################################################################### # Constants @@ -45,18 +47,149 @@ ############################################################################### # Classes +class XPathExtension(object): + """ + Abstract base class for XPath extension functions. All public methods + defined in a derived class are extension functions which can be called from + XSLT. + + Methods to be used as extension functions need to accept an fixed first + parameter. + + :Parameters: + + context : `lxml.etree._XSLTContext` + The evaluation context. + + Apart from that any number of parameters may be given according to the + signature of the XPath function. + """ + + namespace = None + """ + :type: str + + Namespace for these XSLT extension functions defined by this class. + + Override this in derived classes. + """ + + def _stringParameter(self, string): + """ + :return: The normalized string parameter from an XPath parameter. + :rtype: unicode + + :Parameters: + + string : `lxml.etree._ElementStringResult` | [ `lxml.etree._ElementStringResult`, ] | [ `lxml.etree._Element`, ] | [ ] + Original XPath string parameter. + + :Exceptions: + + TypeError + When a type is given which is incompatible with an XPath string. + """ + if isinstance(string, list): + if len(string) == 0: + # Happens for forced but non-existing elements like `text()` in + # an empty element + return u"" + elif len(string) == 1: + string = string[0] + else: + raise TypeError("Encountered an XPath string parameter with more than one (%d) element" % ( len(string), )) + + if isinstance(string, basestring): + return unicode(string) + else: + raise TypeError("Encountered invalid type for XPath string parameter: %s" + % type(string) ) + + def _boolParameter(self, boolean): + """ + :return: The normalized bool parameter from an XPath parameter. + :rtype: bool + + :Parameters: + + boolean : bool + Original XPath bool parameter. + + :Exceptions: + + TypeError + When a type is given which is incompatible with a boolean. + """ + if isinstance(boolean, bool): + return boolean + raise TypeError("Encountered invalid type for XPath boolean parameter: %s" + % type(boolean) ) + + def _floatParameter(self, number): + """ + :return: The normalized float parameter from an XPath parameter. + :rtype: float + + :Parameters: + + number : float + Original XPath number parameter. + + :Exceptions: + + TypeError + When a type is given which is incompatible with an float. + """ + if isinstance(number, float): + + return number + raise TypeError("Encountered invalid type for XPath float parameter: %s" + % type(number) ) + + def _intParameter(self, number): + """ + :return: The normalized int parameter from an XPath parameter. + :rtype: int + + :Parameters: + + number : int + Original XPath number parameter. + + :Exceptions: + + TypeError + When a type is given which is incompatible with an int. + + ValueError + When the number has a non-trivial fractional part. + """ + if isinstance(number, float): + ( fraction, integer ) = math.modf(number) + if fraction == 0: + return int(number) + raise ValueError("XPath number (%f) has non-trivial fractiona part" + % ( number, )) + raise TypeError("Encountered invalid type for XPath int parameter: %s" + % type(number) ) + +############################################################################### + class XsltParser(docutils.parsers.Parser): """ Parses XML input by XSLT and stores the result in the attribute `xslt_result` of the document. Works together with `XsltWriter`. """ - def __init__(self, xsltSource): + def __init__(self, xsltSource, extension=None): """ :Parameters: xsltSource : file-like object The source containing the XSLT. This is an open file-like object. + + extension : None | XPathExtension + The extensions to use or None for no extensions. """ self.xslt = None """ @@ -70,7 +203,11 @@ except Exception, e: raise Exception("Error parsing XSLT: %s" % ( e, )) xsltSource.close() - self.xslt = etree.XSLT(xsltDoc) + if extension is None: + exts = None + else: + exts = etree.Extension(extension, ns=extension.namespace) + self.xslt = etree.XSLT(xsltDoc, extensions=exts) def parse(self, inputstring, document): self.setup_parse(inputstring, document) Modified: trunk/sandbox/docutils_xml/global.log =================================================================== --- trunk/sandbox/docutils_xml/global.log 2013-11-23 11:05:59 UTC (rev 7731) +++ trunk/sandbox/docutils_xml/global.log 2013-11-24 13:05:15 UTC (rev 7732) @@ -1,4 +1,324 @@ ************************************** +Date: Sun Nov 24 14:00:35 CET 2013 +Author: stefan +Tag: docutils_xml_1_46 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added test for non-integer conversion. +************************************** +Date: Sun Nov 24 13:58:27 CET 2013 +Author: stefan +Tag: docutils_xml_1_45 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added tests for giving node content. +************************************** +Date: Sun Nov 24 13:51:34 CET 2013 +Author: stefan +Tag: docutils_xml_1_44 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added tests for missing parameters. +************************************** +Date: Sun Nov 24 13:48:08 CET 2013 +Author: stefan +Tag: docutils_xml_1_43 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added tests with constants. +************************************** +Date: Sun Nov 24 13:11:55 CET 2013 +Author: stefan +Tag: docutils_xml_1_42 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Tests may throw exceptions. +************************************** +Date: Sun Nov 24 12:40:29 CET 2013 +Author: stefan +Tag: docutils_xml_1_41 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added int conversion. +************************************** +Date: Sun Nov 24 12:27:06 CET 2013 +Author: stefan +Tag: docutils_xml_1_40 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added float conversion. +************************************** +Date: Sat Nov 23 21:56:56 CET 2013 +Author: stefan +Tag: docutils_xml_1_39 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added tests for `_boolParameter`(). +************************************** +Date: Sat Nov 23 21:31:20 CET 2013 +Author: stefan +Tag: docutils_xml_1_38 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Added test. +************************************** +Date: Sat Nov 23 21:19:43 CET 2013 +Author: stefan +Tag: docutils_xml_1_37 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Debugging. All tests run. +************************************** +Date: Sat Nov 23 16:56:34 CET 2013 +Author: stefan +Tag: docutils_xml_1_36 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Debugging. Some tests fail. +************************************** +Date: Sat Nov 23 16:15:32 CET 2013 +Author: stefan +Tag: docutils_xml_1_35 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Debugging. Tests run. +************************************** +Date: Sat Nov 23 14:10:42 CET 2013 +Author: stefan +Tag: docutils_xml_1_34 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Extensions are registered in `XsltParser`. Tests do not work yet. +************************************** +Date: Sat Nov 23 13:52:35 CET 2013 +Author: stefan +Tag: docutils_xml_1_33 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +XPath extension is integrated in tests but not in `XsltParser`. +************************************** +Date: Sat Nov 23 13:22:05 CET 2013 +Author: stefan +Tag: docutils_xml_1_32 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Refactoring: Test infrastructure for `XsltParser` allows various XSLT +sheets. +************************************** +Date: Sat Nov 23 13:00:20 CET 2013 +Author: stefan +Tag: docutils_xml_1_31 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/test/test_parsers +In directory eskebo:/home/stefan/free/docutils_xml/test/test_parsers + +Modified Files: + test_XsltParser.py + +-------------------------------------- +Log Message: +Refactoring: Test infrastructure for `XsltParser` allows various XSLT +sheets. +************************************** +Date: Sat Nov 23 12:44:01 CET 2013 +Author: stefan +Tag: docutils_xml_1_30 + +-------------------------------------- +Update of /home/stefan/vault/sm/docutils_xml/docutils_xml/parsers +In directory eskebo:/home/stefan/free/docutils_xml/docutils_xml/parsers + +Modified Files: + xslt.py + +-------------------------------------- +Log Message: +Moved `XPathExtension` from `xml2rstlib` to `docutils_xml`. +************************************** Date: Fri Nov 22 18:14:40 CET 2013 Author: stefan Tag: docutils_xml_1_29 Modified: trunk/sandbox/docutils_xml/tag.log =================================================================== --- trunk/sandbox/docutils_xml/tag.log 2013-11-23 11:05:59 UTC (rev 7731) +++ trunk/sandbox/docutils_xml/tag.log 2013-11-24 13:05:15 UTC (rev 7732) @@ -1 +1 @@ -docutils_xml_1_29 +docutils_xml_1_46 Modified: trunk/sandbox/docutils_xml/test/test_parsers/test_XsltParser.py =================================================================== --- trunk/sandbox/docutils_xml/test/test_parsers/test_XsltParser.py 2013-11-23 11:05:59 UTC (rev 7731) +++ trunk/sandbox/docutils_xml/test/test_parsers/test_XsltParser.py 2013-11-24 13:05:15 UTC (rev 7732) @@ -22,10 +22,11 @@ import unittest import docutils.utils, docutils.frontend import StringIO +from lxml import etree from __init__ import DocutilsTestSupport -from docutils_xml.parsers.xslt import XsltParser +from docutils_xml.parsers.xslt import XsltParser, XPathExtension from docutils_xml.writers.xslt import XsltWriter ############################################################################### @@ -35,54 +36,529 @@ Output checker for XsltParser. """ - identityXslt = u"""\ -<?xml version="1.0"?> -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - <xsl:template match="/"> - <xsl:copy-of select="/"/> - </xsl:template> -</xsl:stylesheet> -""" + xslt = None + """ + :type: basestring - parser = XsltParser(StringIO.StringIO(identityXslt)) - """Parser shared by all XsltParserTestCases.""" + XSLT sheet to use for processing. - option_parser = docutils.frontend.OptionParser(components=( - XsltParser, )) + Override this in subclasses. + """ + extension = None + """ + :type: None | XPathExtension + + XPath extension class to use. + + Override this in subclasses if you need XPath extension functions. + """ + + def __init__(self, *args, **kwargs): + self.parser = XsltParser(StringIO.StringIO(self.xslt), self.extension) + """Input parser for this test case.""" + self.option_parser = docutils.frontend.OptionParser(components=( + self.parser, )) + DocutilsTestSupport.ParserTestCase.__init__(self, *args, **kwargs) + def test_parser(self): settings = self.settings.copy() settings.__dict__.update(self.suite_settings) document = docutils.utils.new_document('test data', settings) - self.parser.parse(self.input, document) - writer = XsltWriter() - output = writer.write(document, docutils.io.StringOutput()) - self.compare_output(self.input, output, self.expected) + if (isinstance(self.expected, type) + and issubclass(self.expected, Exception)): + with self.assertRaises(self.expected): + self.parser.parse(self.input, document) + else: + self.parser.parse(self.input, document) + writer = XsltWriter() + output = writer.write(document, docutils.io.StringOutput()) + self.compare_output(self.input, output, self.expected) ############################################################################### +############################################################################### -class XsltParserTestSuite(DocutilsTestSupport.ParserTestSuite): +class XsltParserIdentityTestCase(XsltParserTestCase): + """ + Output checker for XsltParser with identity transformation. + """ - test_case_class = XsltParserTestCase + xslt = u"""\ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:template match="/"> + <xsl:copy-of select="/"/> + </xsl:template> +</xsl:stylesheet> +""" ############################################################################### -totest = {} +class XsltParserIdentityTestSuite(DocutilsTestSupport.ParserTestSuite): -totest['simple'] = ( + test_case_class = XsltParserIdentityTestCase + +############################################################################### + +identity = { } + +identity['simple'] = ( ( u"""<?xml version="1.0"?> <rootOnly/> """, u"""<?xml version="1.0"?> <rootOnly/> """ ), + ( u"""<?xml version="1.0"?> +""", + etree.LxmlSyntaxError, ), + ( u"""<?xml version="1.0"?> +<rootOnly> +""", + etree.LxmlSyntaxError, ), ) ############################################################################### +############################################################################### +class XPathExtensionTest(XPathExtension): + """ + XPath extension functions for test purposes. + """ + + namespace = "http://www.merten-home.de/docutils_xml" + + def parVoid(self, context): + """ + Accept no parameters and do nothing. + """ + pass + + def parString(self, context, s): + """ + Accept a string parameter and return its string representation. + + :Parameters: + + s : Smart string + The smart string. + """ + return repr(self._stringParameter(s)) + + def parBoolean(self, context, b): + """ + Accept a boolean parameter and return its string representation. + + :Parameters: + + b : boolean + The boolean. + """ + return str(self._boolParameter(b)) + + def parFloat(self, context, f): + """ + Accept a float parameter and return its string representation. + + :Parameters: + + f : float + The float. + """ + return str(self._floatParameter(f)) + + def parInt(self, context, i): + """ + Accept an int parameter and return its string representation. + + :Parameters: + + i : int + The int. + """ + return str(self._intParameter(i)) + +############################################################################### + +class XsltParserXPathExtensionTestCase(XsltParserTestCase): + """ + Output checker for XsltParser using XPath extension functions. + """ + + xslt = u"""\ +<?xml version="1.0"?> +<xsl:stylesheet + xmlns:ext="http://www.merten-home.de/docutils_xml" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0"> + + <xsl:output + method="text" + encoding="utf-8"/> + + <xsl:template + name="output"> + <xsl:param + name="value"/> + <xsl:value-of + select="$value"/> + <xsl:text>
</xsl:text> + </xsl:template> + + <xsl:template + match="void"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parVoid()"/> + </xsl:call-template> + <xsl:apply-templates/> + </xsl:template> + + <!-- Constant values. --> + + <xsl:template + match="test[@const]"> + <xsl:choose> + <xsl:when + test="@type = 'string'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parString('Constant')"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'boolean'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parBoolean(true())"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'float'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parFloat(3.14)"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'int'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parInt(42)"/> + </xsl:call-template> + </xsl:when> + </xsl:choose> + <xsl:apply-templates/> + </xsl:template> + + <!-- Missing values. --> + + <xsl:template + match="test[@missing]"> + <xsl:choose> + <xsl:when + test="@type = 'string'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parString()"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'boolean'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parBoolean()"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'float'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parFloat()"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'int'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parInt()"/> + </xsl:call-template> + </xsl:when> + </xsl:choose> + <xsl:apply-templates/> + </xsl:template> + + <!-- Element as value. --> + + <xsl:template + match="test[@node]"> + <xsl:choose> + <xsl:when + test="@type = 'string'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parString(.)"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'boolean'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parBoolean(.)"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'float'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parFloat(.)"/> + </xsl:call-template> + </xsl:when> + <xsl:when + test="@type = 'int'"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parInt(.)"/> + </xsl:call-template> + </xsl:when> + </xsl:choose> + <xsl:apply-templates/> + </xsl:template> + + <!-- Test attribute values. --> + + <xsl:template + match="@string"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parString(.)"/> + </xsl:call-template> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template + match="@boolean"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parBoolean(boolean(string(.)))"/> + </xsl:call-template> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template + match="@float"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parFloat(number(.))"/> + </xsl:call-template> + <xsl:apply-templates/> + </xsl:template> + + <xsl:template + match="@int"> + <xsl:call-template + name="output"> + <xsl:with-param + name="value" + select="ext:parInt(number(.))"/> + </xsl:call-template> + <xsl:apply-templates/> + </xsl:template> + + <!-- By default apply also to attributes. --> + <xsl:template + match="* | /"> + <xsl:apply-templates + select="* | @* | text()"/> + </xsl:template> + + <!-- Suppress normal output. --> + <xsl:template + match="text() | @*"/> + +</xsl:stylesheet> +""" + + extension = XPathExtensionTest() + +############################################################################### + +class XsltParserXPathExtensionTestSuite(DocutilsTestSupport.ParserTestSuite): + + test_case_class = XsltParserXPathExtensionTestCase + +############################################################################### + +xPathExtension = { } + +xPathExtension['simple'] = ( + ( u"""<?xml version="1.0"?> +<root/> +""", + u"" ), + + ( u"""<?xml version="1.0"?> +<void/> +""", + u""" +""" ), + + # string + ( u"""<?xml version="1.0"?> +<test type="string" const=""/> +""", + u"""u'Constant' +""" ), + ( u"""<?xml version="1.0"?> +<root string="Attribute content"/> +""", + u"""u'Attribute content' +""" ), + ( u"""<?xml version="1.0"?> +<test type="string" missing=""/> +""", + TypeError ), + ( u"""<?xml version="1.0"?> +<test type="string" node="">Element content</test> +""", + TypeError ), + + # boolean + ( u"""<?xml version="1.0"?> +<test type="boolean" const=""/> +""", + u"""True +""" ), + ( u"""<?xml version="1.0"?> +<root boolean="non-empty"/> +""", + u"""True +""" ), + ( u"""<?xml version="1.0"?> +<root boolean=""/> +""", + u"""False +""" ), + ( u"""<?xml version="1.0"?> +<test type="boolean" missing=""/> +""", + TypeError ), + ( u"""<?xml version="1.0"?> +<test type="boolean" node="">non-empty</test> +""", + TypeError ), + + # float + ( u"""<?xml version="1.0"?> +<test type="float" const=""/> +""", + u"""3.14 +""" ), + ( u"""<?xml version="1.0"?> +<root float="0"/> +""", + u"""0.0 +""" ), + ( u"""<?xml version="1.0"?> +<root float=" -3.7 "/> +""", + u"""-3.7 +""" ), + ( u"""<?xml version="1.0"?> +<root float="1e-3"/> +""", + u"""0.001 +""" ), + ( u"""<?xml version="1.0"?> +<test type="float" missing=""/> +""", + TypeError ), + ( u"""<?xml version="1.0"?> +<test type="float" node="">10.7</test> +""", + TypeError ), + + # int + ( u"""<?xml version="1.0"?> +<test type="int" const=""/> +""", + u"""42 +""" ), + ( u"""<?xml version="1.0"?> +<root int="0"/> +""", + u"""0 +""" ), + ( u"""<?xml version="1.0"?> +<root int=" -3 "/> +""", + u"""-3 +""" ), + ( u"""<?xml version="1.0"?> +<root int="1e3"/> +""", + u"""1000 +""" ), + ( u"""<?xml version="1.0"?> +<test type="int" missing=""/> +""", + TypeError ), + ( u"""<?xml version="1.0"?> +<test type="int" node="">17</test> +""", + TypeError ), + ( u"""<?xml version="1.0"?> +<root int="3.14"/> +""", + ValueError ), + ) + +############################################################################### +############################################################################### + def suite(): - s = XsltParserTestSuite() - s.generateTests(totest) + s = unittest.TestSuite() + + identitySuite = XsltParserIdentityTestSuite() + identitySuite.generateTests(identity, dictname='identity') + s.addTest(identitySuite) + + xPathExtensionSuite = XsltParserXPathExtensionTestSuite() + xPathExtensionSuite.generateTests(xPathExtension, dictname='xPathExtension') + s.addTest(xPathExtensionSuite) + return s ############################################################################### Modified: trunk/sandbox/docutils_xml/version.py =================================================================== --- trunk/sandbox/docutils_xml/version.py 2013-11-23 11:05:59 UTC (rev 7731) +++ trunk/sandbox/docutils_xml/version.py 2013-11-24 13:05:15 UTC (rev 7732) @@ -1 +1 @@ -version = '0.2.1' +version = '0.2.6' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |