class XsltParserTestCase(DocutilsTestSupport.ParserTestCase): """ Output checker for XsltParser. """ xslt = None """ :type: basestring XSLT sheet to use for processing. 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): """ :Parameters: See super class for arguments. input : unicode | ( dict, unicode ) Either the input string to use or a tuple with a dictionary containing settings for this test case and the input string. expected : unicode | type Either the expected output string or an exception class. If an exception class is given the test case is expected to raise this exception. """ 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): if isinstance(self.input, (list, tuple)): (case_settings, input) = self.input else: (case_settings, input) = ({}, self.input) settings = self.settings.copy() settings.__dict__.update(self.suite_settings) settings.__dict__.update(case_settings) document = docutils.utils.new_document('test data', settings) if (isinstance(self.expected, type) and issubclass(self.expected, Exception)): with self.assertRaises(self.expected): self.parser.parse(input, document) else: self.parser.parse(input, document) writer = XsltWriter() output = writer.write(document, docutils.io.StringOutput()) self.compare_output(input, output, self.expected)
class XsltParserTestCase(DocutilsTestSupport.ParserTestCase): """ Output checker for XsltParser. """ xslt = None """ :type: basestring XSLT sheet to use for processing. 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): """ :Parameters: See super class for arguments. input : unicode | ( dict, unicode ) Either the input string to use or a tuple with a dictionary containing settings for this test case and the input string. expected : unicode | type Either the expected output string or an exception class. If an exception class is given the test case is expected to raise this exception. """ 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): if isinstance(self.input, (list, tuple)): (case_settings, input) = self.input else: (case_settings, input) = ({}, self.input) settings = self.settings.copy() settings.__dict__.update(self.suite_settings) settings.__dict__.update(case_settings) document = docutils.utils.new_document("test data", settings) if isinstance(self.expected, type) and issubclass(self.expected, Exception): with self.assertRaises(self.expected): self.parser.parse(input, document) else: self.parser.parse(input, document) writer = XsltWriter() output = writer.write(document, docutils.io.StringOutput()) self.compare_output(input, output, self.expected)
def __init__(self, *args, **kwargs): """ :Parameters: See super class for arguments. input : unicode | ( dict, unicode ) Either the input string to use or a tuple with a dictionary containing settings for this test case and the input string. expected : unicode | type Either the expected output string or an exception class. If an exception class is given the test case is expected to raise this exception. """ 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 __init__(self, *args, **kwargs): """ :Parameters: See super class for arguments. input : unicode | ( dict, unicode ) Either the input string to use or a tuple with a dictionary containing settings for this test case and the input string. expected : unicode | type Either the expected output string or an exception class. If an exception class is given the test case is expected to raise this exception. """ 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)
class Parser(XsltParser): """ Parse the input file and translate it to the output file by using XSLT. """ MainXsltNm = 'odf2docutils.xsl' """ :type: str Name of the main XSLT source file. """ def __init__(self): modP = os.path.dirname(__file__) xsltPath = os.path.join(modP, self.MainXsltNm) try: xsltF = open(xsltPath) except IOError, e: raise Exception("Can't open main XSLT file %r: %s" % ( xsltPath, e, )) XsltParser.__init__(self, xsltF)