From 101671ae44e1686680c80cd07b452aabeb88fb63 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 20 Apr 2002 03:01:52 +0000 Subject: Initial revision git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@18 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 379 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 test/DocutilsTestSupport.py (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py new file mode 100644 index 000000000..766eafde6 --- /dev/null +++ b/test/DocutilsTestSupport.py @@ -0,0 +1,379 @@ +#! /usr/bin/env python + +""" +:Authors: David Goodger; Garth Kidd +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +Exports the following: + +:Modules: + - `statemachine` is 'docutils.statemachine' + - `nodes` is 'docutils.nodes' + - `urischemes` is 'docutils.urischemes' + - `utils` is 'docutils.utils' + - `transforms` is 'docutils.transforms' + - `states` is 'docutils.parsers.rst.states' + - `tableparser` is 'docutils.parsers.rst.tableparser' + +:Classes: + - `CustomTestSuite` + - `CustomTestCase` + - `ParserTestSuite` + - `ParserTestCase` + - `TableParserTestSuite` + - `TableParserTestCase` +""" +__docformat__ = 'reStructuredText' + +import UnitTestFolder +import sys, os, unittest, difflib, inspect, os, sys +from pprint import pformat +import docutils +from docutils import statemachine, nodes, urischemes, utils, transforms +from docutils.transforms import universal +from docutils.parsers import rst +from docutils.parsers.rst import states, tableparser, directives, languages +from docutils.statemachine import string2lines + +try: + import mypdb as pdb +except: + import pdb + + +class CustomTestSuite(unittest.TestSuite): + + """ + A collection of custom TestCases. + + """ + + id = '' + """Identifier for the TestSuite. Prepended to the + TestCase identifiers to make identification easier.""" + + nextTestCaseId = 0 + """The next identifier to use for non-identified test cases.""" + + def __init__(self, tests=(), id=None): + """ + Initialize the CustomTestSuite. + + Arguments: + + id -- identifier for the suite, prepended to test cases. + """ + unittest.TestSuite.__init__(self, tests) + if id is None: + outerframes = inspect.getouterframes(inspect.currentframe()) + mypath = outerframes[0][1] + for outerframe in outerframes[1:]: + if outerframe[3] != '__init__': + callerpath = outerframe[1] + break + mydir, myname = os.path.split(mypath) + if not mydir: + mydir = os.curdir + if callerpath.startswith(mydir): + self.id = callerpath[len(mydir) + 1:] # caller's module + else: + self.id = callerpath + else: + self.id = id + + def addTestCase(self, testCaseClass, methodName, input, expected, + id=None, runInDebugger=0, shortDescription=None, + **kwargs): + """ + Create a custom TestCase in the CustomTestSuite. + Also return it, just in case. + + Arguments: + + testCaseClass -- + methodName -- + input -- input to the parser. + expected -- expected output from the parser. + id -- unique test identifier, used by the test framework. + runInDebugger -- if true, run this test under the pdb debugger. + shortDescription -- override to default test description. + """ + if id is None: # generate id if required + id = self.nextTestCaseId + self.nextTestCaseId += 1 + # test identifier will become suiteid.testid + tcid = '%s: %s' % (self.id, id) + # generate and add test case + tc = testCaseClass(methodName, input, expected, tcid, + runInDebugger=runInDebugger, + shortDescription=shortDescription, + **kwargs) + self.addTest(tc) + return tc + + +class CustomTestCase(unittest.TestCase): + + compare = difflib.Differ().compare + """Comparison method shared by all subclasses.""" + + def __init__(self, methodName, input, expected, id, + runInDebugger=0, shortDescription=None): + """ + Initialise the CustomTestCase. + + Arguments: + + methodName -- name of test method to run. + input -- input to the parser. + expected -- expected output from the parser. + id -- unique test identifier, used by the test framework. + runInDebugger -- if true, run this test under the pdb debugger. + shortDescription -- override to default test description. + """ + self.id = id + self.input = input + self.expected = expected + self.runInDebugger = runInDebugger + # Ring your mother. + unittest.TestCase.__init__(self, methodName) + + def __str__(self): + """ + Return string conversion. Overridden to give test id, in addition to + method name. + """ + return '%s; %s' % (self.id, unittest.TestCase.__str__(self)) + + def compareOutput(self, input, output, expected): + """`input`, `output`, and `expected` should all be strings.""" + try: + self.assertEquals('\n' + output, '\n' + expected) + except AssertionError: + print >>sys.stderr, '\n%s\ninput:' % (self,) + print >>sys.stderr, input + print >>sys.stderr, '-: expected\n+: output' + print >>sys.stderr, ''.join(self.compare(expected.splitlines(1), + output.splitlines(1))) + raise + + +class TransformTestSuite(CustomTestSuite): + + """ + A collection of TransformTestCases. + + A TransformTestSuite instance manufactures TransformTestCases, + keeps track of them, and provides a shared test fixture (a-la + setUp and tearDown). + """ + + def __init__(self, parser): + self.parser = parser + """Parser shared by all test cases.""" + + CustomTestSuite.__init__(self) + + def generateTests(self, dict, dictname='totest', + testmethod='test_transforms'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type's name) maps to a list of transform + classes and list of tests. Each test is a list: input, expected + output, optional modifier. The optional third entry, a behavior + modifier, can be 0 (temporarily disable this test) or 1 (run this test + under the pdb debugger). Tests should be self-documenting and not + require external comments. + """ + for name, (transforms, cases) in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + runInDebugger = 0 + if len(case)==3: + if case[2]: + runInDebugger = 1 + else: + continue + self.addTestCase( + TransformTestCase, testmethod, + transforms=transforms, parser=self.parser, + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + runInDebugger=runInDebugger) + + +class TransformTestCase(CustomTestCase): + + """ + Output checker for the transform. + + Should probably be called TransformOutputChecker, but I can deal with + that later when/if someone comes up with a category of transform test + cases that have nothing to do with the input and output of the transform. + """ + + def __init__(self, *args, **kwargs): + self.transforms = kwargs['transforms'] + """List of transforms to perform for this test case.""" + + self.parser = kwargs['parser'] + """Input parser for this test case.""" + + del kwargs['transforms'], kwargs['parser'] # only wanted here + CustomTestCase.__init__(self, *args, **kwargs) + + def test_transforms(self): + if self.runInDebugger: + pdb.set_trace() + doctree = utils.newdocument(warninglevel=5, errorlevel=5, + debug=UnitTestFolder.debug) + self.parser.parse(self.input, doctree) + for transformClass in (self.transforms + universal.test_transforms): + transformClass(doctree).transform() + output = doctree.pformat() + self.compareOutput(self.input, output, self.expected) + + def test_transforms_verbosely(self): + if self.runInDebugger: + pdb.set_trace() + print '\n', self.id + print '-' * 70 + print self.input + doctree = utils.newdocument(warninglevel=5, errorlevel=5, + debug=UnitTestFolder.debug) + self.parser.parse(self.input, doctree) + print '-' * 70 + print doctree.pformat() + for transformClass in self.transforms: + transformClass(doctree).transform() + output = doctree.pformat() + print '-' * 70 + print output + self.compareOutput(self.input, output, self.expected) + + +class ParserTestSuite(CustomTestSuite): + + """ + A collection of ParserTestCases. + + A ParserTestSuite instance manufactures ParserTestCases, + keeps track of them, and provides a shared test fixture (a-la + setUp and tearDown). + """ + + def generateTests(self, dict, dictname='totest'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type name) maps to a list of tests. Each + test is a list: input, expected output, optional modifier. The + optional third entry, a behavior modifier, can be 0 (temporarily + disable this test) or 1 (run this test under the pdb debugger). Tests + should be self-documenting and not require external comments. + """ + for name, cases in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + runInDebugger = 0 + if len(case)==3: + if case[2]: + runInDebugger = 1 + else: + continue + self.addTestCase( + ParserTestCase, 'test_parser', + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + runInDebugger=runInDebugger) + + +class ParserTestCase(CustomTestCase): + + """ + Output checker for the parser. + + Should probably be called ParserOutputChecker, but I can deal with + that later when/if someone comes up with a category of parser test + cases that have nothing to do with the input and output of the parser. + """ + + parser = rst.Parser() + """Parser shared by all ParserTestCases.""" + + def test_parser(self): + if self.runInDebugger: + pdb.set_trace() + document = utils.newdocument(warninglevel=5, errorlevel=5, + debug=UnitTestFolder.debug) + self.parser.parse(self.input, document) + output = document.pformat() + self.compareOutput(self.input, output, self.expected) + + +class TableParserTestSuite(CustomTestSuite): + + """ + A collection of TableParserTestCases. + + A TableParserTestSuite instance manufactures TableParserTestCases, + keeps track of them, and provides a shared test fixture (a-la + setUp and tearDown). + """ + + def generateTests(self, dict, dictname='totest'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type name) maps to a list of tests. Each + test is a list: an input table, expected output from parsegrid(), + expected output from parse(), optional modifier. The optional fourth + entry, a behavior modifier, can be 0 (temporarily disable this test) + or 1 (run this test under the pdb debugger). Tests should be + self-documenting and not require external comments. + """ + for name, cases in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + runInDebugger = 0 + if len(case) == 4: + if case[3]: + runInDebugger = 1 + else: + continue + self.addTestCase(TableParserTestCase, 'test_parsegrid', + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + runInDebugger=runInDebugger) + self.addTestCase(TableParserTestCase, 'test_parse', + input=case[0], expected=case[2], + id='%s[%r][%s]' % (dictname, name, casenum), + runInDebugger=runInDebugger) + + +class TableParserTestCase(CustomTestCase): + + parser = tableparser.TableParser() + + def test_parsegrid(self): + self.parser.setup(string2lines(self.input)) + try: + self.parser.findheadbodysep() + self.parser.parsegrid() + output = self.parser.cells + except Exception, details: + output = '%s: %s' % (details.__class__.__name__, details) + self.compareOutput(self.input, pformat(output) + '\n', + pformat(self.expected) + '\n') + + def test_parse(self): + try: + output = self.parser.parse(string2lines(self.input)) + except Exception, details: + output = '%s: %s' % (details.__class__.__name__, details) + self.compareOutput(self.input, pformat(output) + '\n', + pformat(self.expected) + '\n') -- cgit v1.2.1 From 3f71e18c121b62a8243a7731fddc729e104c9bef Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 25 Apr 2002 03:31:33 +0000 Subject: Support for RFC-2822 testing. Updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@38 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 62 ++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 766eafde6..6fb710cd0 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -28,7 +28,7 @@ Exports the following: """ __docformat__ = 'reStructuredText' -import UnitTestFolder +import package_unittest import sys, os, unittest, difflib, inspect, os, sys from pprint import pformat import docutils @@ -148,6 +148,9 @@ class CustomTestCase(unittest.TestCase): """ return '%s; %s' % (self.id, unittest.TestCase.__str__(self)) + def __repr__(self): + return "<%s %s>" % (self.id, unittest.TestCase.__repr__(self)) + def compareOutput(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" try: @@ -230,7 +233,7 @@ class TransformTestCase(CustomTestCase): if self.runInDebugger: pdb.set_trace() doctree = utils.newdocument(warninglevel=5, errorlevel=5, - debug=UnitTestFolder.debug) + debug=package_unittest.debug) self.parser.parse(self.input, doctree) for transformClass in (self.transforms + universal.test_transforms): transformClass(doctree).transform() @@ -244,7 +247,7 @@ class TransformTestCase(CustomTestCase): print '-' * 70 print self.input doctree = utils.newdocument(warninglevel=5, errorlevel=5, - debug=UnitTestFolder.debug) + debug=package_unittest.debug) self.parser.parse(self.input, doctree) print '-' * 70 print doctree.pformat() @@ -256,6 +259,29 @@ class TransformTestCase(CustomTestCase): self.compareOutput(self.input, output, self.expected) +class ParserTestCase(CustomTestCase): + + """ + Output checker for the parser. + + Should probably be called ParserOutputChecker, but I can deal with + that later when/if someone comes up with a category of parser test + cases that have nothing to do with the input and output of the parser. + """ + + parser = rst.Parser() + """Parser shared by all ParserTestCases.""" + + def test_parser(self): + if self.runInDebugger: + pdb.set_trace() + document = utils.newdocument(warninglevel=5, errorlevel=5, + debug=package_unittest.debug) + self.parser.parse(self.input, document) + output = document.pformat() + self.compareOutput(self.input, output, self.expected) + + class ParserTestSuite(CustomTestSuite): """ @@ -266,6 +292,8 @@ class ParserTestSuite(CustomTestSuite): setUp and tearDown). """ + test_case_class = ParserTestCase + def generateTests(self, dict, dictname='totest'): """ Stock the suite with test cases generated from a test data dictionary. @@ -286,33 +314,25 @@ class ParserTestSuite(CustomTestSuite): else: continue self.addTestCase( - ParserTestCase, 'test_parser', + self.test_case_class, 'test_parser', input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), runInDebugger=runInDebugger) -class ParserTestCase(CustomTestCase): +class RFC2822ParserTestCase(ParserTestCase): - """ - Output checker for the parser. + """RFC2822-specific parser test case.""" - Should probably be called ParserOutputChecker, but I can deal with - that later when/if someone comes up with a category of parser test - cases that have nothing to do with the input and output of the parser. - """ + parser = rst.Parser(rfc2822=1) + """Parser shared by all RFC2822ParserTestCases.""" - parser = rst.Parser() - """Parser shared by all ParserTestCases.""" - def test_parser(self): - if self.runInDebugger: - pdb.set_trace() - document = utils.newdocument(warninglevel=5, errorlevel=5, - debug=UnitTestFolder.debug) - self.parser.parse(self.input, document) - output = document.pformat() - self.compareOutput(self.input, output, self.expected) +class RFC2822ParserTestSuite(ParserTestSuite): + + """A collection of RFC2822ParserTestCases.""" + + test_case_class = RFC2822ParserTestCase class TableParserTestSuite(CustomTestSuite): -- cgit v1.2.1 From b93e27dd4509f9f73df3568cf8a4ee2cd4dbf010 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 5 May 2002 15:42:03 +0000 Subject: Support for PEP extensions to reStructuredText. General improvements. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@88 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 54 ++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6fb710cd0..3b883d49b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -36,6 +36,7 @@ from docutils import statemachine, nodes, urischemes, utils, transforms from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages +from docutils.readers import pep from docutils.statemachine import string2lines try: @@ -229,15 +230,19 @@ class TransformTestCase(CustomTestCase): del kwargs['transforms'], kwargs['parser'] # only wanted here CustomTestCase.__init__(self, *args, **kwargs) + def supports(self, format): + return 1 + def test_transforms(self): if self.runInDebugger: pdb.set_trace() - doctree = utils.newdocument(warninglevel=5, errorlevel=5, - debug=package_unittest.debug) - self.parser.parse(self.input, doctree) + document = utils.new_document(warning_level=1, error_level=5, + debug=package_unittest.debug, + stream=DevNull()) + self.parser.parse(self.input, document) for transformClass in (self.transforms + universal.test_transforms): - transformClass(doctree).transform() - output = doctree.pformat() + transformClass(document, self).transform() + output = document.pformat() self.compareOutput(self.input, output, self.expected) def test_transforms_verbosely(self): @@ -246,14 +251,15 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - doctree = utils.newdocument(warninglevel=5, errorlevel=5, - debug=package_unittest.debug) - self.parser.parse(self.input, doctree) + document = utils.new_document(warning_level=1, error_level=5, + debug=package_unittest.debug, + stream=DevNull()) + self.parser.parse(self.input, document) print '-' * 70 - print doctree.pformat() + print document.pformat() for transformClass in self.transforms: - transformClass(doctree).transform() - output = doctree.pformat() + transformClass(document).transform() + output = document.pformat() print '-' * 70 print output self.compareOutput(self.input, output, self.expected) @@ -275,8 +281,8 @@ class ParserTestCase(CustomTestCase): def test_parser(self): if self.runInDebugger: pdb.set_trace() - document = utils.newdocument(warninglevel=5, errorlevel=5, - debug=package_unittest.debug) + document = utils.new_document(warning_level=5, error_level=5, + debug=package_unittest.debug) self.parser.parse(self.input, document) output = document.pformat() self.compareOutput(self.input, output, self.expected) @@ -320,19 +326,19 @@ class ParserTestSuite(CustomTestSuite): runInDebugger=runInDebugger) -class RFC2822ParserTestCase(ParserTestCase): +class PEPParserTestCase(ParserTestCase): - """RFC2822-specific parser test case.""" + """PEP-specific parser test case.""" - parser = rst.Parser(rfc2822=1) - """Parser shared by all RFC2822ParserTestCases.""" + parser = rst.Parser(rfc2822=1, inliner=pep.Inliner()) + """Parser shared by all PEPParserTestCases.""" -class RFC2822ParserTestSuite(ParserTestSuite): +class PEPParserTestSuite(ParserTestSuite): - """A collection of RFC2822ParserTestCases.""" + """A collection of PEPParserTestCases.""" - test_case_class = RFC2822ParserTestCase + test_case_class = PEPParserTestCase class TableParserTestSuite(CustomTestSuite): @@ -397,3 +403,11 @@ class TableParserTestCase(CustomTestCase): output = '%s: %s' % (details.__class__.__name__, details) self.compareOutput(self.input, pformat(output) + '\n', pformat(self.expected) + '\n') + + +class DevNull: + + """Output sink.""" + + def write(self, string): + pass -- cgit v1.2.1 From 060ae1cc18c6362cbfc28c6ee525ff32616ad1fb Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 24 May 2002 03:08:09 +0000 Subject: - Changed names of Reporter's thresholds: warning_level -> report_level; error_level -> halt_level. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@143 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 3b883d49b..43e5cc4af 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -236,7 +236,7 @@ class TransformTestCase(CustomTestCase): def test_transforms(self): if self.runInDebugger: pdb.set_trace() - document = utils.new_document(warning_level=1, error_level=5, + document = utils.new_document(report_level=1, halt_level=5, debug=package_unittest.debug, stream=DevNull()) self.parser.parse(self.input, document) @@ -251,7 +251,7 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - document = utils.new_document(warning_level=1, error_level=5, + document = utils.new_document(report_level=1, halt_level=5, debug=package_unittest.debug, stream=DevNull()) self.parser.parse(self.input, document) @@ -281,7 +281,7 @@ class ParserTestCase(CustomTestCase): def test_parser(self): if self.runInDebugger: pdb.set_trace() - document = utils.new_document(warning_level=5, error_level=5, + document = utils.new_document(report_level=5, halt_level=5, debug=package_unittest.debug) self.parser.parse(self.input, document) output = document.pformat() -- cgit v1.2.1 From 67b87f5d516ec079f2465fbbc7301d83f42d7683 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 30 May 2002 02:18:16 +0000 Subject: - Added support for an option values object which carries default settings and overrides (from command-line options and library use). - Cleaned up imports: no more relative package imports or comma-separated lists of top-level modules. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@155 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 43e5cc4af..76e3a36e0 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -28,11 +28,15 @@ Exports the following: """ __docformat__ = 'reStructuredText' -import package_unittest -import sys, os, unittest, difflib, inspect, os, sys +import sys +import os +import unittest +import difflib +import inspect from pprint import pformat +import package_unittest import docutils -from docutils import statemachine, nodes, urischemes, utils, transforms +from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages @@ -45,6 +49,14 @@ except: import pdb +class DevNull: + + """Output sink.""" + + def write(self, string): + pass + + class CustomTestSuite(unittest.TestSuite): """ @@ -220,6 +232,12 @@ class TransformTestCase(CustomTestCase): cases that have nothing to do with the input and output of the transform. """ + options = frontend.OptionParser().get_default_values() + options.report_level = 1 + options.halt_level = 5 + options.debug = package_unittest.debug + options.warning_stream = DevNull() + def __init__(self, *args, **kwargs): self.transforms = kwargs['transforms'] """List of transforms to perform for this test case.""" @@ -236,9 +254,7 @@ class TransformTestCase(CustomTestCase): def test_transforms(self): if self.runInDebugger: pdb.set_trace() - document = utils.new_document(report_level=1, halt_level=5, - debug=package_unittest.debug, - stream=DevNull()) + document = utils.new_document(self.options) self.parser.parse(self.input, document) for transformClass in (self.transforms + universal.test_transforms): transformClass(document, self).transform() @@ -251,9 +267,7 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - document = utils.new_document(report_level=1, halt_level=5, - debug=package_unittest.debug, - stream=DevNull()) + document = utils.new_document(self.options) self.parser.parse(self.input, document) print '-' * 70 print document.pformat() @@ -278,11 +292,15 @@ class ParserTestCase(CustomTestCase): parser = rst.Parser() """Parser shared by all ParserTestCases.""" + options = frontend.OptionParser().get_default_values() + options.report_level = 5 + options.halt_level = 5 + options.debug = package_unittest.debug + def test_parser(self): if self.runInDebugger: pdb.set_trace() - document = utils.new_document(report_level=5, halt_level=5, - debug=package_unittest.debug) + document = utils.new_document(self.options) self.parser.parse(self.input, document) output = document.pformat() self.compareOutput(self.input, output, self.expected) @@ -403,11 +421,3 @@ class TableParserTestCase(CustomTestCase): output = '%s: %s' % (details.__class__.__name__, details) self.compareOutput(self.input, pformat(output) + '\n', pformat(self.expected) + '\n') - - -class DevNull: - - """Output sink.""" - - def write(self, string): - pass -- cgit v1.2.1 From a6e799cb8524fc622f92e3a7d3c185bf0532f0ec Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 18 Jul 2002 01:38:19 +0000 Subject: - Added support for simple tables. - Refactored naming. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@308 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 178 +++++++++++++++++++++++++++----------------- 1 file changed, 111 insertions(+), 67 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 76e3a36e0..00afa10f5 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -23,8 +23,10 @@ Exports the following: - `CustomTestCase` - `ParserTestSuite` - `ParserTestCase` - - `TableParserTestSuite` - - `TableParserTestCase` + - `GridTableParserTestSuite` + - `GridTableParserTestCase` + - `SimpleTableParserTestSuite` + - `SimpleTableParserTestCase` """ __docformat__ = 'reStructuredText' @@ -68,7 +70,7 @@ class CustomTestSuite(unittest.TestSuite): """Identifier for the TestSuite. Prepended to the TestCase identifiers to make identification easier.""" - nextTestCaseId = 0 + next_test_case_id = 0 """The next identifier to use for non-identified test cases.""" def __init__(self, tests=(), id=None): @@ -97,8 +99,8 @@ class CustomTestSuite(unittest.TestSuite): else: self.id = id - def addTestCase(self, testCaseClass, methodName, input, expected, - id=None, runInDebugger=0, shortDescription=None, + def addTestCase(self, test_case_class, method_name, input, expected, + id=None, run_in_debugger=0, short_description=None, **kwargs): """ Create a custom TestCase in the CustomTestSuite. @@ -106,24 +108,24 @@ class CustomTestSuite(unittest.TestSuite): Arguments: - testCaseClass -- - methodName -- + test_case_class -- + method_name -- input -- input to the parser. expected -- expected output from the parser. id -- unique test identifier, used by the test framework. - runInDebugger -- if true, run this test under the pdb debugger. - shortDescription -- override to default test description. + run_in_debugger -- if true, run this test under the pdb debugger. + short_description -- override to default test description. """ if id is None: # generate id if required - id = self.nextTestCaseId - self.nextTestCaseId += 1 + id = self.next_test_case_id + self.next_test_case_id += 1 # test identifier will become suiteid.testid tcid = '%s: %s' % (self.id, id) # generate and add test case - tc = testCaseClass(methodName, input, expected, tcid, - runInDebugger=runInDebugger, - shortDescription=shortDescription, - **kwargs) + tc = test_case_class(method_name, input, expected, tcid, + run_in_debugger=run_in_debugger, + short_description=short_description, + **kwargs) self.addTest(tc) return tc @@ -133,26 +135,26 @@ class CustomTestCase(unittest.TestCase): compare = difflib.Differ().compare """Comparison method shared by all subclasses.""" - def __init__(self, methodName, input, expected, id, - runInDebugger=0, shortDescription=None): + def __init__(self, method_name, input, expected, id, + run_in_debugger=0, short_description=None): """ Initialise the CustomTestCase. Arguments: - methodName -- name of test method to run. + method_name -- name of test method to run. input -- input to the parser. expected -- expected output from the parser. id -- unique test identifier, used by the test framework. - runInDebugger -- if true, run this test under the pdb debugger. - shortDescription -- override to default test description. + run_in_debugger -- if true, run this test under the pdb debugger. + short_description -- override to default test description. """ self.id = id self.input = input self.expected = expected - self.runInDebugger = runInDebugger + self.run_in_debugger = run_in_debugger # Ring your mother. - unittest.TestCase.__init__(self, methodName) + unittest.TestCase.__init__(self, method_name) def __str__(self): """ @@ -164,7 +166,7 @@ class CustomTestCase(unittest.TestCase): def __repr__(self): return "<%s %s>" % (self.id, unittest.TestCase.__repr__(self)) - def compareOutput(self, input, output, expected): + def compare_output(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" try: self.assertEquals('\n' + output, '\n' + expected) @@ -208,10 +210,10 @@ class TransformTestSuite(CustomTestSuite): for name, (transforms, cases) in dict.items(): for casenum in range(len(cases)): case = cases[casenum] - runInDebugger = 0 + run_in_debugger = 0 if len(case)==3: if case[2]: - runInDebugger = 1 + run_in_debugger = 1 else: continue self.addTestCase( @@ -219,7 +221,7 @@ class TransformTestSuite(CustomTestSuite): transforms=transforms, parser=self.parser, input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), - runInDebugger=runInDebugger) + run_in_debugger=run_in_debugger) class TransformTestCase(CustomTestCase): @@ -252,17 +254,17 @@ class TransformTestCase(CustomTestCase): return 1 def test_transforms(self): - if self.runInDebugger: + if self.run_in_debugger: pdb.set_trace() document = utils.new_document(self.options) self.parser.parse(self.input, document) for transformClass in (self.transforms + universal.test_transforms): transformClass(document, self).transform() output = document.pformat() - self.compareOutput(self.input, output, self.expected) + self.compare_output(self.input, output, self.expected) def test_transforms_verbosely(self): - if self.runInDebugger: + if self.run_in_debugger: pdb.set_trace() print '\n', self.id print '-' * 70 @@ -276,7 +278,7 @@ class TransformTestCase(CustomTestCase): output = document.pformat() print '-' * 70 print output - self.compareOutput(self.input, output, self.expected) + self.compare_output(self.input, output, self.expected) class ParserTestCase(CustomTestCase): @@ -298,12 +300,12 @@ class ParserTestCase(CustomTestCase): options.debug = package_unittest.debug def test_parser(self): - if self.runInDebugger: + if self.run_in_debugger: pdb.set_trace() document = utils.new_document(self.options) self.parser.parse(self.input, document) output = document.pformat() - self.compareOutput(self.input, output, self.expected) + self.compare_output(self.input, output, self.expected) class ParserTestSuite(CustomTestSuite): @@ -331,17 +333,17 @@ class ParserTestSuite(CustomTestSuite): for name, cases in dict.items(): for casenum in range(len(cases)): case = cases[casenum] - runInDebugger = 0 + run_in_debugger = 0 if len(case)==3: if case[2]: - runInDebugger = 1 + run_in_debugger = 1 else: continue self.addTestCase( self.test_case_class, 'test_parser', input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), - runInDebugger=runInDebugger) + run_in_debugger=run_in_debugger) class PEPParserTestCase(ParserTestCase): @@ -359,22 +361,48 @@ class PEPParserTestSuite(ParserTestSuite): test_case_class = PEPParserTestCase -class TableParserTestSuite(CustomTestSuite): +class GridTableParserTestCase(CustomTestCase): + + parser = tableparser.GridTableParser() + + def test_parse_table(self): + self.parser.setup(string2lines(self.input)) + try: + self.parser.find_head_body_sep() + self.parser.parse_table() + output = self.parser.cells + except Exception, details: + output = '%s: %s' % (details.__class__.__name__, details) + self.compare_output(self.input, pformat(output) + '\n', + pformat(self.expected) + '\n') + + def test_parse(self): + try: + output = self.parser.parse(string2lines(self.input)) + except Exception, details: + output = '%s: %s' % (details.__class__.__name__, details) + self.compare_output(self.input, pformat(output) + '\n', + pformat(self.expected) + '\n') + + +class GridTableParserTestSuite(CustomTestSuite): """ - A collection of TableParserTestCases. + A collection of GridTableParserTestCases. - A TableParserTestSuite instance manufactures TableParserTestCases, - keeps track of them, and provides a shared test fixture (a-la - setUp and tearDown). + A GridTableParserTestSuite instance manufactures GridTableParserTestCases, + keeps track of them, and provides a shared test fixture (a-la setUp and + tearDown). """ + test_case_class = GridTableParserTestCase + def generateTests(self, dict, dictname='totest'): """ Stock the suite with test cases generated from a test data dictionary. Each dictionary key (test type name) maps to a list of tests. Each - test is a list: an input table, expected output from parsegrid(), + test is a list: an input table, expected output from parse_table(), expected output from parse(), optional modifier. The optional fourth entry, a behavior modifier, can be 0 (temporarily disable this test) or 1 (run this test under the pdb debugger). Tests should be @@ -383,41 +411,57 @@ class TableParserTestSuite(CustomTestSuite): for name, cases in dict.items(): for casenum in range(len(cases)): case = cases[casenum] - runInDebugger = 0 + run_in_debugger = 0 if len(case) == 4: - if case[3]: - runInDebugger = 1 + if case[-1]: + run_in_debugger = 1 else: continue - self.addTestCase(TableParserTestCase, 'test_parsegrid', + self.addTestCase(self.test_case_class, 'test_parse_table', input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), - runInDebugger=runInDebugger) - self.addTestCase(TableParserTestCase, 'test_parse', + run_in_debugger=run_in_debugger) + self.addTestCase(self.test_case_class, 'test_parse', input=case[0], expected=case[2], id='%s[%r][%s]' % (dictname, name, casenum), - runInDebugger=runInDebugger) + run_in_debugger=run_in_debugger) -class TableParserTestCase(CustomTestCase): +class SimpleTableParserTestCase(GridTableParserTestCase): - parser = tableparser.TableParser() + parser = tableparser.SimpleTableParser() - def test_parsegrid(self): - self.parser.setup(string2lines(self.input)) - try: - self.parser.findheadbodysep() - self.parser.parsegrid() - output = self.parser.cells - except Exception, details: - output = '%s: %s' % (details.__class__.__name__, details) - self.compareOutput(self.input, pformat(output) + '\n', - pformat(self.expected) + '\n') - def test_parse(self): - try: - output = self.parser.parse(string2lines(self.input)) - except Exception, details: - output = '%s: %s' % (details.__class__.__name__, details) - self.compareOutput(self.input, pformat(output) + '\n', - pformat(self.expected) + '\n') +class SimpleTableParserTestSuite(CustomTestSuite): + + """ + A collection of SimpleTableParserTestCases. + """ + + test_case_class = SimpleTableParserTestCase + + def generateTests(self, dict, dictname='totest'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type name) maps to a list of tests. Each + test is a list: an input table, expected output from parse(), optional + modifier. The optional third entry, a behavior modifier, can be 0 + (temporarily disable this test) or 1 (run this test under the pdb + debugger). Tests should be self-documenting and not require external + comments. + """ + for name, cases in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + run_in_debugger = 0 + if len(case) == 3: + if case[-1]: + run_in_debugger = 1 + else: + continue + self.addTestCase(self.test_case_class, 'test_parse', + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + run_in_debugger=run_in_debugger) + -- cgit v1.2.1 From b33b5e161850ae6ffb6fc60e47f7b9e57c4d748c Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 10 Aug 2002 22:59:42 +0000 Subject: Fixed lingering bugs; now alltests.py can be run from anywhere, and individual test cases can be run from their own directories. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@499 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 00afa10f5..ca825ded0 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -83,11 +83,16 @@ class CustomTestSuite(unittest.TestSuite): """ unittest.TestSuite.__init__(self, tests) if id is None: + mypath = os.path.abspath( + sys.modules[CustomTestSuite.__module__].__file__) outerframes = inspect.getouterframes(inspect.currentframe()) - mypath = outerframes[0][1] for outerframe in outerframes[1:]: if outerframe[3] != '__init__': callerpath = outerframe[1] + if callerpath is None: + # It happens sometimes. Why is a mystery. + callerpath = os.getcwd() + callerpath = os.path.abspath(callerpath) break mydir, myname = os.path.split(mypath) if not mydir: -- cgit v1.2.1 From 95b63698e4c2c83da12a7b2d72672b09cb8468e0 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 13 Aug 2002 01:01:01 +0000 Subject: Support for Unicode output. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@511 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index ca825ded0..923336edc 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -36,6 +36,7 @@ import unittest import difflib import inspect from pprint import pformat +from types import UnicodeType import package_unittest import docutils from docutils import frontend, nodes, statemachine, urischemes, utils @@ -173,6 +174,12 @@ class CustomTestCase(unittest.TestCase): def compare_output(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" + if type(input) == UnicodeType: + input = input.encode('raw_unicode_escape') + if type(output) == UnicodeType: + output = output.encode('raw_unicode_escape') + if type(expected) == UnicodeType: + expected = expected.encode('raw_unicode_escape') try: self.assertEquals('\n' + output, '\n' + expected) except AssertionError: -- cgit v1.2.1 From 13ed20d392cc6c5e727344dad0c3aca8cea125f1 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 21 Aug 2002 03:00:07 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@572 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 923336edc..00ebefe61 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -268,7 +268,7 @@ class TransformTestCase(CustomTestCase): def test_transforms(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document(self.options) + document = utils.new_document('test data', self.options) self.parser.parse(self.input, document) for transformClass in (self.transforms + universal.test_transforms): transformClass(document, self).transform() @@ -281,7 +281,7 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - document = utils.new_document(self.options) + document = utils.new_document('test data', self.options) self.parser.parse(self.input, document) print '-' * 70 print document.pformat() @@ -314,7 +314,7 @@ class ParserTestCase(CustomTestCase): def test_parser(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document(self.options) + document = utils.new_document('test data', self.options) self.parser.parse(self.input, document) output = document.pformat() self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 7ec8f57a8b921e2507569a0107d49bd35a210187 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 23 Aug 2002 01:57:09 +0000 Subject: docstring git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@581 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 00ebefe61..5f97a7ac2 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -21,12 +21,17 @@ Exports the following: :Classes: - `CustomTestSuite` - `CustomTestCase` + - `TransformTestSuite` + - `TransformTestCase` - `ParserTestSuite` - `ParserTestCase` + - `PEPParserTestSuite` + - `PEPParserTestCase` - `GridTableParserTestSuite` - `GridTableParserTestCase` - `SimpleTableParserTestSuite` - `SimpleTableParserTestCase` + - `DevNull` (output sink) """ __docformat__ = 'reStructuredText' -- cgit v1.2.1 From c1554e0cae13b502620d286b2d7519c7f4c53909 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 5 Sep 2002 03:15:16 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@631 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5f97a7ac2..42298c981 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -274,7 +274,10 @@ class TransformTestCase(CustomTestCase): if self.run_in_debugger: pdb.set_trace() document = utils.new_document('test data', self.options) + document.reporter.attach_observer(document.note_parse_message) self.parser.parse(self.input, document) + document.reporter.detach_observer(document.note_parse_message) + document.reporter.attach_observer(document.note_transform_message) for transformClass in (self.transforms + universal.test_transforms): transformClass(document, self).transform() output = document.pformat() -- cgit v1.2.1 From 49373e9eff9b650bd989452f2067cf2b78a5cebe Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 7 Sep 2002 02:42:09 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@653 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 42298c981..4f1a4c76b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -251,7 +251,7 @@ class TransformTestCase(CustomTestCase): cases that have nothing to do with the input and output of the transform. """ - options = frontend.OptionParser().get_default_values() + options = frontend.OptionParser(components=(rst.Parser,)).get_default_values() options.report_level = 1 options.halt_level = 5 options.debug = package_unittest.debug @@ -314,7 +314,7 @@ class ParserTestCase(CustomTestCase): parser = rst.Parser() """Parser shared by all ParserTestCases.""" - options = frontend.OptionParser().get_default_values() + options = frontend.OptionParser(components=(parser,)).get_default_values() options.report_level = 5 options.halt_level = 5 options.debug = package_unittest.debug @@ -373,6 +373,12 @@ class PEPParserTestCase(ParserTestCase): parser = rst.Parser(rfc2822=1, inliner=pep.Inliner()) """Parser shared by all PEPParserTestCases.""" + option_parser = frontend.OptionParser(components=(parser, pep.Reader)) + options = option_parser.get_default_values() + options.report_level = 5 + options.halt_level = 5 + options.debug = package_unittest.debug + class PEPParserTestSuite(ParserTestSuite): -- cgit v1.2.1 From efdd39867964b92520a58c6796658895e412c441 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 9 Oct 2002 00:51:53 +0000 Subject: changed docstring field lists into comments git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@778 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 4f1a4c76b..6e9c804e5 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -1,12 +1,10 @@ -#! /usr/bin/env python +# Authors: David Goodger; Garth Kidd +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. """ -:Authors: David Goodger; Garth Kidd -:Contact: goodger@users.sourceforge.net -:Revision: $Revision$ -:Date: $Date$ -:Copyright: This module has been placed in the public domain. - Exports the following: :Modules: -- cgit v1.2.1 From afeedfb343c2904e9357997d2a50f8f3cabb2568 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 18 Oct 2002 04:55:21 +0000 Subject: Refactored names (options -> settings; .transform() -> .apply(); etc.); updated. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@825 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6e9c804e5..7d7252184 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -249,11 +249,12 @@ class TransformTestCase(CustomTestCase): cases that have nothing to do with the input and output of the transform. """ - options = frontend.OptionParser(components=(rst.Parser,)).get_default_values() - options.report_level = 1 - options.halt_level = 5 - options.debug = package_unittest.debug - options.warning_stream = DevNull() + option_parser = frontend.OptionParser(components=(rst.Parser,)) + settings = option_parser.get_default_values() + settings.report_level = 1 + settings.halt_level = 5 + settings.debug = package_unittest.debug + settings.warning_stream = DevNull() def __init__(self, *args, **kwargs): self.transforms = kwargs['transforms'] @@ -271,13 +272,13 @@ class TransformTestCase(CustomTestCase): def test_transforms(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document('test data', self.options) + document = utils.new_document('test data', self.settings) document.reporter.attach_observer(document.note_parse_message) self.parser.parse(self.input, document) document.reporter.detach_observer(document.note_parse_message) document.reporter.attach_observer(document.note_transform_message) for transformClass in (self.transforms + universal.test_transforms): - transformClass(document, self).transform() + transformClass(document, self).apply() output = document.pformat() self.compare_output(self.input, output, self.expected) @@ -287,12 +288,12 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - document = utils.new_document('test data', self.options) + document = utils.new_document('test data', self.settings) self.parser.parse(self.input, document) print '-' * 70 print document.pformat() for transformClass in self.transforms: - transformClass(document).transform() + transformClass(document).apply() output = document.pformat() print '-' * 70 print output @@ -312,15 +313,16 @@ class ParserTestCase(CustomTestCase): parser = rst.Parser() """Parser shared by all ParserTestCases.""" - options = frontend.OptionParser(components=(parser,)).get_default_values() - options.report_level = 5 - options.halt_level = 5 - options.debug = package_unittest.debug + option_parser = frontend.OptionParser(components=(parser,)) + settings = option_parser.get_default_values() + settings.report_level = 5 + settings.halt_level = 5 + settings.debug = package_unittest.debug def test_parser(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document('test data', self.options) + document = utils.new_document('test data', self.settings) self.parser.parse(self.input, document) output = document.pformat() self.compare_output(self.input, output, self.expected) @@ -372,10 +374,10 @@ class PEPParserTestCase(ParserTestCase): """Parser shared by all PEPParserTestCases.""" option_parser = frontend.OptionParser(components=(parser, pep.Reader)) - options = option_parser.get_default_values() - options.report_level = 5 - options.halt_level = 5 - options.debug = package_unittest.debug + settings = option_parser.get_default_values() + settings.report_level = 5 + settings.halt_level = 5 + settings.debug = package_unittest.debug class PEPParserTestSuite(ParserTestSuite): -- cgit v1.2.1 From 1ecb8a1bf993d41cb606a26ca5168809bd75412b Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 24 Oct 2002 00:51:10 +0000 Subject: Completed transform reform; updated. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@853 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 7d7252184..822a45946 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -273,12 +273,13 @@ class TransformTestCase(CustomTestCase): if self.run_in_debugger: pdb.set_trace() document = utils.new_document('test data', self.settings) - document.reporter.attach_observer(document.note_parse_message) self.parser.parse(self.input, document) - document.reporter.detach_observer(document.note_parse_message) - document.reporter.attach_observer(document.note_transform_message) - for transformClass in (self.transforms + universal.test_transforms): - transformClass(document, self).apply() + # Don't do a ``populate_from_components()`` because that would + # enable the Transformer's default transforms. + document.transformer.add_transforms(self.transforms) + document.transformer.add_transform(universal.TestMessages) + document.transformer.components['writer'] = self + document.transformer.apply_transforms() output = document.pformat() self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 673c882e62ff706d8706218bfe74c203c46c87f5 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 28 Nov 2002 03:45:11 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@983 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 822a45946..f33086be9 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -46,7 +46,7 @@ from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages -from docutils.readers import pep +from docutils.readers import standalone, pep, pysource from docutils.statemachine import string2lines try: -- cgit v1.2.1 From bafaf9960d397e6b897ed2a20fe8460a2cdd91db Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 5 Dec 2002 02:34:13 +0000 Subject: added support for Python module parser tests (readers/python/moduleparser.py) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@992 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index f33086be9..e7eedfee5 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -46,7 +46,8 @@ from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages -from docutils.readers import standalone, pep, pysource +from docutils.readers import standalone, pep, python +from docutils.readers.python import moduleparser from docutils.statemachine import string2lines try: @@ -492,3 +493,45 @@ class SimpleTableParserTestSuite(CustomTestSuite): id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) + +class PythonModuleParserTestSuite(CustomTestSuite): + + """ + A collection of PythonModuleParserTestCase. + """ + + def generateTests(self, dict, dictname='totest', + testmethod='test_parser'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type's name) maps to a list of tests. Each + test is a list: input, expected output, optional modifier. The + optional third entry, a behavior modifier, can be 0 (temporarily + disable this test) or 1 (run this test under the pdb debugger). Tests + should be self-documenting and not require external comments. + """ + for name, cases in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + run_in_debugger = 0 + if len(case)==3: + if case[2]: + run_in_debugger = 1 + else: + continue + self.addTestCase( + PythonModuleParserTestCase, testmethod, + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + run_in_debugger=run_in_debugger) + + +class PythonModuleParserTestCase(CustomTestCase): + + def test_parser(self): + if self.run_in_debugger: + pdb.set_trace() + module = moduleparser.parse_module(self.input, 'test data') + output = str(module) + self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 64978d7d1302427544d2f18d32a6de535f52e15b Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 14 Dec 2002 01:39:06 +0000 Subject: support for changed exception text git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1021 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e7eedfee5..3280a97fa 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -535,3 +535,17 @@ class PythonModuleParserTestCase(CustomTestCase): module = moduleparser.parse_module(self.input, 'test data') output = str(module) self.compare_output(self.input, output, self.expected) + + def test_token_parser_rhs(self): + if self.run_in_debugger: + pdb.set_trace() + tr = moduleparser.TokenParser(self.input) + output = tr.rhs(1) + self.compare_output(self.input, output, self.expected) + + +def exception_args(code): + try: + exec(code) + except Exception, detail: + return detail.args -- cgit v1.2.1 From 9e16185c81fd4ddc140bf6ef1101033b73088efe Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 4 Jan 2003 00:18:34 +0000 Subject: Support for skipping tests. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1059 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 3280a97fa..b12e88773 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -47,15 +47,20 @@ from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages from docutils.readers import standalone, pep, python -from docutils.readers.python import moduleparser from docutils.statemachine import string2lines +try: + from docutils.readers.python import moduleparser +except: + moduleparser = None + try: import mypdb as pdb except: import pdb + class DevNull: """Output sink.""" @@ -194,6 +199,9 @@ class CustomTestCase(unittest.TestCase): output.splitlines(1))) raise + def skip_test(self): + print >>sys.stderr, '%s: Test skipped' % self + class TransformTestSuite(CustomTestSuite): @@ -500,6 +508,13 @@ class PythonModuleParserTestSuite(CustomTestSuite): A collection of PythonModuleParserTestCase. """ + if moduleparser: + test_methods = {'test_parser': 'test_parser', + 'test_token_parser_rhs': 'test_token_parser_rhs'} + else: + test_methods = {'test_parser': 'skip_test', + 'test_token_parser_rhs': 'skip_test'} + def generateTests(self, dict, dictname='totest', testmethod='test_parser'): """ @@ -521,7 +536,8 @@ class PythonModuleParserTestSuite(CustomTestSuite): else: continue self.addTestCase( - PythonModuleParserTestCase, testmethod, + PythonModuleParserTestCase, + self.test_methods[testmethod], input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) -- cgit v1.2.1 From 4ffd15469aa4a45615f7fdf9fd491f5a4ca68eea Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 4 Jan 2003 01:06:25 +0000 Subject: improved test skipping support git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1062 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 47 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index b12e88773..cc76c8281 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -502,18 +502,33 @@ class SimpleTableParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) +class PythonModuleParserTestCase(CustomTestCase): + + def test_parser(self): + if self.run_in_debugger: + pdb.set_trace() + module = moduleparser.parse_module(self.input, 'test data') + output = str(module) + self.compare_output(self.input, output, self.expected) + + def test_token_parser_rhs(self): + if self.run_in_debugger: + pdb.set_trace() + tr = moduleparser.TokenParser(self.input) + output = tr.rhs(1) + self.compare_output(self.input, output, self.expected) + + class PythonModuleParserTestSuite(CustomTestSuite): """ A collection of PythonModuleParserTestCase. """ - if moduleparser: - test_methods = {'test_parser': 'test_parser', - 'test_token_parser_rhs': 'test_token_parser_rhs'} - else: - test_methods = {'test_parser': 'skip_test', - 'test_token_parser_rhs': 'skip_test'} + if moduleparser is None: + PythonModuleParserTestCase.test_parser = CustomTestCase.skip_test + PythonModuleParserTestCase.test_token_parser_rhs = \ + CustomTestCase.skip_test def generateTests(self, dict, dictname='totest', testmethod='test_parser'): @@ -536,30 +551,12 @@ class PythonModuleParserTestSuite(CustomTestSuite): else: continue self.addTestCase( - PythonModuleParserTestCase, - self.test_methods[testmethod], + PythonModuleParserTestCase, testmethod, input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) -class PythonModuleParserTestCase(CustomTestCase): - - def test_parser(self): - if self.run_in_debugger: - pdb.set_trace() - module = moduleparser.parse_module(self.input, 'test data') - output = str(module) - self.compare_output(self.input, output, self.expected) - - def test_token_parser_rhs(self): - if self.run_in_debugger: - pdb.set_trace() - tr = moduleparser.TokenParser(self.input) - output = tr.rhs(1) - self.compare_output(self.input, output, self.expected) - - def exception_args(code): try: exec(code) -- cgit v1.2.1 From 82cbb844cb5b48c95dabcdc07c586d7232c69dd6 Mon Sep 17 00:00:00 2001 From: grubert Date: Mon, 3 Mar 2003 10:59:31 +0000 Subject: Add LatexPublishTest classes. Add writer latex writer test. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1211 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index cc76c8281..5dd192c25 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -29,6 +29,8 @@ Exports the following: - `GridTableParserTestCase` - `SimpleTableParserTestSuite` - `SimpleTableParserTestCase` + - 'LatexPublishTestSuite' + - 'LatexPublishTestCase' - `DevNull` (output sink) """ __docformat__ = 'reStructuredText' @@ -42,6 +44,7 @@ from pprint import pformat from types import UnicodeType import package_unittest import docutils +import docutils.core from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst @@ -556,6 +559,44 @@ class PythonModuleParserTestSuite(CustomTestSuite): id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) +class LatexPublishTestCase(CustomTestCase): + + """ + Test case for publish. + """ + + def test_publish(self): + if self.run_in_debugger: + pdb.set_trace() + output = docutils.core.publish_string(source=self.input, source_path=None, + destination_path=None, + reader=None, reader_name='standalone', + parser=None, parser_name='restructuredtext', + writer=None, writer_name='latex', + settings=None, settings_spec=None, settings_overrides=None) + self.compare_output(self.input, output, self.expected) + +class LatexPublishTestSuite(CustomTestSuite): + + def __init__(self): + CustomTestSuite.__init__(self) + + def generateTests(self, dict, dictname='totest'): + for name, cases in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + run_in_debugger = 0 + if len(case)==3: + if case[2]: + run_in_debugger = 1 + else: + continue + self.addTestCase( + LatexPublishTestCase, 'test_publish', + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + run_in_debugger=run_in_debugger) + def exception_args(code): try: -- cgit v1.2.1 From 3a6bd3b4b4d4f73b6cdc97ac65e638827523cd3d Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 3 Jun 2003 02:14:28 +0000 Subject: Disabled config files when testing. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1372 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5dd192c25..ebfc218f6 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -559,23 +559,29 @@ class PythonModuleParserTestSuite(CustomTestSuite): id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) -class LatexPublishTestCase(CustomTestCase): + +# @@@ These should be generalized to WriterPublishTestCase/Suite or +# just PublishTestCase/Suite, as per TransformTestCase/Suite. +class LatexPublishTestCase(CustomTestCase, docutils.SettingsSpec): """ Test case for publish. """ + settings_default_overrides = {'_disable_config': 1} + def test_publish(self): if self.run_in_debugger: pdb.set_trace() - output = docutils.core.publish_string(source=self.input, source_path=None, - destination_path=None, - reader=None, reader_name='standalone', - parser=None, parser_name='restructuredtext', - writer=None, writer_name='latex', - settings=None, settings_spec=None, settings_overrides=None) + output = docutils.core.publish_string( + source=self.input, + reader_name='standalone', + parser_name='restructuredtext', + writer_name='latex', + settings_spec=self) self.compare_output(self.input, output, self.expected) + class LatexPublishTestSuite(CustomTestSuite): def __init__(self): -- cgit v1.2.1 From 28beb4fa2791b1722fab297c9e44b0ff7e652bf1 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 5 Jul 2003 19:42:22 +0000 Subject: added ``StringList`` support for table tests git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1571 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index ebfc218f6..0f3ae7840 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -50,7 +50,7 @@ from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, directives, languages from docutils.readers import standalone, pep, python -from docutils.statemachine import string2lines +from docutils.statemachine import StringList, string2lines try: from docutils.readers.python import moduleparser @@ -63,6 +63,9 @@ except: import pdb +# Hack to make repr(StringList) look like repr(list): +StringList.__repr__ = StringList.__str__ + class DevNull: @@ -405,7 +408,7 @@ class GridTableParserTestCase(CustomTestCase): parser = tableparser.GridTableParser() def test_parse_table(self): - self.parser.setup(string2lines(self.input)) + self.parser.setup(StringList(string2lines(self.input), 'test data')) try: self.parser.find_head_body_sep() self.parser.parse_table() @@ -417,7 +420,8 @@ class GridTableParserTestCase(CustomTestCase): def test_parse(self): try: - output = self.parser.parse(string2lines(self.input)) + output = self.parser.parse(StringList(string2lines(self.input), + 'test data')) except Exception, details: output = '%s: %s' % (details.__class__.__name__, details) self.compare_output(self.input, pformat(output) + '\n', -- cgit v1.2.1 From deaf371541cffaf3646ff4fa725c3055496dea27 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 6 Aug 2003 18:38:10 +0000 Subject: provide more exception data git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1622 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 0f3ae7840..6d7de133c 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -608,8 +608,13 @@ class LatexPublishTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -def exception_args(code): +def exception_data(code): + """ + Execute `code` and return the resulting exception, the exception arguments, + and the formatted exception string. + """ try: exec(code) except Exception, detail: - return detail.args + return (detail, detail.args, + '%s: %s' % (detail.__class__.__name__, detail)) -- cgit v1.2.1 From 2a9d65d0b995c27395b53afde4da65c88a16e3fe Mon Sep 17 00:00:00 2001 From: orutherfurd Date: Sun, 21 Mar 2004 22:44:56 +0000 Subject: refactored publisher test suite/case class names to make testing other writers easier git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1850 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6d7de133c..8f1b5c91e 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -29,8 +29,9 @@ Exports the following: - `GridTableParserTestCase` - `SimpleTableParserTestSuite` - `SimpleTableParserTestCase` - - 'LatexPublishTestSuite' - - 'LatexPublishTestCase' + - `WriterPublishTestCase` + - `LatexWriterPublishTestCase` + - `PublishTestSuite` - `DevNull` (output sink) """ __docformat__ = 'reStructuredText' @@ -564,16 +565,15 @@ class PythonModuleParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -# @@@ These should be generalized to WriterPublishTestCase/Suite or -# just PublishTestCase/Suite, as per TransformTestCase/Suite. -class LatexPublishTestCase(CustomTestCase, docutils.SettingsSpec): +class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): """ Test case for publish. """ settings_default_overrides = {'_disable_config': 1} - + writer_name = '' # override in subclasses + def test_publish(self): if self.run_in_debugger: pdb.set_trace() @@ -581,15 +581,33 @@ class LatexPublishTestCase(CustomTestCase, docutils.SettingsSpec): source=self.input, reader_name='standalone', parser_name='restructuredtext', - writer_name='latex', + writer_name=self.writer_name, settings_spec=self) self.compare_output(self.input, output, self.expected) -class LatexPublishTestSuite(CustomTestSuite): +class LatexWriterPublishTestCase(WriterPublishTestCase): + + """ + Test case for Latex writer. + """ + + writer_name = 'latex' + + +class PublishTestSuite(CustomTestSuite): + + TEST_CLASSES = { + 'latex': LatexWriterPublishTestCase, + } - def __init__(self): + def __init__(self,writer_name): + """ + `writer_name` is the name of the writer + to use. It must be a key in `TEST_CLASSES`. + """ CustomTestSuite.__init__(self) + self.test_class = self.TEST_CLASSES[writer_name] def generateTests(self, dict, dictname='totest'): for name, cases in dict.items(): @@ -602,7 +620,7 @@ class LatexPublishTestSuite(CustomTestSuite): else: continue self.addTestCase( - LatexPublishTestCase, 'test_publish', + self.test_class, 'test_publish', input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) -- cgit v1.2.1 From ad4a0f8a81f935a0c6829bb1f2db2f42d19b20c8 Mon Sep 17 00:00:00 2001 From: mmgilbe Date: Mon, 22 Mar 2004 01:09:49 +0000 Subject: Updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1856 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 8f1b5c91e..92d20f41e 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -271,6 +271,7 @@ class TransformTestCase(CustomTestCase): settings.halt_level = 5 settings.debug = package_unittest.debug settings.warning_stream = DevNull() + unknown_reference_resolvers = () def __init__(self, *args, **kwargs): self.transforms = kwargs['transforms'] -- cgit v1.2.1 From db10b42915077db1a6cbb936145d0d803142b12a Mon Sep 17 00:00:00 2001 From: ianbicking Date: Tue, 23 Mar 2004 19:57:14 +0000 Subject: * Bug fixes to python reader * Getting tests up-to-date * Trimming unused nodes from pynodes git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1876 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 92d20f41e..a153d4f5e 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -516,7 +516,7 @@ class PythonModuleParserTestCase(CustomTestCase): def test_parser(self): if self.run_in_debugger: pdb.set_trace() - module = moduleparser.parse_module(self.input, 'test data') + module = moduleparser.parse_module(self.input, 'test data').pformat() output = str(module) self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 634a5d0622c6fbeb09face1622dc8b4d79878f00 Mon Sep 17 00:00:00 2001 From: reggie Date: Tue, 23 Mar 2004 22:29:44 +0000 Subject: Added funtionality to keep track of individual parts of a document and store them in a dictionary as the "parts" attribute of the writer. Added publish_parts convenience function to allow easy access to these parts. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1879 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 54 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index a153d4f5e..b523f7d92 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -31,7 +31,9 @@ Exports the following: - `SimpleTableParserTestCase` - `WriterPublishTestCase` - `LatexWriterPublishTestCase` + - `HtmlWriterPublishTestCase` - `PublishTestSuite` + - `HtmlFragmentTestSuite` - `DevNull` (output sink) """ __docformat__ = 'reStructuredText' @@ -596,13 +598,41 @@ class LatexWriterPublishTestCase(WriterPublishTestCase): writer_name = 'latex' +class HtmlWriterPublishTestCase(WriterPublishTestCase): + + """ + Test case for fragment code in HTML writer. + """ + + writer_name = 'html' + + def __init__(self, *args, **kwargs): + self.settings_overrides = kwargs['settings_overrides'] + """Settings overrides to use for this test case.""" + + del kwargs['settings_overrides'] # only wanted here + CustomTestCase.__init__(self, *args, **kwargs) + + def test_publish(self): + if self.run_in_debugger: + pdb.set_trace() + output = docutils.core.publish_parts( + source=self.input, + reader_name='standalone', + parser_name='restructuredtext', + writer_name=self.writer_name, + settings_spec=self, + settings_overrides=self.settings_overrides) + self.compare_output(self.input, output['fragment'], self.expected) + + class PublishTestSuite(CustomTestSuite): TEST_CLASSES = { 'latex': LatexWriterPublishTestCase, } - def __init__(self,writer_name): + def __init__(self, writer_name): """ `writer_name` is the name of the writer to use. It must be a key in `TEST_CLASSES`. @@ -627,6 +657,28 @@ class PublishTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) +class HtmlFragmentTestSuite(CustomTestSuite): + def __init__(self): + CustomTestSuite.__init__(self) + self.test_class = HtmlWriterPublishTestCase + + def generateTests(self, dict, dictname='totest'): + for name, (settings_overrides, cases) in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + run_in_debugger = 0 + if len(case)==3: + if case[2]: + run_in_debugger = 1 + else: + continue + self.addTestCase( + self.test_class, 'test_publish', + settings_overrides=settings_overrides, + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + run_in_debugger=run_in_debugger) + def exception_data(code): """ Execute `code` and return the resulting exception, the exception arguments, -- cgit v1.2.1 From 917d7123f53aa0ba69c2ebcfed167acaac9c4931 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 17 Apr 2004 22:47:37 +0000 Subject: added support for custom interpreted text roles git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1958 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index b523f7d92..3bbb1fd52 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -51,7 +51,7 @@ import docutils.core from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst -from docutils.parsers.rst import states, tableparser, directives, languages +from docutils.parsers.rst import states, tableparser, roles, languages from docutils.readers import standalone, pep, python from docutils.statemachine import StringList, string2lines @@ -333,7 +333,7 @@ class ParserTestCase(CustomTestCase): parser = rst.Parser() """Parser shared by all ParserTestCases.""" - option_parser = frontend.OptionParser(components=(parser,)) + option_parser = frontend.OptionParser(components=(rst.Parser,)) settings = option_parser.get_default_values() settings.report_level = 5 settings.halt_level = 5 @@ -343,6 +343,8 @@ class ParserTestCase(CustomTestCase): if self.run_in_debugger: pdb.set_trace() document = utils.new_document('test data', self.settings) + # Remove any additions made by "role" directives: + roles._roles = {} self.parser.parse(self.input, document) output = document.pformat() self.compare_output(self.input, output, self.expected) @@ -393,7 +395,7 @@ class PEPParserTestCase(ParserTestCase): parser = rst.Parser(rfc2822=1, inliner=pep.Inliner()) """Parser shared by all PEPParserTestCases.""" - option_parser = frontend.OptionParser(components=(parser, pep.Reader)) + option_parser = frontend.OptionParser(components=(rst.Parser, pep.Reader)) settings = option_parser.get_default_values() settings.report_level = 5 settings.halt_level = 5 -- cgit v1.2.1 From 693b7480ab21ad348a30056294fad39337e89e22 Mon Sep 17 00:00:00 2001 From: wiemann Date: Tue, 27 Apr 2004 18:46:34 +0000 Subject: Added pseudo-XML test. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@1995 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 3bbb1fd52..1d3fc3dd9 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -600,6 +600,15 @@ class LatexWriterPublishTestCase(WriterPublishTestCase): writer_name = 'latex' +class PseudoXMLWriterPublishTestCase(WriterPublishTestCase): + + """ + Test case for pseudo-XML writer. + """ + + writer_name = 'pseudoxml' + + class HtmlWriterPublishTestCase(WriterPublishTestCase): """ @@ -632,6 +641,7 @@ class PublishTestSuite(CustomTestSuite): TEST_CLASSES = { 'latex': LatexWriterPublishTestCase, + 'pseudoxml': PseudoXMLWriterPublishTestCase, } def __init__(self, writer_name): -- cgit v1.2.1 From 55ec8869e29a3c5a54da5b8f70dd3b56db1ad11d Mon Sep 17 00:00:00 2001 From: wiemann Date: Fri, 30 Apr 2004 22:47:44 +0000 Subject: Fixed documentation. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2017 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 1d3fc3dd9..c2906ad20 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -31,6 +31,7 @@ Exports the following: - `SimpleTableParserTestCase` - `WriterPublishTestCase` - `LatexWriterPublishTestCase` + - `PseudoXMLWriterPublishTestCase` - `HtmlWriterPublishTestCase` - `PublishTestSuite` - `HtmlFragmentTestSuite` -- cgit v1.2.1 From 4418cd01deb5242e6ee0e682533b1ef05ba538cd Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 7 May 2004 14:40:34 +0000 Subject: unused import removed git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2039 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index c2906ad20..e74ef1915 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -53,7 +53,7 @@ from docutils import frontend, nodes, statemachine, urischemes, utils from docutils.transforms import universal from docutils.parsers import rst from docutils.parsers.rst import states, tableparser, roles, languages -from docutils.readers import standalone, pep, python +from docutils.readers import standalone, pep from docutils.statemachine import StringList, string2lines try: -- cgit v1.2.1 From 6a19d000aba8d369242f2c409e7ecafe691bdef4 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 7 May 2004 15:29:40 +0000 Subject: whitespace git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2043 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e74ef1915..ff3ab3353 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -525,7 +525,7 @@ class PythonModuleParserTestCase(CustomTestCase): output = str(module) self.compare_output(self.input, output, self.expected) - def test_token_parser_rhs(self): + def test_token_parser_rhs(self): if self.run_in_debugger: pdb.set_trace() tr = moduleparser.TokenParser(self.input) @@ -579,7 +579,7 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): settings_default_overrides = {'_disable_config': 1} writer_name = '' # override in subclasses - + def test_publish(self): if self.run_in_debugger: pdb.set_trace() @@ -647,7 +647,7 @@ class PublishTestSuite(CustomTestSuite): def __init__(self, writer_name): """ - `writer_name` is the name of the writer + `writer_name` is the name of the writer to use. It must be a key in `TEST_CLASSES`. """ CustomTestSuite.__init__(self) -- cgit v1.2.1 From f40eb958d0e53eb5aad9e8b3fdb1cc98e9598df8 Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 7 May 2004 15:33:33 +0000 Subject: Py2.1 compatibility git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2044 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index ff3ab3353..126448b4b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -58,6 +58,7 @@ from docutils.statemachine import StringList, string2lines try: from docutils.readers.python import moduleparser + from tokenize import generate_tokens # new in Python 2.2 except: moduleparser = None -- cgit v1.2.1 From c3446fab679133b8d74ffbcefc1bbe6bc9ebaccb Mon Sep 17 00:00:00 2001 From: goodger Date: Fri, 7 May 2004 21:31:42 +0000 Subject: added Python version checking git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2048 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 126448b4b..0af838e1c 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -56,10 +56,9 @@ from docutils.parsers.rst import states, tableparser, roles, languages from docutils.readers import standalone, pep from docutils.statemachine import StringList, string2lines -try: +if sys.hexversion >= 0x02020000: # Python 2.2 from docutils.readers.python import moduleparser - from tokenize import generate_tokens # new in Python 2.2 -except: +else: moduleparser = None try: @@ -540,11 +539,6 @@ class PythonModuleParserTestSuite(CustomTestSuite): A collection of PythonModuleParserTestCase. """ - if moduleparser is None: - PythonModuleParserTestCase.test_parser = CustomTestCase.skip_test - PythonModuleParserTestCase.test_token_parser_rhs = \ - CustomTestCase.skip_test - def generateTests(self, dict, dictname='totest', testmethod='test_parser'): """ @@ -571,6 +565,14 @@ class PythonModuleParserTestSuite(CustomTestSuite): id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) + if moduleparser is None: + # Skip Python Source Reader tests for Python < 2.2: + def generateTests(*args, **kwargs): pass + + #PythonModuleParserTestCase.test_parser = CustomTestCase.skip_test + #PythonModuleParserTestCase.test_token_parser_rhs = \ + # CustomTestCase.skip_test + class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): -- cgit v1.2.1 From b4d29e860f96c5380c7b4695664e7b4a1af6fd0a Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 8 May 2004 19:21:20 +0000 Subject: added one-time notice of skipped tests git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2050 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 0af838e1c..872175cc2 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -154,6 +154,9 @@ class CustomTestSuite(unittest.TestSuite): self.addTest(tc) return tc + def generate_no_tests(self, *args, **kwargs): + pass + class CustomTestCase(unittest.TestCase): @@ -539,6 +542,17 @@ class PythonModuleParserTestSuite(CustomTestSuite): A collection of PythonModuleParserTestCase. """ + notified = None + + def __init__(self, *args, **kwargs): + if moduleparser is None: + if not self.notified: + print ('Tests of docutils.readers.python skipped; ' + 'Python 2.2 or higher required.') + PythonModuleParserTestSuite.notified = 1 + self.generateTests = self.generate_no_tests + CustomTestSuite.__init__(self, *args, **kwargs) + def generateTests(self, dict, dictname='totest', testmethod='test_parser'): """ @@ -565,14 +579,6 @@ class PythonModuleParserTestSuite(CustomTestSuite): id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) - if moduleparser is None: - # Skip Python Source Reader tests for Python < 2.2: - def generateTests(*args, **kwargs): pass - - #PythonModuleParserTestCase.test_parser = CustomTestCase.skip_test - #PythonModuleParserTestCase.test_token_parser_rhs = \ - # CustomTestCase.skip_test - class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): -- cgit v1.2.1 From efa3b5a365e2d0e616d77447c17a2c415aaa3546 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 9 May 2004 02:06:45 +0000 Subject: Added support for publish_parts interface for HTML git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2055 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 93 +++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 33 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 872175cc2..e1f4369ba 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -619,34 +619,6 @@ class PseudoXMLWriterPublishTestCase(WriterPublishTestCase): writer_name = 'pseudoxml' -class HtmlWriterPublishTestCase(WriterPublishTestCase): - - """ - Test case for fragment code in HTML writer. - """ - - writer_name = 'html' - - def __init__(self, *args, **kwargs): - self.settings_overrides = kwargs['settings_overrides'] - """Settings overrides to use for this test case.""" - - del kwargs['settings_overrides'] # only wanted here - CustomTestCase.__init__(self, *args, **kwargs) - - def test_publish(self): - if self.run_in_debugger: - pdb.set_trace() - output = docutils.core.publish_parts( - source=self.input, - reader_name='standalone', - parser_name='restructuredtext', - writer_name=self.writer_name, - settings_spec=self, - settings_overrides=self.settings_overrides) - self.compare_output(self.input, output['fragment'], self.expected) - - class PublishTestSuite(CustomTestSuite): TEST_CLASSES = { @@ -679,10 +651,7 @@ class PublishTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -class HtmlFragmentTestSuite(CustomTestSuite): - def __init__(self): - CustomTestSuite.__init__(self) - self.test_class = HtmlWriterPublishTestCase +class HtmlPublishPartsTestSuite(CustomTestSuite): def generateTests(self, dict, dictname='totest'): for name, (settings_overrides, cases) in dict.items(): @@ -695,12 +664,70 @@ class HtmlFragmentTestSuite(CustomTestSuite): else: continue self.addTestCase( - self.test_class, 'test_publish', + HtmlWriterPublishPartsTestCase, 'test_publish', settings_overrides=settings_overrides, input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), run_in_debugger=run_in_debugger) + +class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): + + """ + Test case for HTML writer via the publish_parts interface. + """ + + writer_name = 'html' + + def __init__(self, *args, **kwargs): + self.settings_overrides = kwargs['settings_overrides'] + """Settings overrides to use for this test case.""" + + del kwargs['settings_overrides'] # only wanted here + CustomTestCase.__init__(self, *args, **kwargs) + + def test_publish(self): + if self.run_in_debugger: + pdb.set_trace() + parts = docutils.core.publish_parts( + source=self.input, + reader_name='standalone', + parser_name='restructuredtext', + writer_name=self.writer_name, + settings_spec=self, + settings_overrides=self.settings_overrides) + output = self.format_output(parts) + # interpolate standard variables: + expected = self.expected % {'version': docutils.__version__} + self.compare_output(self.input, output, expected) + + standard_meta_value = """\ + + +""" % docutils.__version__ + + def format_output(self, parts): + """Minimize & standardize the output.""" + # remove redundant bits: + del parts['whole'] + del parts['body'] + parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') + # remove empty values: + for key in parts.keys(): + if not parts[key]: + del parts[key] + # standard output format: + keys = parts.keys() + keys.sort() + output = [] + for key in keys: + output.append("%r: '''%s'''" + % (key, parts[key].encode('raw_unicode_escape'))) + if output[-1].endswith("\n'''"): + output[-1] = output[-1][:-4] + "\\n'''" + return '{' + ',\n '.join(output) + '}\n' + + def exception_data(code): """ Execute `code` and return the resulting exception, the exception arguments, -- cgit v1.2.1 From 8151d561018865c3501894539bc144ffc4f150d0 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 9 May 2004 02:14:33 +0000 Subject: further minimization git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2057 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e1f4369ba..5c5c49d42 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -705,13 +705,18 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): """ % docutils.__version__ + standard_stylesheet_value = ('\n') def format_output(self, parts): """Minimize & standardize the output.""" # remove redundant bits: del parts['whole'] del parts['body'] + # remove standard bits: parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') + if parts['stylesheet'] == self.standard_stylesheet_value: + del parts['stylesheet'] # remove empty values: for key in parts.keys(): if not parts[key]: -- cgit v1.2.1 From 34a92129993494ee286047194275d048d279db6e Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 16 Jun 2004 17:22:29 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2288 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5c5c49d42..1545db42d 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -396,7 +396,7 @@ class PEPParserTestCase(ParserTestCase): """PEP-specific parser test case.""" - parser = rst.Parser(rfc2822=1, inliner=pep.Inliner()) + parser = rst.Parser(rfc2822=1, inliner=rst.states.Inliner()) """Parser shared by all PEPParserTestCases.""" option_parser = frontend.OptionParser(components=(rst.Parser, pep.Reader)) -- cgit v1.2.1 From 28990425747d5915945f4097ef180aa6cadddec0 Mon Sep 17 00:00:00 2001 From: wiemann Date: Tue, 22 Jun 2004 20:13:37 +0000 Subject: renamed difflib to docutils_difflib git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2354 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 1545db42d..baaf44978 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -42,7 +42,7 @@ __docformat__ = 'reStructuredText' import sys import os import unittest -import difflib +import docutils_difflib import inspect from pprint import pformat from types import UnicodeType @@ -160,7 +160,7 @@ class CustomTestSuite(unittest.TestSuite): class CustomTestCase(unittest.TestCase): - compare = difflib.Differ().compare + compare = docutils_difflib.Differ().compare """Comparison method shared by all subclasses.""" def __init__(self, method_name, input, expected, id, -- cgit v1.2.1 From 92cf1a41dfcfaecc618930fb85cf5fb5f775dc01 Mon Sep 17 00:00:00 2001 From: cben Date: Sun, 25 Jul 2004 02:14:23 +0000 Subject: Replace version number sniffing with specific features sniffing. Also fix 2 bugs in `report_UnicodeError`: * Print the current encoding (was a ``%s``). * Don't crash before Python 2.3 where `UnicodeError` objects had no ``object`` or ``encoding`` attributes. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2450 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index baaf44978..a7c17a105 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -56,9 +56,9 @@ from docutils.parsers.rst import states, tableparser, roles, languages from docutils.readers import standalone, pep from docutils.statemachine import StringList, string2lines -if sys.hexversion >= 0x02020000: # Python 2.2 +try: from docutils.readers.python import moduleparser -else: +except ImportError: # moduleparser depends on modules added in Python 2.2 moduleparser = None try: -- cgit v1.2.1 From 80e3d5d2480ed56cb88094abfc6e88cc3bf1aef2 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 25 Jul 2004 02:30:05 +0000 Subject: simple import isn't enough -- added another requirement (testing for 2.2 was easier!) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2452 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index a7c17a105..7525141f3 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -58,6 +58,8 @@ from docutils.statemachine import StringList, string2lines try: from docutils.readers.python import moduleparser + from tokenize import generate_tokens + del generate_tokens except ImportError: # moduleparser depends on modules added in Python 2.2 moduleparser = None -- cgit v1.2.1 From 5c1ef3d165e68715f8dd4c226e59a60d9610ca58 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 29 Aug 2004 19:30:56 +0000 Subject: reordering so that TestCases appear before TestSuites git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2547 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 206 ++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 103 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 7525141f3..fc4e97d6f 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -81,6 +81,64 @@ class DevNull: pass +class CustomTestCase(unittest.TestCase): + + compare = docutils_difflib.Differ().compare + """Comparison method shared by all subclasses.""" + + def __init__(self, method_name, input, expected, id, + run_in_debugger=0, short_description=None): + """ + Initialise the CustomTestCase. + + Arguments: + + method_name -- name of test method to run. + input -- input to the parser. + expected -- expected output from the parser. + id -- unique test identifier, used by the test framework. + run_in_debugger -- if true, run this test under the pdb debugger. + short_description -- override to default test description. + """ + self.id = id + self.input = input + self.expected = expected + self.run_in_debugger = run_in_debugger + # Ring your mother. + unittest.TestCase.__init__(self, method_name) + + def __str__(self): + """ + Return string conversion. Overridden to give test id, in addition to + method name. + """ + return '%s; %s' % (self.id, unittest.TestCase.__str__(self)) + + def __repr__(self): + return "<%s %s>" % (self.id, unittest.TestCase.__repr__(self)) + + def compare_output(self, input, output, expected): + """`input`, `output`, and `expected` should all be strings.""" + if type(input) == UnicodeType: + input = input.encode('raw_unicode_escape') + if type(output) == UnicodeType: + output = output.encode('raw_unicode_escape') + if type(expected) == UnicodeType: + expected = expected.encode('raw_unicode_escape') + try: + self.assertEquals('\n' + output, '\n' + expected) + except AssertionError: + print >>sys.stderr, '\n%s\ninput:' % (self,) + print >>sys.stderr, input + print >>sys.stderr, '-: expected\n+: output' + print >>sys.stderr, ''.join(self.compare(expected.splitlines(1), + output.splitlines(1))) + raise + + def skip_test(self): + print >>sys.stderr, '%s: Test skipped' % self + + class CustomTestSuite(unittest.TestSuite): """ @@ -160,109 +218,6 @@ class CustomTestSuite(unittest.TestSuite): pass -class CustomTestCase(unittest.TestCase): - - compare = docutils_difflib.Differ().compare - """Comparison method shared by all subclasses.""" - - def __init__(self, method_name, input, expected, id, - run_in_debugger=0, short_description=None): - """ - Initialise the CustomTestCase. - - Arguments: - - method_name -- name of test method to run. - input -- input to the parser. - expected -- expected output from the parser. - id -- unique test identifier, used by the test framework. - run_in_debugger -- if true, run this test under the pdb debugger. - short_description -- override to default test description. - """ - self.id = id - self.input = input - self.expected = expected - self.run_in_debugger = run_in_debugger - # Ring your mother. - unittest.TestCase.__init__(self, method_name) - - def __str__(self): - """ - Return string conversion. Overridden to give test id, in addition to - method name. - """ - return '%s; %s' % (self.id, unittest.TestCase.__str__(self)) - - def __repr__(self): - return "<%s %s>" % (self.id, unittest.TestCase.__repr__(self)) - - def compare_output(self, input, output, expected): - """`input`, `output`, and `expected` should all be strings.""" - if type(input) == UnicodeType: - input = input.encode('raw_unicode_escape') - if type(output) == UnicodeType: - output = output.encode('raw_unicode_escape') - if type(expected) == UnicodeType: - expected = expected.encode('raw_unicode_escape') - try: - self.assertEquals('\n' + output, '\n' + expected) - except AssertionError: - print >>sys.stderr, '\n%s\ninput:' % (self,) - print >>sys.stderr, input - print >>sys.stderr, '-: expected\n+: output' - print >>sys.stderr, ''.join(self.compare(expected.splitlines(1), - output.splitlines(1))) - raise - - def skip_test(self): - print >>sys.stderr, '%s: Test skipped' % self - - -class TransformTestSuite(CustomTestSuite): - - """ - A collection of TransformTestCases. - - A TransformTestSuite instance manufactures TransformTestCases, - keeps track of them, and provides a shared test fixture (a-la - setUp and tearDown). - """ - - def __init__(self, parser): - self.parser = parser - """Parser shared by all test cases.""" - - CustomTestSuite.__init__(self) - - def generateTests(self, dict, dictname='totest', - testmethod='test_transforms'): - """ - Stock the suite with test cases generated from a test data dictionary. - - Each dictionary key (test type's name) maps to a list of transform - classes and list of tests. Each test is a list: input, expected - output, optional modifier. The optional third entry, a behavior - modifier, can be 0 (temporarily disable this test) or 1 (run this test - under the pdb debugger). Tests should be self-documenting and not - require external comments. - """ - for name, (transforms, cases) in dict.items(): - for casenum in range(len(cases)): - case = cases[casenum] - run_in_debugger = 0 - if len(case)==3: - if case[2]: - run_in_debugger = 1 - else: - continue - self.addTestCase( - TransformTestCase, testmethod, - transforms=transforms, parser=self.parser, - input=case[0], expected=case[1], - id='%s[%r][%s]' % (dictname, name, casenum), - run_in_debugger=run_in_debugger) - - class TransformTestCase(CustomTestCase): """ @@ -326,6 +281,51 @@ class TransformTestCase(CustomTestCase): self.compare_output(self.input, output, self.expected) +class TransformTestSuite(CustomTestSuite): + + """ + A collection of TransformTestCases. + + A TransformTestSuite instance manufactures TransformTestCases, + keeps track of them, and provides a shared test fixture (a-la + setUp and tearDown). + """ + + def __init__(self, parser): + self.parser = parser + """Parser shared by all test cases.""" + + CustomTestSuite.__init__(self) + + def generateTests(self, dict, dictname='totest', + testmethod='test_transforms'): + """ + Stock the suite with test cases generated from a test data dictionary. + + Each dictionary key (test type's name) maps to a list of transform + classes and list of tests. Each test is a list: input, expected + output, optional modifier. The optional third entry, a behavior + modifier, can be 0 (temporarily disable this test) or 1 (run this test + under the pdb debugger). Tests should be self-documenting and not + require external comments. + """ + for name, (transforms, cases) in dict.items(): + for casenum in range(len(cases)): + case = cases[casenum] + run_in_debugger = 0 + if len(case)==3: + if case[2]: + run_in_debugger = 1 + else: + continue + self.addTestCase( + TransformTestCase, testmethod, + transforms=transforms, parser=self.parser, + input=case[0], expected=case[1], + id='%s[%r][%s]' % (dictname, name, casenum), + run_in_debugger=run_in_debugger) + + class ParserTestCase(CustomTestCase): """ -- cgit v1.2.1 From 0c6e28c65c75920ad60b651a4535d90fc87013dd Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 29 Aug 2004 21:55:26 +0000 Subject: added some comments, did some cleanup; David Goodger, could you review this? git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2549 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index fc4e97d6f..0e6d3a08c 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -17,18 +17,18 @@ Exports the following: - `tableparser` is 'docutils.parsers.rst.tableparser' :Classes: - - `CustomTestSuite` - `CustomTestCase` - - `TransformTestSuite` + - `CustomTestSuite` - `TransformTestCase` - - `ParserTestSuite` + - `TransformTestSuite` - `ParserTestCase` - - `PEPParserTestSuite` + - `ParserTestSuite` - `PEPParserTestCase` - - `GridTableParserTestSuite` + - `PEPParserTestSuite` - `GridTableParserTestCase` - - `SimpleTableParserTestSuite` + - `GridTableParserTestSuite` - `SimpleTableParserTestCase` + - `SimpleTableParserTestSuite` - `WriterPublishTestCase` - `LatexWriterPublishTestCase` - `PseudoXMLWriterPublishTestCase` @@ -82,6 +82,14 @@ class DevNull: class CustomTestCase(unittest.TestCase): + + """ + Helper class, providing extended functionality over unittest.TestCase. + + This isn't specific to Docutils but of general use when dealing + with large amounts of text. In particular, see the compare_output + method and the parameter list of __init__. + """ compare = docutils_difflib.Differ().compare """Comparison method shared by all subclasses.""" @@ -104,6 +112,10 @@ class CustomTestCase(unittest.TestCase): self.input = input self.expected = expected self.run_in_debugger = run_in_debugger + + # XXX What do we do with short_description? It isn't used at + # all. + # Ring your mother. unittest.TestCase.__init__(self, method_name) @@ -135,15 +147,15 @@ class CustomTestCase(unittest.TestCase): output.splitlines(1))) raise - def skip_test(self): - print >>sys.stderr, '%s: Test skipped' % self - class CustomTestSuite(unittest.TestSuite): """ - A collection of custom TestCases. + A collection of CustomTestCases. + Provides test suite ID generation. + + XXX Any other reason why we need this class? """ id = '' @@ -188,13 +200,13 @@ class CustomTestSuite(unittest.TestSuite): id=None, run_in_debugger=0, short_description=None, **kwargs): """ - Create a custom TestCase in the CustomTestSuite. + Create a CustomTestCase in the CustomTestSuite. Also return it, just in case. Arguments: - test_case_class -- - method_name -- + test_case_class -- the CustomTestCase to add + method_name -- a string; CustomTestCase.method_name is the test input -- input to the parser. expected -- expected output from the parser. id -- unique test identifier, used by the test framework. @@ -302,12 +314,13 @@ class TransformTestSuite(CustomTestSuite): """ Stock the suite with test cases generated from a test data dictionary. - Each dictionary key (test type's name) maps to a list of transform - classes and list of tests. Each test is a list: input, expected - output, optional modifier. The optional third entry, a behavior - modifier, can be 0 (temporarily disable this test) or 1 (run this test - under the pdb debugger). Tests should be self-documenting and not - require external comments. + Each dictionary key (test type's name) maps to a tuple, whose + first item is a list of transform classes and whose second + item is a list of tests. Each test is a list: input, expected + output, optional modifier. The optional third entry, a + behavior modifier, can be 0 (temporarily disable this test) or + 1 (run this test under the pdb debugger). Tests should be + self-documenting and not require external comments. """ for name, (transforms, cases) in dict.items(): for casenum in range(len(cases)): @@ -604,20 +617,12 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): class LatexWriterPublishTestCase(WriterPublishTestCase): - - """ - Test case for Latex writer. - """ - + """Test case for Latex writer.""" writer_name = 'latex' class PseudoXMLWriterPublishTestCase(WriterPublishTestCase): - - """ - Test case for pseudo-XML writer. - """ - + """Test case for pseudo-XML writer.""" writer_name = 'pseudoxml' -- cgit v1.2.1 From 79fadb03aea8a33e2fc999aab34eef383059a3a4 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 13 Sep 2004 14:03:17 +0000 Subject: removed unused code; updated docstring git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2602 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 0e6d3a08c..d4917094e 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -94,8 +94,7 @@ class CustomTestCase(unittest.TestCase): compare = docutils_difflib.Differ().compare """Comparison method shared by all subclasses.""" - def __init__(self, method_name, input, expected, id, - run_in_debugger=0, short_description=None): + def __init__(self, method_name, input, expected, id, run_in_debugger=0): """ Initialise the CustomTestCase. @@ -106,16 +105,12 @@ class CustomTestCase(unittest.TestCase): expected -- expected output from the parser. id -- unique test identifier, used by the test framework. run_in_debugger -- if true, run this test under the pdb debugger. - short_description -- override to default test description. """ self.id = id self.input = input self.expected = expected self.run_in_debugger = run_in_debugger - # XXX What do we do with short_description? It isn't used at - # all. - # Ring your mother. unittest.TestCase.__init__(self, method_name) @@ -153,9 +148,7 @@ class CustomTestSuite(unittest.TestSuite): """ A collection of CustomTestCases. - Provides test suite ID generation. - - XXX Any other reason why we need this class? + Provides test suite ID generation and a method for adding test cases. """ id = '' @@ -197,8 +190,7 @@ class CustomTestSuite(unittest.TestSuite): self.id = id def addTestCase(self, test_case_class, method_name, input, expected, - id=None, run_in_debugger=0, short_description=None, - **kwargs): + id=None, run_in_debugger=0, **kwargs): """ Create a CustomTestCase in the CustomTestSuite. Also return it, just in case. @@ -211,7 +203,6 @@ class CustomTestSuite(unittest.TestSuite): expected -- expected output from the parser. id -- unique test identifier, used by the test framework. run_in_debugger -- if true, run this test under the pdb debugger. - short_description -- override to default test description. """ if id is None: # generate id if required id = self.next_test_case_id @@ -220,9 +211,7 @@ class CustomTestSuite(unittest.TestSuite): tcid = '%s: %s' % (self.id, id) # generate and add test case tc = test_case_class(method_name, input, expected, tcid, - run_in_debugger=run_in_debugger, - short_description=short_description, - **kwargs) + run_in_debugger=run_in_debugger, **kwargs) self.addTest(tc) return tc -- cgit v1.2.1 From 097eea916324344e93db305e0faf43adbca92cc5 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 13 Sep 2004 18:14:34 +0000 Subject: added functions for proper multi-line string output git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2604 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 106 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 4 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index d4917094e..4b45831cb 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -45,7 +45,7 @@ import unittest import docutils_difflib import inspect from pprint import pformat -from types import UnicodeType +from types import UnicodeType, StringType import package_unittest import docutils import docutils.core @@ -87,8 +87,11 @@ class CustomTestCase(unittest.TestCase): Helper class, providing extended functionality over unittest.TestCase. This isn't specific to Docutils but of general use when dealing - with large amounts of text. In particular, see the compare_output - method and the parameter list of __init__. + with large amounts of text. The methods failUnlessEqual, + failIfEqual, failUnlessAlmostEqual and failIfAlmostEqual have been + overwritten to provide better support for multi-line strings. + Furthermore, see the compare_output method and the parameter list + of __init__. """ compare = docutils_difflib.Differ().compare @@ -133,7 +136,7 @@ class CustomTestCase(unittest.TestCase): if type(expected) == UnicodeType: expected = expected.encode('raw_unicode_escape') try: - self.assertEquals('\n' + output, '\n' + expected) + self.assertEquals(output, expected) except AssertionError: print >>sys.stderr, '\n%s\ninput:' % (self,) print >>sys.stderr, input @@ -142,6 +145,58 @@ class CustomTestCase(unittest.TestCase): output.splitlines(1))) raise + def failUnlessEqual(self, first, second, msg=None): + """Fail if the two objects are unequal as determined by the '==' + operator. + """ + if not first == second: + raise self.failureException, \ + (msg or '%s != %s' % _format_str(first, second)) + + def failIfEqual(self, first, second, msg=None): + """Fail if the two objects are equal as determined by the '==' + operator. + """ + if first == second: + raise self.failureException, \ + (msg or '%s == %s' % _format_str(first, second)) + + def failUnlessAlmostEqual(self, first, second, places=7, msg=None): + """Fail if the two objects are unequal as determined by their + difference rounded to the given number of decimal places + (default 7) and comparing to zero. + + Note that decimal places (from zero) are usually not the same + as significant digits (measured from the most signficant digit). + """ + if round(second-first, places) != 0: + raise self.failureException, \ + (msg or '%s != %s within %s places' % + _format_str(first, second, places)) + + def failIfAlmostEqual(self, first, second, places=7, msg=None): + """Fail if the two objects are equal as determined by their + difference rounded to the given number of decimal places + (default 7) and comparing to zero. + + Note that decimal places (from zero) are usually not the same + as significant digits (measured from the most signficant digit). + """ + if round(second-first, places) == 0: + raise self.failureException, \ + (msg or '%s == %s within %s places' % + _format_str(first, second, places)) + + # Synonyms for assertion methods + + assertEqual = assertEquals = failUnlessEqual + + assertNotEqual = assertNotEquals = failIfEqual + + assertAlmostEqual = assertAlmostEquals = failUnlessAlmostEqual + + assertNotAlmostEqual = assertNotAlmostEquals = failIfAlmostEqual + class CustomTestSuite(unittest.TestSuite): @@ -739,3 +794,46 @@ def exception_data(code): except Exception, detail: return (detail, detail.args, '%s: %s' % (detail.__class__.__name__, detail)) + + +def _format_str(*args): + r""" + Return a tuple containing representations of all args. + + Same as map(repr, args) except that it returns multi-line + representations for strings containing newlines, e.g.:: + + '''\ + foo \n\ + bar + + baz''' + + instead of:: + + 'foo \nbar\n\nbaz' + + This is a helper function for CustomTestCase. + """ + import re + return_tuple = [] + for i in args: + r = repr(i) + if '\n' in i and (isinstance(i, StringType) or + isinstance(i, UnicodeType)): + stripped = '' + if isinstance(i, UnicodeType): + # stripped = 'u' or 'U' + stripped = r[0] + r = r[1:] + # quote_char = "'" or '"' + quote_char = r[0] + assert quote_char in ("'", "'") + assert r[0] == r[-1] + r = r[1:-1] + r = (stripped + 3 * quote_char + '\\\n' + + re.sub(r'(?<=[^\\])((\\\\)*)\\n', r'\1\n', r) + + 3 * quote_char) + r = re.sub(r' \n', r' \\n\\\n', r) + return_tuple.append(r) + return tuple(return_tuple) -- cgit v1.2.1 From ccd56c100333ddaed257f53f892ee6ee3f4db3f5 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 13 Sep 2004 18:16:41 +0000 Subject: removed floating point comparison methods If we need them, they're in the history now. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2605 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 4b45831cb..6272557aa 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -87,11 +87,10 @@ class CustomTestCase(unittest.TestCase): Helper class, providing extended functionality over unittest.TestCase. This isn't specific to Docutils but of general use when dealing - with large amounts of text. The methods failUnlessEqual, - failIfEqual, failUnlessAlmostEqual and failIfAlmostEqual have been - overwritten to provide better support for multi-line strings. - Furthermore, see the compare_output method and the parameter list - of __init__. + with large amounts of text. The methods failUnlessEqual and + failIfEqual have been overwritten to provide better support for + multi-line strings. Furthermore, see the compare_output method + and the parameter list of __init__. """ compare = docutils_difflib.Differ().compare @@ -161,42 +160,12 @@ class CustomTestCase(unittest.TestCase): raise self.failureException, \ (msg or '%s == %s' % _format_str(first, second)) - def failUnlessAlmostEqual(self, first, second, places=7, msg=None): - """Fail if the two objects are unequal as determined by their - difference rounded to the given number of decimal places - (default 7) and comparing to zero. - - Note that decimal places (from zero) are usually not the same - as significant digits (measured from the most signficant digit). - """ - if round(second-first, places) != 0: - raise self.failureException, \ - (msg or '%s != %s within %s places' % - _format_str(first, second, places)) - - def failIfAlmostEqual(self, first, second, places=7, msg=None): - """Fail if the two objects are equal as determined by their - difference rounded to the given number of decimal places - (default 7) and comparing to zero. - - Note that decimal places (from zero) are usually not the same - as significant digits (measured from the most signficant digit). - """ - if round(second-first, places) == 0: - raise self.failureException, \ - (msg or '%s == %s within %s places' % - _format_str(first, second, places)) - # Synonyms for assertion methods assertEqual = assertEquals = failUnlessEqual assertNotEqual = assertNotEquals = failIfEqual - assertAlmostEqual = assertAlmostEquals = failUnlessAlmostEqual - - assertNotAlmostEqual = assertNotAlmostEquals = failIfAlmostEqual - class CustomTestSuite(unittest.TestSuite): -- cgit v1.2.1 From 01e27496cf9d56721b2843b5d8227f1f0a37fe3e Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 29 Sep 2004 17:56:10 +0000 Subject: added close() method for DevNull git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2669 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6272557aa..3f8451959 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -80,6 +80,9 @@ class DevNull: def write(self, string): pass + def close(self): + pass + class CustomTestCase(unittest.TestCase): -- cgit v1.2.1 From 7cbda7d4e42f3484eb7f1d7f5cce4961cf6f6016 Mon Sep 17 00:00:00 2001 From: wiemann Date: Fri, 1 Oct 2004 16:03:36 +0000 Subject: added DocutilsTestSupport.testroot git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2683 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 3f8451959..2c30e2b6f 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -73,6 +73,9 @@ except: StringList.__repr__ = StringList.__str__ +testroot = os.path.abspath(os.path.dirname(__file__) or os.path.curdir) + + class DevNull: """Output sink.""" -- cgit v1.2.1 From 0bfcd094bb1caf0050981139617139cce2e7880c Mon Sep 17 00:00:00 2001 From: fdrake Date: Tue, 5 Oct 2004 14:00:10 +0000 Subject: backward compatibility fix git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2702 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 2c30e2b6f..82a580df4 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -73,7 +73,7 @@ except: StringList.__repr__ = StringList.__str__ -testroot = os.path.abspath(os.path.dirname(__file__) or os.path.curdir) +testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) class DevNull: -- cgit v1.2.1 From 6fa2e20d77db8d257d35ca5c6bead6125a1977c6 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 20 Oct 2004 00:02:37 +0000 Subject: set --strict-visitor for writer tests git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2729 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 82a580df4..6bed804e2 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -620,7 +620,7 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): Test case for publish. """ - settings_default_overrides = {'_disable_config': 1} + settings_default_overrides = {'_disable_config': 1, 'strict_visitor': 1} writer_name = '' # override in subclasses def test_publish(self): -- cgit v1.2.1 From 598365ca8c5c1569a6ee7aeb17f03bae6d452ab2 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 24 Oct 2004 00:25:51 +0000 Subject: minor output formatting improvement for failed tests git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2765 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6bed804e2..e920a768c 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -807,7 +807,7 @@ def _format_str(*args): assert r[0] == r[-1] r = r[1:-1] r = (stripped + 3 * quote_char + '\\\n' + - re.sub(r'(?<=[^\\])((\\\\)*)\\n', r'\1\n', r) + + re.sub(r'(? Date: Sat, 30 Oct 2004 13:57:06 +0000 Subject: added TransitionTestCase, which applies transforms git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2773 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e920a768c..6bc536965 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -23,6 +23,7 @@ Exports the following: - `TransformTestSuite` - `ParserTestCase` - `ParserTestSuite` + - `TransitionTestCase` - `PEPParserTestCase` - `PEPParserTestSuite` - `GridTableParserTestCase` @@ -426,6 +427,26 @@ class ParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) +class TransitionTestCase(ParserTestCase): + + """ + Transitions-specific test case, testing parser and transforms. + For use with ParserTestSuite. + """ + + def test_parser(self): + if self.run_in_debugger: + pdb.set_trace() + document = utils.new_document('test data', self.settings) + # Remove any additions made by "role" directives: + roles._roles = {} + self.parser.parse(self.input, document) + document.transformer.apply_transforms() + output = document.pformat() + self.compare_output(self.input, output, self.expected) + + + class PEPParserTestCase(ParserTestCase): """PEP-specific parser test case.""" -- cgit v1.2.1 From f5badc85ced6a97b79cc6a6d85887f0f610824b6 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sat, 30 Oct 2004 15:54:45 +0000 Subject: renamed TransitionTestCase to ParserTransformTestCase; also run default transforms git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2779 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6bc536965..5a9951da9 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -23,7 +23,7 @@ Exports the following: - `TransformTestSuite` - `ParserTestCase` - `ParserTestSuite` - - `TransitionTestCase` + - `ParserTransformTestCase` - `PEPParserTestCase` - `PEPParserTestSuite` - `GridTableParserTestCase` @@ -427,13 +427,17 @@ class ParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -class TransitionTestCase(ParserTestCase): +class ParserTransformTestCase(ParserTestCase): """ - Transitions-specific test case, testing parser and transforms. + Like ParserTestCase, except that default transforms are run. + For use with ParserTestSuite. """ - + + # Get settings with report_level == 1 from TransformTestCase + settings = TransformTestCase.settings + def test_parser(self): if self.run_in_debugger: pdb.set_trace() @@ -441,6 +445,7 @@ class TransitionTestCase(ParserTestCase): # Remove any additions made by "role" directives: roles._roles = {} self.parser.parse(self.input, document) + document.transformer.populate_from_components([rst.Parser]) document.transformer.apply_transforms() output = document.pformat() self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 04b99fa2349bff7e1f05b18e501b7d12b8d52175 Mon Sep 17 00:00:00 2001 From: goodger Date: Mon, 1 Nov 2004 02:58:09 +0000 Subject: removed ParserTransformTestCase (it was mixing testing modes) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@2791 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5a9951da9..221336336 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -427,31 +427,6 @@ class ParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -class ParserTransformTestCase(ParserTestCase): - - """ - Like ParserTestCase, except that default transforms are run. - - For use with ParserTestSuite. - """ - - # Get settings with report_level == 1 from TransformTestCase - settings = TransformTestCase.settings - - def test_parser(self): - if self.run_in_debugger: - pdb.set_trace() - document = utils.new_document('test data', self.settings) - # Remove any additions made by "role" directives: - roles._roles = {} - self.parser.parse(self.input, document) - document.transformer.populate_from_components([rst.Parser]) - document.transformer.apply_transforms() - output = document.pformat() - self.compare_output(self.input, output, self.expected) - - - class PEPParserTestCase(ParserTestCase): """PEP-specific parser test case.""" -- cgit v1.2.1 From 9757de8a9ede6e064e830d72adb8db2f8347f500 Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 23 Mar 2005 17:28:46 +0000 Subject: ensure we are in the correct directory; the working directory is changed during execution of the test suite! git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3098 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 221336336..e3764adfb 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -167,6 +167,9 @@ class CustomTestCase(unittest.TestCase): raise self.failureException, \ (msg or '%s == %s' % _format_str(first, second)) + def setUp(self): + os.chdir(testroot) + # Synonyms for assertion methods assertEqual = assertEquals = failUnlessEqual -- cgit v1.2.1 From edc53d064c0242cf29ca1c683f52794132a48ded Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 24 Apr 2005 03:02:10 +0000 Subject: fixed typo git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3249 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e3764adfb..9c09792ae 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -807,7 +807,7 @@ def _format_str(*args): r = r[1:] # quote_char = "'" or '"' quote_char = r[0] - assert quote_char in ("'", "'") + assert quote_char in ("'", '"') assert r[0] == r[-1] r = r[1:-1] r = (stripped + 3 * quote_char + '\\\n' + -- cgit v1.2.1 From 03da26f3c9d0d99ea4afd99cf5330fe307ce3bb3 Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 24 Apr 2005 23:21:48 +0000 Subject: Added ``html_body``, ``html_title``, & ``html_subtitle`` to HTML writer parts dictionary exposed by ``docutils.core.publish_parts``; updated tests. Added "``publish_parts`` Details" section to docs/api/publish.txt. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3251 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 9c09792ae..40ac89c4f 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -742,6 +742,7 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): """Minimize & standardize the output.""" # remove redundant bits: del parts['whole'] + assert parts['body'] == parts['fragment'] del parts['body'] # remove standard bits: parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') -- cgit v1.2.1 From df86c29341bb830c87ee468323c1e3afa9d32a03 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 26 Apr 2005 03:57:00 +0000 Subject: Added ``html_prolog`` & ``html_head`` to HTML writer parts dictionary exposed by ``docutils.core.publish_parts``; updated tests & docs. At the request of Marcelo Huerta. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3257 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 40ac89c4f..87a200598 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -731,12 +731,17 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): expected = self.expected % {'version': docutils.__version__} self.compare_output(self.input, output, expected) - standard_meta_value = """\ + standard_meta_value_template = """\ -""" % docutils.__version__ +""" + standard_meta_value = standard_meta_value_template % docutils.__version__ standard_stylesheet_value = ('\n') + standard_html_prolog = """\ + + +""" def format_output(self, parts): """Minimize & standardize the output.""" @@ -748,6 +753,10 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') if parts['stylesheet'] == self.standard_stylesheet_value: del parts['stylesheet'] + parts['html_head'] = parts['html_head'].replace( + self.standard_meta_value, '...') + parts['html_prolog'] = parts['html_prolog'].replace( + self.standard_html_prolog, '') # remove empty values: for key in parts.keys(): if not parts[key]: -- cgit v1.2.1 From ce727c88d8d89f9f86275c0d3fca3ae2be392cec Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 27 Apr 2005 21:04:03 +0000 Subject: fixed encoding/charset values in "html_prolog" & "html_head" parts, which should not have been interpolated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3268 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 87a200598..d9f78f774 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -731,11 +731,16 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): expected = self.expected % {'version': docutils.__version__} self.compare_output(self.input, output, expected) - standard_meta_value_template = """\ - - -""" - standard_meta_value = standard_meta_value_template % docutils.__version__ + + standard_content_type_template = ('\n') + standard_generator_template = ( + '\n') + standard_html_meta_value = ( + standard_content_type_template + + standard_generator_template % docutils.__version__) + standard_meta_value = standard_html_meta_value % 'utf-8' standard_stylesheet_value = ('\n') standard_html_prolog = """\ @@ -745,16 +750,16 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): def format_output(self, parts): """Minimize & standardize the output.""" - # remove redundant bits: + # remove redundant parts: del parts['whole'] assert parts['body'] == parts['fragment'] del parts['body'] - # remove standard bits: + # remove standard portions: parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') if parts['stylesheet'] == self.standard_stylesheet_value: del parts['stylesheet'] parts['html_head'] = parts['html_head'].replace( - self.standard_meta_value, '...') + self.standard_html_meta_value, '...') parts['html_prolog'] = parts['html_prolog'].replace( self.standard_html_prolog, '') # remove empty values: -- cgit v1.2.1 From d90d048247c7f3012414659a52078b6c8a89765f Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Jun 2005 14:51:42 +0000 Subject: added deactivation of config file reading (for easier testing) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3511 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index d9f78f774..5aadf91bb 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -17,6 +17,7 @@ Exports the following: - `tableparser` is 'docutils.parsers.rst.tableparser' :Classes: + - `StandardTestCase` - `CustomTestCase` - `CustomTestSuite` - `TransformTestCase` @@ -88,16 +89,29 @@ class DevNull: pass -class CustomTestCase(unittest.TestCase): +class StandardTestCase(unittest.TestCase): + + """ + Helper class, providing the same interface as unittest.TestCase, + but with useful setUp and tearDown methods. + """ + + def setUp(self): + os.chdir(testroot) + frontend._globally_deactivate_config_files = 1 + + def tearDown(self): + frontend._globally_deactivate_config_files = 0 + + +class CustomTestCase(StandardTestCase): """ Helper class, providing extended functionality over unittest.TestCase. - This isn't specific to Docutils but of general use when dealing - with large amounts of text. The methods failUnlessEqual and - failIfEqual have been overwritten to provide better support for - multi-line strings. Furthermore, see the compare_output method - and the parameter list of __init__. + The methods failUnlessEqual and failIfEqual have been overwritten + to provide better support for multi-line strings. Furthermore, + see the compare_output method and the parameter list of __init__. """ compare = docutils_difflib.Differ().compare @@ -135,11 +149,11 @@ class CustomTestCase(unittest.TestCase): def compare_output(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" - if type(input) == UnicodeType: + if isinstance(input, UnicodeType): input = input.encode('raw_unicode_escape') - if type(output) == UnicodeType: + if isinstance(output, UnicodeType): output = output.encode('raw_unicode_escape') - if type(expected) == UnicodeType: + if isinstance(expected, UnicodeType): expected = expected.encode('raw_unicode_escape') try: self.assertEquals(output, expected) @@ -167,9 +181,6 @@ class CustomTestCase(unittest.TestCase): raise self.failureException, \ (msg or '%s == %s' % _format_str(first, second)) - def setUp(self): - os.chdir(testroot) - # Synonyms for assertion methods assertEqual = assertEquals = failUnlessEqual -- cgit v1.2.1 From 0b2a9c1f38b64f72e1d5e387bea0db076c1d8f13 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Jun 2005 18:25:59 +0000 Subject: simplified test code git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3516 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5aadf91bb..e37d8698b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -629,15 +629,19 @@ class PythonModuleParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): +class WriterPublishTestCase(CustomTestCase): """ Test case for publish. """ - settings_default_overrides = {'_disable_config': 1, 'strict_visitor': 1} writer_name = '' # override in subclasses + def __init__(self, *args, **kwargs): + self.writer_name = kwargs['writer_name'] + del kwargs['writer_name'] + CustomTestCase.__init__(self, *args, **kwargs) + def test_publish(self): if self.run_in_debugger: pdb.set_trace() @@ -646,34 +650,19 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): reader_name='standalone', parser_name='restructuredtext', writer_name=self.writer_name, - settings_spec=self) + settings_overrides={'strict_visitor': 1}) self.compare_output(self.input, output, self.expected) -class LatexWriterPublishTestCase(WriterPublishTestCase): - """Test case for Latex writer.""" - writer_name = 'latex' - - -class PseudoXMLWriterPublishTestCase(WriterPublishTestCase): - """Test case for pseudo-XML writer.""" - writer_name = 'pseudoxml' - - class PublishTestSuite(CustomTestSuite): - TEST_CLASSES = { - 'latex': LatexWriterPublishTestCase, - 'pseudoxml': PseudoXMLWriterPublishTestCase, - } - def __init__(self, writer_name): """ - `writer_name` is the name of the writer - to use. It must be a key in `TEST_CLASSES`. + `writer_name` is the name of the writer to use. """ CustomTestSuite.__init__(self) - self.test_class = self.TEST_CLASSES[writer_name] + self.test_class = WriterPublishTestCase + self.writer_name = writer_name def generateTests(self, dict, dictname='totest'): for name, cases in dict.items(): @@ -689,7 +678,9 @@ class PublishTestSuite(CustomTestSuite): self.test_class, 'test_publish', input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), - run_in_debugger=run_in_debugger) + run_in_debugger=run_in_debugger, + # Passed to constructor of self.test_class: + writer_name=self.writer_name) class HtmlPublishPartsTestSuite(CustomTestSuite): -- cgit v1.2.1 From 35f3e54cbfdeb7d4effa271bf0e7d07600ffd284 Mon Sep 17 00:00:00 2001 From: wiemann Date: Sun, 19 Jun 2005 18:31:28 +0000 Subject: fixed error git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3517 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index e37d8698b..3f459bebf 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -629,17 +629,19 @@ class PythonModuleParserTestSuite(CustomTestSuite): run_in_debugger=run_in_debugger) -class WriterPublishTestCase(CustomTestCase): +class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): """ Test case for publish. """ - writer_name = '' # override in subclasses + settings_default_overrides = {'strict_visitor': 1} + writer_name = '' # set in subclasses or constructor def __init__(self, *args, **kwargs): - self.writer_name = kwargs['writer_name'] - del kwargs['writer_name'] + if kwargs.has_key('writer_name'): + self.writer_name = kwargs['writer_name'] + del kwargs['writer_name'] CustomTestCase.__init__(self, *args, **kwargs) def test_publish(self): @@ -650,7 +652,7 @@ class WriterPublishTestCase(CustomTestCase): reader_name='standalone', parser_name='restructuredtext', writer_name=self.writer_name, - settings_overrides={'strict_visitor': 1}) + settings_spec=self) self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From 5eb7b3b1420555500ad3e2c8756f683175d17699 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 20 Jun 2005 21:52:53 +0000 Subject: ensure that always a stylesheet path/URL is given; I've seen to many poor-looking documents on the web due to the missing stylesheet -- people seem to miss that quite frequently git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3543 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 3f459bebf..f1fa277a7 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -713,6 +713,10 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): writer_name = 'html' + settings_default_overrides = \ + WriterPublishTestCase.settings_default_overrides.copy() + settings_default_overrides['stylesheet'] = None + def __init__(self, *args, **kwargs): self.settings_overrides = kwargs['settings_overrides'] """Settings overrides to use for this test case.""" -- cgit v1.2.1 From c04ee4d9948a2854fd9ea96eb9f1e22f56be29d5 Mon Sep 17 00:00:00 2001 From: wiemann Date: Tue, 21 Jun 2005 00:11:44 +0000 Subject: issue a warning rather than an error when no stylesheet is given; default for "stylesheet" is now None, not -1 git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3549 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index f1fa277a7..5452f1929 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -715,7 +715,7 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): settings_default_overrides = \ WriterPublishTestCase.settings_default_overrides.copy() - settings_default_overrides['stylesheet'] = None + settings_default_overrides['stylesheet'] = '' def __init__(self, *args, **kwargs): self.settings_overrides = kwargs['settings_overrides'] -- cgit v1.2.1 From 25934f67bf5d516f1bcdb32cc4d770f5d479d6fc Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 23 Jun 2005 17:35:19 +0000 Subject: removed docutils.frontend._globally_deactivate_config_files (reverting much of rev. 3511), since it duplicates settings._disable_config functionality git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3567 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5452f1929..32c263982 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -98,10 +98,6 @@ class StandardTestCase(unittest.TestCase): def setUp(self): os.chdir(testroot) - frontend._globally_deactivate_config_files = 1 - - def tearDown(self): - frontend._globally_deactivate_config_files = 0 class CustomTestCase(StandardTestCase): @@ -635,7 +631,8 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): Test case for publish. """ - settings_default_overrides = {'strict_visitor': 1} + settings_default_overrides = {'_disable_config': 1, + 'strict_visitor': 1} writer_name = '' # set in subclasses or constructor def __init__(self, *args, **kwargs): -- cgit v1.2.1 From fb247a2c98d8fffdca2a6ede5235f1b9e28a27ae Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 28 Jun 2005 13:49:10 +0000 Subject: Added ``_stylesheet_required`` internal setting, docutils.transforms.html.StylesheetCheck transform, docs, tests, and support. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3617 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 32c263982..72d5cdbc2 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -632,6 +632,7 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): """ settings_default_overrides = {'_disable_config': 1, + '_stylesheet_required': 0, 'strict_visitor': 1} writer_name = '' # set in subclasses or constructor -- cgit v1.2.1 From d04b3b06ae8404240bd8ab5cd22bebb34dfdb0f3 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 2 Jul 2005 23:08:53 +0000 Subject: revert docutils.writers.null.Writer.output to None, now with docutils.io.Output and test support git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3646 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 72d5cdbc2..c0c2c331b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -153,13 +153,19 @@ class CustomTestCase(StandardTestCase): expected = expected.encode('raw_unicode_escape') try: self.assertEquals(output, expected) - except AssertionError: + except AssertionError, error: print >>sys.stderr, '\n%s\ninput:' % (self,) print >>sys.stderr, input - print >>sys.stderr, '-: expected\n+: output' - print >>sys.stderr, ''.join(self.compare(expected.splitlines(1), - output.splitlines(1))) - raise + try: + comparison = ''.join(self.compare(expected.splitlines(1), + output.splitlines(1))) + print >>sys.stderr, '-: expected\n+: output' + print >>sys.stderr, comparison + except AttributeError: # expected or output not a string + # alternative output for non-strings: + print >>sys.stderr, 'expected: %r' % expected + print >>sys.stderr, 'output: %r' % output + raise error def failUnlessEqual(self, first, second, msg=None): """Fail if the two objects are unequal as determined by the '==' @@ -819,8 +825,8 @@ def _format_str(*args): return_tuple = [] for i in args: r = repr(i) - if '\n' in i and (isinstance(i, StringType) or - isinstance(i, UnicodeType)): + if ( (isinstance(i, StringType) or isinstance(i, UnicodeType)) + and '\n' in i): stripped = '' if isinstance(i, UnicodeType): # stripped = 'u' or 'U' -- cgit v1.2.1 From 4687626a27fc714d021060ad45f4477c6dd904c8 Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 6 Jul 2005 16:37:24 +0000 Subject: moved comparison methods up to StandardTestCase git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3662 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index c0c2c331b..0466590fd 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -93,12 +93,34 @@ class StandardTestCase(unittest.TestCase): """ Helper class, providing the same interface as unittest.TestCase, - but with useful setUp and tearDown methods. + but with useful setUp and comparison methods. """ def setUp(self): os.chdir(testroot) + def failUnlessEqual(self, first, second, msg=None): + """Fail if the two objects are unequal as determined by the '==' + operator. + """ + if not first == second: + raise self.failureException, \ + (msg or '%s != %s' % _format_str(first, second)) + + def failIfEqual(self, first, second, msg=None): + """Fail if the two objects are equal as determined by the '==' + operator. + """ + if first == second: + raise self.failureException, \ + (msg or '%s == %s' % _format_str(first, second)) + + # Synonyms for assertion methods + + assertEqual = assertEquals = failUnlessEqual + + assertNotEqual = assertNotEquals = failIfEqual + class CustomTestCase(StandardTestCase): @@ -167,28 +189,6 @@ class CustomTestCase(StandardTestCase): print >>sys.stderr, 'output: %r' % output raise error - def failUnlessEqual(self, first, second, msg=None): - """Fail if the two objects are unequal as determined by the '==' - operator. - """ - if not first == second: - raise self.failureException, \ - (msg or '%s != %s' % _format_str(first, second)) - - def failIfEqual(self, first, second, msg=None): - """Fail if the two objects are equal as determined by the '==' - operator. - """ - if first == second: - raise self.failureException, \ - (msg or '%s == %s' % _format_str(first, second)) - - # Synonyms for assertion methods - - assertEqual = assertEquals = failUnlessEqual - - assertNotEqual = assertNotEquals = failIfEqual - class CustomTestSuite(unittest.TestSuite): -- cgit v1.2.1 From 5c90ddc006b36818e727b4a42196a708b2a78a25 Mon Sep 17 00:00:00 2001 From: wiemann Date: Wed, 24 Aug 2005 21:33:21 +0000 Subject: made _stylesheet_required setting default to 0, activating it in the rst2html.py front-end tool git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3830 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 - 1 file changed, 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 0466590fd..ba4a14f81 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -638,7 +638,6 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): """ settings_default_overrides = {'_disable_config': 1, - '_stylesheet_required': 0, 'strict_visitor': 1} writer_name = '' # set in subclasses or constructor -- cgit v1.2.1 From 954c213bb271a9a2b91e694c8fbf155925dd9f4e Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 15 Sep 2005 14:16:33 +0000 Subject: Added support for specifying runtime settings at the suite level git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3879 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index ba4a14f81..ea1672d1b 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -135,7 +135,8 @@ class CustomTestCase(StandardTestCase): compare = docutils_difflib.Differ().compare """Comparison method shared by all subclasses.""" - def __init__(self, method_name, input, expected, id, run_in_debugger=0): + def __init__(self, method_name, input, expected, id, run_in_debugger=0, + suite_settings=None): """ Initialise the CustomTestCase. @@ -146,11 +147,13 @@ class CustomTestCase(StandardTestCase): expected -- expected output from the parser. id -- unique test identifier, used by the test framework. run_in_debugger -- if true, run this test under the pdb debugger. + suite_settings -- settings overrides for this test suite. """ self.id = id self.input = input self.expected = expected self.run_in_debugger = run_in_debugger + self.suite_settings = suite_settings or {} # Ring your mother. unittest.TestCase.__init__(self, method_name) @@ -205,15 +208,17 @@ class CustomTestSuite(unittest.TestSuite): next_test_case_id = 0 """The next identifier to use for non-identified test cases.""" - def __init__(self, tests=(), id=None): + def __init__(self, tests=(), id=None, suite_settings=None): """ Initialize the CustomTestSuite. Arguments: id -- identifier for the suite, prepended to test cases. + suite_settings -- settings overrides for this test suite. """ unittest.TestSuite.__init__(self, tests) + self.suite_settings = suite_settings or {} if id is None: mypath = os.path.abspath( sys.modules[CustomTestSuite.__module__].__file__) @@ -256,6 +261,9 @@ class CustomTestSuite(unittest.TestSuite): self.next_test_case_id += 1 # test identifier will become suiteid.testid tcid = '%s: %s' % (self.id, id) + # suite_settings may be passed as a parameter; + # if not, set from attribute: + kwargs.setdefault('suite_settings', self.suite_settings) # generate and add test case tc = test_case_class(method_name, input, expected, tcid, run_in_debugger=run_in_debugger, **kwargs) @@ -300,7 +308,9 @@ class TransformTestCase(CustomTestCase): def test_transforms(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document('test data', self.settings) + settings = self.settings.copy() + settings.__dict__.update(self.suite_settings) + document = utils.new_document('test data', settings) self.parser.parse(self.input, document) # Don't do a ``populate_from_components()`` because that would # enable the Transformer's default transforms. @@ -317,7 +327,9 @@ class TransformTestCase(CustomTestCase): print '\n', self.id print '-' * 70 print self.input - document = utils.new_document('test data', self.settings) + settings = self.settings.copy() + settings.__dict__.update(self.suite_settings) + document = utils.new_document('test data', settings) self.parser.parse(self.input, document) print '-' * 70 print document.pformat() @@ -339,11 +351,11 @@ class TransformTestSuite(CustomTestSuite): setUp and tearDown). """ - def __init__(self, parser): + def __init__(self, parser, suite_settings=None): self.parser = parser """Parser shared by all test cases.""" - CustomTestSuite.__init__(self) + CustomTestSuite.__init__(self, suite_settings=suite_settings) def generateTests(self, dict, dictname='totest', testmethod='test_transforms'): @@ -363,6 +375,11 @@ class TransformTestSuite(CustomTestSuite): case = cases[casenum] run_in_debugger = 0 if len(case)==3: + # TODO: (maybe) change the 3rd argument to a dict, so it + # can handle more cases by keyword ('disable', 'debug', + # 'settings'), here and in other generateTests methods. + # But there's also the method that + # HtmlPublishPartsTestSuite uses if case[2]: run_in_debugger = 1 else: @@ -397,7 +414,9 @@ class ParserTestCase(CustomTestCase): def test_parser(self): if self.run_in_debugger: pdb.set_trace() - document = utils.new_document('test data', self.settings) + settings = self.settings.copy() + settings.__dict__.update(self.suite_settings) + document = utils.new_document('test data', settings) # Remove any additions made by "role" directives: roles._roles = {} self.parser.parse(self.input, document) @@ -655,17 +674,18 @@ class WriterPublishTestCase(CustomTestCase, docutils.SettingsSpec): reader_name='standalone', parser_name='restructuredtext', writer_name=self.writer_name, - settings_spec=self) + settings_spec=self, + settings_overrides=self.suite_settings) self.compare_output(self.input, output, self.expected) class PublishTestSuite(CustomTestSuite): - def __init__(self, writer_name): + def __init__(self, writer_name, suite_settings=None): """ `writer_name` is the name of the writer to use. """ - CustomTestSuite.__init__(self) + CustomTestSuite.__init__(self, suite_settings=suite_settings) self.test_class = WriterPublishTestCase self.writer_name = writer_name @@ -692,6 +712,8 @@ class HtmlPublishPartsTestSuite(CustomTestSuite): def generateTests(self, dict, dictname='totest'): for name, (settings_overrides, cases) in dict.items(): + settings = self.suite_settings.copy() + settings.update(settings_overrides) for casenum in range(len(cases)): case = cases[casenum] run_in_debugger = 0 @@ -702,10 +724,10 @@ class HtmlPublishPartsTestSuite(CustomTestSuite): continue self.addTestCase( HtmlWriterPublishPartsTestCase, 'test_publish', - settings_overrides=settings_overrides, input=case[0], expected=case[1], id='%s[%r][%s]' % (dictname, name, casenum), - run_in_debugger=run_in_debugger) + run_in_debugger=run_in_debugger, + suite_settings=settings) class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): @@ -720,13 +742,6 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): WriterPublishTestCase.settings_default_overrides.copy() settings_default_overrides['stylesheet'] = '' - def __init__(self, *args, **kwargs): - self.settings_overrides = kwargs['settings_overrides'] - """Settings overrides to use for this test case.""" - - del kwargs['settings_overrides'] # only wanted here - CustomTestCase.__init__(self, *args, **kwargs) - def test_publish(self): if self.run_in_debugger: pdb.set_trace() @@ -736,7 +751,7 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): parser_name='restructuredtext', writer_name=self.writer_name, settings_spec=self, - settings_overrides=self.settings_overrides) + settings_overrides=self.suite_settings) output = self.format_output(parts) # interpolate standard variables: expected = self.expected % {'version': docutils.__version__} -- cgit v1.2.1 From 5da7532801abf44378d5422760ab68a84bc39fbc Mon Sep 17 00:00:00 2001 From: wiemann Date: Tue, 11 Oct 2005 23:00:39 +0000 Subject: removed references to default.css; to-do: update PEP writer (-> pep.css) and then docs/user/tools.txt git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3940 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index ea1672d1b..6947c4478 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -767,8 +767,6 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): standard_content_type_template + standard_generator_template % docutils.__version__) standard_meta_value = standard_html_meta_value % 'utf-8' - standard_stylesheet_value = ('\n') standard_html_prolog = """\ @@ -782,8 +780,6 @@ class HtmlWriterPublishPartsTestCase(WriterPublishTestCase): del parts['body'] # remove standard portions: parts['meta'] = parts['meta'].replace(self.standard_meta_value, '') - if parts['stylesheet'] == self.standard_stylesheet_value: - del parts['stylesheet'] parts['html_head'] = parts['html_head'].replace( self.standard_html_meta_value, '...') parts['html_prolog'] = parts['html_prolog'].replace( -- cgit v1.2.1 From 61fff66ccbdf0463f131340e2349e7042eb568a6 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 3 Dec 2005 02:11:03 +0000 Subject: set sys.path to pick up the right Docutils git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4131 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 6947c4478..5ad3673d4 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -43,6 +43,10 @@ __docformat__ = 'reStructuredText' import sys import os + +testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) +sys.path.insert(1, os.path.normpath(os.path.join(testroot, '..'))) + import unittest import docutils_difflib import inspect @@ -75,9 +79,6 @@ except: StringList.__repr__ = StringList.__str__ -testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) - - class DevNull: """Output sink.""" -- cgit v1.2.1 From 6e517e2f13176544d003efb786c3ab30ff8e87e6 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 14 Dec 2005 14:50:54 +0000 Subject: added path for extra modules (roman, optparse, textwrap) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4211 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 5ad3673d4..a3b93e364 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -46,6 +46,7 @@ import os testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) sys.path.insert(1, os.path.normpath(os.path.join(testroot, '..'))) +sys.path.append(os.path.normpath(os.path.join(testroot, '..', 'extras'))) import unittest import docutils_difflib -- cgit v1.2.1 From 3541047c4fbdb4c83e8cff7f257f565e354ba201 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 15 Dec 2005 03:09:04 +0000 Subject: path fixes git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4217 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index a3b93e364..758b86454 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -45,6 +45,7 @@ import sys import os testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) +os.chdir(testroot) sys.path.insert(1, os.path.normpath(os.path.join(testroot, '..'))) sys.path.append(os.path.normpath(os.path.join(testroot, '..', 'extras'))) -- cgit v1.2.1 From ce200099b841f02879d3d2496103521af3a4f413 Mon Sep 17 00:00:00 2001 From: wiemann Date: Thu, 15 Dec 2005 20:54:48 +0000 Subject: added absolute path of test root to sys.path because Py21/Py22 insert the *relative* path "test" at the beginning of sys.path when running "python2.2 test/alltests.py", which breaks the imports due to chdir; replaced os.path.sep with os.sep for Py21/Py22 compatibility git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4220 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 758b86454..c3c0aa2a2 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -46,7 +46,8 @@ import os testroot = os.path.abspath(os.path.dirname(__file__) or os.curdir) os.chdir(testroot) -sys.path.insert(1, os.path.normpath(os.path.join(testroot, '..'))) +sys.path.insert(0, os.path.normpath(os.path.join(testroot, '..'))) +sys.path.insert(0, testroot) sys.path.append(os.path.normpath(os.path.join(testroot, '..', 'extras'))) import unittest -- cgit v1.2.1 From 334b3eab36f78925c80149abec5352caedee4873 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 9 Jan 2006 03:06:58 +0000 Subject: moved clear_roles to DocutilsTestSupport.CustomTestCase so that it is used globally git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4254 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index c3c0aa2a2..1fbecbb32 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -172,6 +172,21 @@ class CustomTestCase(StandardTestCase): def __repr__(self): return "<%s %s>" % (self.id, unittest.TestCase.__repr__(self)) + def clear_roles(self): + # Language-specific roles and roles added by the + # "default-role" and "role" directives are currently stored + # globally in the roles._roles dictionary. This workaround + # empties that dictionary. + roles._roles = {} + + def setUp(self): + StandardTestCase.setUp(self) + self.clear_roles() + + def tearDown(self): + StandardTestCase.tearDown(self) + self.clear_roles() + def compare_output(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" if isinstance(input, UnicodeType): @@ -421,8 +436,6 @@ class ParserTestCase(CustomTestCase): settings = self.settings.copy() settings.__dict__.update(self.suite_settings) document = utils.new_document('test data', settings) - # Remove any additions made by "role" directives: - roles._roles = {} self.parser.parse(self.input, document) output = document.pformat() self.compare_output(self.input, output, self.expected) -- cgit v1.2.1 From d2bdd5c0e3514a7223cc454e89f6ab7d82b54beb Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 9 Jan 2006 03:29:23 +0000 Subject: some cleanup: removed unnecessary tearDown method; removed unnecessary roles parameter to Inliner.__init__ git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4258 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- test/DocutilsTestSupport.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'test/DocutilsTestSupport.py') diff --git a/test/DocutilsTestSupport.py b/test/DocutilsTestSupport.py index 1fbecbb32..c30b263d6 100644 --- a/test/DocutilsTestSupport.py +++ b/test/DocutilsTestSupport.py @@ -183,10 +183,6 @@ class CustomTestCase(StandardTestCase): StandardTestCase.setUp(self) self.clear_roles() - def tearDown(self): - StandardTestCase.tearDown(self) - self.clear_roles() - def compare_output(self, input, output, expected): """`input`, `output`, and `expected` should all be strings.""" if isinstance(input, UnicodeType): -- cgit v1.2.1