diff options
Diffstat (limited to 'docutils/test')
| -rw-r--r-- | docutils/test/DocutilsTestSupport.py | 27 | ||||
| -rwxr-xr-x | docutils/test/alltests.py | 32 | ||||
| -rw-r--r-- | docutils/test/package_unittest.py | 11 | ||||
| -rw-r--r-- | docutils/test/test_error_reporting.py | 10 | ||||
| -rwxr-xr-x | docutils/test/test_functional.py | 5 | ||||
| -rwxr-xr-x | docutils/test/test_io.py | 4 | ||||
| -rw-r--r-- | docutils/test/test_parsers/test_rst/test_directives/test_code.py | 14 | ||||
| -rw-r--r-- | docutils/test/test_parsers/test_rst/test_directives/test_code_long.py | 7 | ||||
| -rw-r--r-- | docutils/test/test_parsers/test_rst/test_directives/test_code_none.py | 4 | ||||
| -rwxr-xr-x | docutils/test/test_parsers/test_rst/test_doctest_blocks.py | 12 | ||||
| -rwxr-xr-x | docutils/test/test_settings.py | 9 | ||||
| -rwxr-xr-x | docutils/test/test_statemachine.py | 23 | ||||
| -rw-r--r-- | docutils/test/test_transforms/test_smartquotes.py | 10 | ||||
| -rw-r--r-- | docutils/test/test_transforms/test_strip_elements_with_class.py | 2 | ||||
| -rwxr-xr-x | docutils/test/test_viewlist.py | 14 |
15 files changed, 93 insertions, 91 deletions
diff --git a/docutils/test/DocutilsTestSupport.py b/docutils/test/DocutilsTestSupport.py index b6c3cdeca..479f0e073 100644 --- a/docutils/test/DocutilsTestSupport.py +++ b/docutils/test/DocutilsTestSupport.py @@ -38,6 +38,7 @@ Exports the following: - `HtmlFragmentTestSuite` - `DevNull` (output sink) """ +from __future__ import print_function __docformat__ = 'reStructuredText' import sys @@ -230,17 +231,17 @@ class CustomTestCase(StandardTestCase): try: self.assertEqual(output, expected) except AssertionError, error: - print >>sys.stderr, '\n%s\ninput:' % (self,) - print >>sys.stderr, input + print('\n%s\ninput:' % (self,), file=sys.stderr) + print(input, file=sys.stderr) try: comparison = ''.join(self.compare(expected.splitlines(1), output.splitlines(1))) - print >>sys.stderr, '-: expected\n+: output' - print >>sys.stderr, comparison + print('-: expected\n+: output', file=sys.stderr) + print(comparison, file=sys.stderr) 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 + print('expected: %r' % expected, file=sys.stderr) + print('output: %r' % output, file=sys.stderr) raise error @@ -375,20 +376,20 @@ class TransformTestCase(CustomTestCase): def test_transforms_verbosely(self): if self.run_in_debugger: pdb.set_trace() - print '\n', self.id - print '-' * 70 - print self.input + print('\n', self.id) + print('-' * 70) + print(self.input) 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() + print('-' * 70) + print(document.pformat()) for transformClass in self.transforms: transformClass(document).apply() output = document.pformat() - print '-' * 70 - print output + print('-' * 70) + print(output) self.compare_output(self.input, output, self.expected) diff --git a/docutils/test/alltests.py b/docutils/test/alltests.py index 183c5de77..231f288b3 100755 --- a/docutils/test/alltests.py +++ b/docutils/test/alltests.py @@ -1,12 +1,12 @@ #!/bin/sh ''''exec python -u "$0" "$@" #''' +from __future__ import print_function # $Id$ # Author: David Goodger <goodger@python.org> # Copyright: This module has been placed in the public domain. -__doc__ = \ -""" +__doc__ = """\ All modules named 'test_*.py' in the current directory, and recursively in subdirectories (packages) called 'test_*', are loaded and test suites within are run. @@ -15,7 +15,7 @@ are run. import time # Start point for actual elapsed time, including imports # and setup outside of unittest. -start = time.time() +start = time.time() # noqa import sys import atexit @@ -66,12 +66,13 @@ def pformat(suite): if line[-1:] == '[': indent += step else: - if line [-5:] == ']>]>,': + if line[-5:] == ']>]>,': indent -= step * 2 elif line[-3:] == ']>,': indent -= step return '\n'.join(output) + def suite(): path, script = os.path.split(sys.argv[0]) suite = package_unittest.loadTestModules(DocutilsTestSupport.testroot, @@ -79,26 +80,25 @@ def suite(): sys.stdout.flush() return suite + # must redirect stderr *before* first import of unittest sys.stdout = sys.stderr = Tee('alltests.out') -import package_unittest +import package_unittest # noqa if __name__ == '__main__': suite = suite() - print ('Testing Docutils %s with Python %s on %s at %s' - % (docutils.__version__, sys.version.split()[0], - time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S'))) - print ('OS: %s %s %s (%s, %s)' - % (platform.system(), platform.release(), platform.version(), - sys.platform, platform.platform())) - print 'Working directory: %s' % os.getcwd() - print 'Docutils package: %s' % os.path.dirname(docutils.__file__) + print('Testing Docutils %s with Python %s on %s at %s' % ( + docutils.__version__, sys.version.split()[0], + time.strftime('%Y-%m-%d'), time.strftime('%H:%M:%S'))) + print('OS: %s %s %s (%s, %s)' % ( + platform.system(), platform.release(), platform.version(), + sys.platform, platform.platform())) + print('Working directory: %s' % os.getcwd()) + print('Docutils package: %s' % os.path.dirname(docutils.__file__)) sys.stdout.flush() result = package_unittest.main(suite) - #if package_unittest.verbosity > 1: - # print >>sys.stderr, pformat(suite) # check the test suite finish = time.time() - print 'Elapsed time: %.3f seconds' % (finish - start) + print('Elapsed time: %.3f seconds' % (finish - start)) sys.exit(not result.wasSuccessful()) diff --git a/docutils/test/package_unittest.py b/docutils/test/package_unittest.py index 995547c19..1fb05aee5 100644 --- a/docutils/test/package_unittest.py +++ b/docutils/test/package_unittest.py @@ -9,6 +9,7 @@ This module extends unittest.py with `loadTestModules()`, by loading multiple test modules from a directory. Optionally, test packages are also loaded, recursively. """ +from __future__ import print_function import sys import os @@ -37,8 +38,8 @@ Options: def usageExit(msg=None): """Print usage and exit.""" if msg: - print msg - print USAGE + print(msg) + print(USAGE) sys.exit(2) def parseArgs(argv=sys.argv): @@ -96,11 +97,11 @@ def loadTestModules(path, name='', packages=None): sys.path.insert(0, path) for mod in testModules: if debug: - print >>sys.stderr, "importing %s" % mod + print("importing %s" % mod, file=sys.stderr) try: module = import_module(mod) except ImportError: - print >>sys.stderr, "ERROR: Can't import %s, skipping its tests:" % mod + print("ERROR: Can't import %s, skipping its tests:" % mod, file=sys.stderr) sys.excepthook(*sys.exc_info()) else: # if there's a suite defined, incorporate its contents @@ -148,7 +149,7 @@ def main(suite=None): suite = unittest.defaultTestLoader.loadTestsFromModule( __import__('__main__')) if debug: - print >>sys.stderr, "Debug: Suite=%s" % suite + print("Debug: Suite=%s" % suite, file=sys.stderr) testRunner = unittest.TextTestRunner(verbosity=verbosity) # run suites (if we were called from test_all) or suite... if type(suite) == type([]): diff --git a/docutils/test/test_error_reporting.py b/docutils/test/test_error_reporting.py index d62e6dbad..7239c44f7 100644 --- a/docutils/test/test_error_reporting.py +++ b/docutils/test/test_error_reporting.py @@ -20,13 +20,15 @@ instances like, e.g., :: try: something except IOError, error: - print 'Found %s' % error + print('Found %s' % error) unless the minimal required Python version has this problem fixed. """ +from __future__ import print_function import unittest -import sys, os +import os +import sys from io import StringIO, BytesIO import DocutilsTestSupport # must be imported before docutils @@ -39,8 +41,8 @@ if sys.version_info < (3, 0): # problems solved in py3k import locale # module missing in Jython oldlocale = locale.getlocale() except ImportError: - print ('cannot test error reporting with problematic locales,\n' - '`import locale` failed.') + print('cannot test error reporting with problematic locales,\n' + '`import locale` failed.') # locales confirmed to use non-ASCII chars in the IOError message diff --git a/docutils/test/test_functional.py b/docutils/test/test_functional.py index ca72b04a9..04fb0faeb 100755 --- a/docutils/test/test_functional.py +++ b/docutils/test/test_functional.py @@ -9,6 +9,7 @@ Perform tests with the data in the functional/ directory. Read README.txt for details on how this is done. """ +from __future__ import print_function import sys import os @@ -196,8 +197,8 @@ expected output and check it in: expected_path, params['destination_path'])) if sys.version_info < (3,0): diff = diff.encode(sys.stderr.encoding or 'ascii', 'replace') - print >>sys.stderr, '\n%s:' % (self,) - print >>sys.stderr, diff + print('\n%s:' % (self,), file=sys.stderr) + print(diff, file=sys.stderr) raise # Execute optional function containing extra tests: if '_test_more' in namespace: diff --git a/docutils/test/test_io.py b/docutils/test/test_io.py index 894e16430..0c8485fa5 100755 --- a/docutils/test/test_io.py +++ b/docutils/test/test_io.py @@ -69,7 +69,7 @@ blah input = io.StringInput(source=b"""\ #! python # -*- coding: ascii -*- -print "hello world" +print("hello world") """) data = input.read() self.assertEqual(input.successful_encoding, 'ascii') @@ -77,7 +77,7 @@ print "hello world" #! python # extraneous comment; prevents coding slug from being read # -*- coding: ascii -*- -print "hello world" +print("hello world") """) data = input.read() self.assertNotEqual(input.successful_encoding, 'ascii') diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code.py b/docutils/test/test_parsers/test_rst/test_directives/test_code.py index 25353fb3f..c9d2113fb 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_code.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_code.py @@ -98,7 +98,7 @@ totest['code-parsing'] = [ .. code:: python :class: testclass - print 'hello world' # to stdout + print('hello world') # to stdout """, """\ <document source="test data"> @@ -106,9 +106,12 @@ totest['code-parsing'] = [ \n\ <inline classes="keyword"> print - \n\ + <inline classes="punctuation"> + ( <inline classes="literal string single"> 'hello world' + <inline classes="punctuation"> + ) \n\ <inline classes="comment single"> # to stdout @@ -124,7 +127,7 @@ totest['code-parsing'] = [ ''' # and now for something completely different - print 8/2 + print(8/2) """, """\ <document source="test data"> @@ -163,13 +166,16 @@ totest['code-parsing'] = [ \n\ <inline classes="keyword"> print - \n\ + <inline classes="punctuation"> + ( <inline classes="literal number integer"> 8 <inline classes="operator"> / <inline classes="literal number integer"> 2 + <inline classes="punctuation"> + ) """], ["""\ .. code:: latex diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py index 58de6d180..21e21e5ed 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_long.py @@ -29,7 +29,7 @@ totest['code-parsing-long'] = [ ''' # and now for something completely different - print 8/2 + print(8/2) """, """\ <document source="test data"> @@ -68,13 +68,16 @@ totest['code-parsing-long'] = [ \n\ <inline classes="keyword"> print - \n\ + <inline classes="punctuation"> + ( <inline classes="literal number integer"> 8 <inline classes="operator"> / <inline classes="literal number integer"> 2 + <inline classes="punctuation"> + ) """], ["""\ .. code:: latex diff --git a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py index 4e0d056d6..23a611c0c 100644 --- a/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py +++ b/docutils/test/test_parsers/test_rst/test_directives/test_code_none.py @@ -37,7 +37,7 @@ totest['code-parsing-none'] = [ ''' # and now for something completely different - print 8/2 + print(8/2) """, """\ <document source="test data"> @@ -59,7 +59,7 @@ totest['code-parsing-none'] = [ # and now for something completely different <inline classes="ln"> 12 \n\ - print 8/2 + print(8/2) """], ["""\ .. code:: latex diff --git a/docutils/test/test_parsers/test_rst/test_doctest_blocks.py b/docutils/test/test_parsers/test_rst/test_doctest_blocks.py index 9de95a25a..fb733dba8 100755 --- a/docutils/test/test_parsers/test_rst/test_doctest_blocks.py +++ b/docutils/test/test_parsers/test_rst/test_doctest_blocks.py @@ -21,7 +21,7 @@ totest['doctest_blocks'] = [ ["""\ Paragraph. ->>> print "Doctest block." +>>> print("Doctest block.") Doctest block. Paragraph. @@ -31,7 +31,7 @@ Paragraph. <paragraph> Paragraph. <doctest_block xml:space="preserve"> - >>> print "Doctest block." + >>> print("Doctest block.") Doctest block. <paragraph> Paragraph. @@ -39,7 +39,7 @@ Paragraph. ["""\ Paragraph. ->>> print " Indented output." +>>> print(" Indented output.") Indented output. """, """\ @@ -47,13 +47,13 @@ Paragraph. <paragraph> Paragraph. <doctest_block xml:space="preserve"> - >>> print " Indented output." + >>> print(" Indented output.") Indented output. """], ["""\ Paragraph. - >>> print " Indented block & output." + >>> print(" Indented block & output.") Indented block & output. """, """\ @@ -62,7 +62,7 @@ Paragraph. Paragraph. <block_quote> <doctest_block xml:space="preserve"> - >>> print " Indented block & output." + >>> print(" Indented block & output.") Indented block & output. """], ] diff --git a/docutils/test/test_settings.py b/docutils/test/test_settings.py index 335167436..37698f7d6 100755 --- a/docutils/test/test_settings.py +++ b/docutils/test/test_settings.py @@ -8,6 +8,7 @@ """ Tests of runtime settings. """ +from __future__ import print_function import sys import os @@ -111,10 +112,10 @@ class ConfigFileTests(unittest.TestCase): try: self.assertEqual(result, expected) except AssertionError: - print >>sys.stderr, '\n%s\n' % (self,) - print >>sys.stderr, '-: expected\n+: result' - print >>sys.stderr, ''.join(self.compare(expected.splitlines(1), - result.splitlines(1))) + print('\n%s\n' % (self,), file=sys.stderr) + print('-: expected\n+: result', file=sys.stderr) + print(''.join(self.compare(expected.splitlines(1), + result.splitlines(1))), file=sys.stderr) raise def test_nofiles(self): diff --git a/docutils/test/test_statemachine.py b/docutils/test/test_statemachine.py index 31b20ca37..77dbd7029 100755 --- a/docutils/test/test_statemachine.py +++ b/docutils/test/test_statemachine.py @@ -7,6 +7,7 @@ """ Test module for statemachine.py. """ +from __future__ import print_function import unittest import sys @@ -56,47 +57,47 @@ class MockState(statemachine.StateWS): def bof(self, context): self.levelholder[0] += 1 self.level = self.levelholder[0] - if self.debug: print >>sys.stderr, 'StateMachine%s' % self.level + if self.debug: print('StateMachine%s' % self.level, file=sys.stderr) return [], ['StateMachine%s' % self.level] def blank(self, match, context, next_state): result = ['blank%s' % self.level] - if self.debug: print >>sys.stderr, 'blank%s' % self.level + if self.debug: print('blank%s' % self.level, file=sys.stderr) if context and context[-1] and context[-1][-2:] == '::': result.extend(self.literalblock()) return [], None, result def indent(self, match, context, next_state): - if self.debug: print >>sys.stderr, 'indent%s' % self.level + if self.debug: print('indent%s' % self.level, file=sys.stderr) context, next_state, result = statemachine.StateWS.indent( self, match, context, next_state) return context, next_state, ['indent%s' % self.level] + result def known_indent(self, match, context, next_state): - if self.debug: print >>sys.stderr, 'known_indent%s' % self.level + if self.debug: print('known_indent%s' % self.level, file=sys.stderr) context, next_state, result = statemachine.StateWS.known_indent( self, match, context, next_state) return context, next_state, ['known_indent%s' % self.level] + result def bullet(self, match, context, next_state): - if self.debug: print >>sys.stderr, 'bullet%s' % self.level + if self.debug: print('bullet%s' % self.level, file=sys.stderr) context, next_state, result \ = self.known_indent(match, context, next_state) return [], next_state, ['bullet%s' % self.level] + result def text(self, match, context, next_state): - if self.debug: print >>sys.stderr, 'text%s' % self.level + if self.debug: print('text%s' % self.level, file=sys.stderr) return [match.string], next_state, ['text%s' % self.level] def literalblock(self): indented, indent, offset, good = self.state_machine.get_indented() - if self.debug: print >>sys.stderr, 'literalblock%s(%s)' % (self.level, - indent) + if self.debug: print('literalblock%s(%s)' % (self.level, + indent), file=sys.stderr) return ['literalblock%s(%s)' % (self.level, indent)] def eof(self, context): self.levelholder[0] -= 1 - if self.debug: print >>sys.stderr, 'finished%s' % self.level + if self.debug: print('finished%s' % self.level, file=sys.stderr) return ['finished%s' % self.level] @@ -169,10 +170,10 @@ class SMWSTests(unittest.TestCase): self.assertTrue(good) self.sm.previous_line(3) if self.sm.debug: - print '\ntest_get_indented: self.sm.line:\n', self.sm.line + print('\ntest_get_indented: self.sm.line:\n', self.sm.line) indented, indent, offset, good = self.sm.get_indented() if self.sm.debug: - print '\ntest_get_indented: indented:\n', indented + print('\ntest_get_indented: indented:\n', indented) self.assertEqual(indent, lbindent) self.assertEqual(indented, literalblock) self.assertEqual(offset, (len(para1) + len(item1) + len(item2) diff --git a/docutils/test/test_transforms/test_smartquotes.py b/docutils/test/test_transforms/test_smartquotes.py index e65c5aa6f..9336838c5 100644 --- a/docutils/test/test_transforms/test_smartquotes.py +++ b/docutils/test/test_transforms/test_smartquotes.py @@ -18,7 +18,7 @@ Test module for universal.SmartQuotes transform. """ -from __init__ import DocutilsTestSupport # must be imported before docutils +from __init__ import DocutilsTestSupport # must be imported before docutils from docutils.transforms.universal import SmartQuotes from docutils.parsers.rst import Parser @@ -72,13 +72,13 @@ Do not "educate" quotes ``inside "literal" text`` and :: .. role:: python(code) :class: python -Keep quotes straight in code and math: +Keep quotes straight in code and math: :code:`print "hello"` :python:`print("hello")` :math:`1' 12"`. .. code:: - print "hello" - + print("hello") + .. math:: f'(x) = df(x)/dx @@ -105,7 +105,7 @@ u"""\ 1' 12" . <literal_block classes="code" xml:space="preserve"> - print "hello" + print("hello") <math_block xml:space="preserve"> f'(x) = df(x)/dx """], diff --git a/docutils/test/test_transforms/test_strip_elements_with_class.py b/docutils/test/test_transforms/test_strip_elements_with_class.py index bbb99cbb0..3c3f40aea 100644 --- a/docutils/test/test_transforms/test_strip_elements_with_class.py +++ b/docutils/test/test_transforms/test_strip_elements_with_class.py @@ -37,7 +37,7 @@ this is ham .. code:: :class: spam - print "spam" + print("spam") .. image:: spam.jpg :class: spam diff --git a/docutils/test/test_viewlist.py b/docutils/test/test_viewlist.py index 416915da5..00f36a255 100755 --- a/docutils/test/test_viewlist.py +++ b/docutils/test/test_viewlist.py @@ -9,8 +9,6 @@ Test module for the ViewList class from statemachine.py. """ import unittest -import sys -import re from DocutilsTestSupport import statemachine @@ -76,7 +74,6 @@ class ViewListTests(unittest.TestCase): self.assertEqual(a, a_list) self.assertEqual(a.items, [('a', i+1) for (i, v) in enumerate(a_list)]) self.assertEqual(a.parent, self.a) - # a.pprint() def test_set_slice(self): a = statemachine.ViewList(self.a[:]) @@ -84,8 +81,6 @@ class ViewListTests(unittest.TestCase): s[2:2] = self.b s_list = self.a_list[2:-2] s_list[2:2] = self.b_list - # s.pprint() - # s[1:4].pprint() self.assertEqual(s, s_list) self.assertEqual(s, a[2:-2]) self.assertEqual(s.items, a[2:-2].items) @@ -119,7 +114,6 @@ class ViewListTests(unittest.TestCase): a = statemachine.ViewList(self.a) a.append('Q', 'runtime') a.append(self.b) - # a.pprint() self.assertEqual(a, a_list) self.assertEqual(a.info(len(self.a)), ('runtime', 0)) self.assertEqual(a.info(-2), ('b', len(self.b) - 2)) @@ -131,7 +125,6 @@ class ViewListTests(unittest.TestCase): a.extend(self.b) self.assertEqual(a, a_list) self.assertEqual(a.info(len(self.a) + 1), ('b', 1)) - # a.pprint() def test_view(self): a = statemachine.ViewList(self.a[:]) @@ -176,16 +169,9 @@ class ViewListTests(unittest.TestCase): def test_sort(self): c = self.c[:] c.reverse() - # c.pprint() c.sort() self.assertEqual(self.c, c) -# print -# print a -# print s -# print a.items -# print s.items - class StringList(unittest.TestCase): |
