aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2012-12-14 13:31:41 -0500
committerWaylan Limberg <waylan@gmail.com>2012-12-14 13:31:41 -0500
commit9bcd7b8763627c64184b0bf147ec1830fde0a5dc (patch)
treec4ae05ca3e9bd76d9fb3120e0672bda29abec200
parenta974fd6e902ccc9e5b782707344d9af734b169b6 (diff)
downloadmarkdown-9bcd7b8763627c64184b0bf147ec1830fde0a5dc.tar.gz
markdown-9bcd7b8763627c64184b0bf147ec1830fde0a5dc.tar.bz2
markdown-9bcd7b8763627c64184b0bf147ec1830fde0a5dc.zip
Testing framework now runs on Python 2 & 3 unmodified.
-rw-r--r--fabfile.py3
-rw-r--r--tests/__init__.py20
-rw-r--r--tests/plugins.py4
-rw-r--r--tests/test_apis.py48
-rw-r--r--tests/test_extensions.py1
-rw-r--r--tests/util.py6
6 files changed, 46 insertions, 36 deletions
diff --git a/fabfile.py b/fabfile.py
index 16ceb1d..f9333e0 100644
--- a/fabfile.py
+++ b/fabfile.py
@@ -58,8 +58,7 @@ def build_tests(version=_pyversion[:3]):
if version.startswith('3'):
# Do 2to3 conversion
local('2to3-%s -w -d build/test.%s/markdown' % (version, version))
- local('2to3-%s -w build/test.%s/tests' % (version, version))
- local('2to3-%s -w build/test.%s/run-tests.py' % (version, version))
+
def generate_test(file):
""" Generate a given test. """
diff --git a/tests/__init__.py b/tests/__init__.py
index 4722e33..bb56bd4 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,4 +1,4 @@
-from __future__ import with_statement
+
import os
import markdown
import codecs
@@ -6,11 +6,11 @@ import difflib
try:
import nose
except ImportError:
- raise ImportError, "The nose testing framework is required to run " \
+ raise ImportError("The nose testing framework is required to run " \
"Python-Markdown tests. Run `easy_install nose` " \
- "to install the latest version."
-import util
-from plugins import HtmlOutput, Markdown
+ "to install the latest version.")
+from . import util
+from .plugins import HtmlOutput, Markdown
try:
import tidy
except ImportError:
@@ -84,7 +84,7 @@ class CheckSyntax(object):
""" Compare expected output to actual output and report result. """
cfg_section = get_section(file, config)
if config.get(cfg_section, 'skip'):
- raise nose.plugins.skip.SkipTest, 'Test skipped per config.'
+ raise nose.plugins.skip.SkipTest('Test skipped per config.')
input_file = file + config.get(cfg_section, 'input_ext')
with codecs.open(input_file, encoding="utf-8") as f:
input = f.read()
@@ -99,7 +99,7 @@ class CheckSyntax(object):
output = normalize(output)
elif config.get(cfg_section, 'normalize'):
# Tidy is not available. Skip this test.
- raise nose.plugins.skip.SkipTest, 'Test skipped. Tidy not available in system.'
+ raise nose.plugins.skip.SkipTest('Test skipped. Tidy not available in system.')
diff = [l for l in difflib.unified_diff(expected_output.splitlines(True),
output.splitlines(True),
output_file,
@@ -125,17 +125,17 @@ def generate(file, config):
""" Write expected output file for given input. """
cfg_section = get_section(file, config)
if config.get(cfg_section, 'skip'):
- print 'Skipping:', file
+ print('Skipping:', file)
return None
input_file = file + config.get(cfg_section, 'input_ext')
output_file = file + config.get(cfg_section, 'output_ext')
if not os.path.isfile(output_file) or \
os.path.getmtime(output_file) < os.path.getmtime(input_file):
- print 'Generating:', file
+ print('Generating:', file)
markdown.markdownFromFile(input=input_file, output=output_file,
encoding='utf-8', **get_args(file, config))
else:
- print 'Already up-to-date:', file
+ print('Already up-to-date:', file)
def generate_all():
""" Generate expected output for all outdated tests. """
diff --git a/tests/plugins.py b/tests/plugins.py
index 6e72024..bbeed60 100644
--- a/tests/plugins.py
+++ b/tests/plugins.py
@@ -1,5 +1,5 @@
import traceback
-from util import MarkdownSyntaxError
+from .util import MarkdownSyntaxError
from nose.plugins import Plugin
from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
@@ -73,7 +73,7 @@ or ""))
self.html.extend(['<span>FAILED (',
'failures=%d ' % len(result.failures),
'errors=%d' % len(result.errors)])
- for cls in result.errorClasses.keys():
+ for cls in list(result.errorClasses.keys()):
storage, label, isfail = result.errorClasses[cls]
if len(storage):
self.html.append(' %ss=%d' % (label, len(storage)))
diff --git a/tests/test_apis.py b/tests/test_apis.py
index b39664a..e0f7a03 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -7,6 +7,7 @@ Tests of the various APIs with the python markdown lib.
"""
+from __future__ import unicode_literals
import unittest
import os
import sys
@@ -14,6 +15,8 @@ import types
import markdown
import warnings
+PY3 = sys.version_info[0] == 3
+
class TestMarkdownBasics(unittest.TestCase):
""" Tests basics of the Markdown class. """
@@ -140,51 +143,51 @@ class TestOrderedDict(unittest.TestCase):
def testValues(self):
""" Test output of OrderedDict.values(). """
- self.assertEqual(self.odict.values(), ['This', 'a', 'self', 'test'])
+ self.assertEqual(list(self.odict.values()), ['This', 'a', 'self', 'test'])
def testKeys(self):
""" Test output of OrderedDict.keys(). """
- self.assertEqual(self.odict.keys(),
+ self.assertEqual(list(self.odict.keys()),
['first', 'third', 'fourth', 'fifth'])
def testItems(self):
""" Test output of OrderedDict.items(). """
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])
def testAddBefore(self):
""" Test adding an OrderedDict item before a given key. """
self.odict.add('second', 'is', '<third')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('second', 'is'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])
def testAddAfter(self):
""" Test adding an OrderDict item after a given key. """
self.odict.add('second', 'is', '>first')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('second', 'is'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])
def testAddAfterEnd(self):
""" Test adding an OrderedDict item after the last key. """
self.odict.add('sixth', '.', '>fifth')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
def testAdd_begin(self):
""" Test adding an OrderedDict item using "_begin". """
self.odict.add('zero', 'CRAZY', '_begin')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('zero', 'CRAZY'), ('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])
def testAdd_end(self):
""" Test adding an OrderedDict item using "_end". """
self.odict.add('sixth', '.', '_end')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
@@ -196,20 +199,20 @@ class TestOrderedDict(unittest.TestCase):
def testDeleteItem(self):
""" Test deletion of an OrderedDict item. """
del self.odict['fourth']
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'), ('fifth', 'test')])
def testChangeValue(self):
""" Test OrderedDict change value. """
self.odict['fourth'] = 'CRAZY'
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'),
('fourth', 'CRAZY'), ('fifth', 'test')])
def testChangeOrder(self):
""" Test OrderedDict change order. """
self.odict.link('fourth', '<third')
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('fourth', 'self'),
('third', 'a'), ('fifth', 'test')])
@@ -217,7 +220,7 @@ class TestOrderedDict(unittest.TestCase):
""" Test OrderedDict change order with bad location. """
self.assertRaises(ValueError, self.odict.link('fourth', '<bad'))
# Check for data integrity ("fourth" wasn't deleted).'
- self.assertEqual(self.odict.items(),
+ self.assertEqual(list(self.odict.items()),
[('first', 'This'), ('third', 'a'),
('fourth', 'self'), ('fifth', 'test')])
@@ -267,6 +270,9 @@ class TestErrors(unittest.TestCase):
def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False):
""" Create a fake extension module for testing. """
mod_name = '_'.join(['mdx', name])
+ if not PY3:
+ # mod_name must be bytes in Python 2.x
+ mod_name = bytes(mod_name)
ext_mod = types.ModuleType(mod_name)
def makeExtension(configs=None):
if is_wrong_type:
@@ -332,7 +338,7 @@ class testAtomicString(unittest.TestCase):
""" Test that a regular string is parsed. """
tree = markdown.util.etree.Element('div')
p = markdown.util.etree.SubElement(tree, 'p')
- p.text = u'some *text*'
+ p.text = 'some *text*'
new = self.inlineprocessor.run(tree)
self.assertEqual(markdown.serializers.to_html_string(new),
'<div><p>some <em>text</em></p></div>')
@@ -341,7 +347,7 @@ class testAtomicString(unittest.TestCase):
""" Test that a simple AtomicString is not parsed. """
tree = markdown.util.etree.Element('div')
p = markdown.util.etree.SubElement(tree, 'p')
- p.text = markdown.util.AtomicString(u'some *text*')
+ p.text = markdown.util.AtomicString('some *text*')
new = self.inlineprocessor.run(tree)
self.assertEqual(markdown.serializers.to_html_string(new),
'<div><p>some *text*</p></div>')
@@ -350,16 +356,16 @@ class testAtomicString(unittest.TestCase):
""" Test that a nested AtomicString is not parsed. """
tree = markdown.util.etree.Element('div')
p = markdown.util.etree.SubElement(tree, 'p')
- p.text = markdown.util.AtomicString(u'*some* ')
+ p.text = markdown.util.AtomicString('*some* ')
span1 = markdown.util.etree.SubElement(p, 'span')
- span1.text = markdown.util.AtomicString(u'*more* ')
+ span1.text = markdown.util.AtomicString('*more* ')
span2 = markdown.util.etree.SubElement(span1, 'span')
- span2.text = markdown.util.AtomicString(u'*text* ')
+ span2.text = markdown.util.AtomicString('*text* ')
span3 = markdown.util.etree.SubElement(span2, 'span')
- span3.text = markdown.util.AtomicString(u'*here*')
- span3.tail = markdown.util.AtomicString(u' *to*')
- span2.tail = markdown.util.AtomicString(u' *test*')
- span1.tail = markdown.util.AtomicString(u' *with*')
+ span3.text = markdown.util.AtomicString('*here*')
+ span3.tail = markdown.util.AtomicString(' *to*')
+ span2.tail = markdown.util.AtomicString(' *test*')
+ span1.tail = markdown.util.AtomicString(' *with*')
new = self.inlineprocessor.run(tree)
self.assertEqual(markdown.serializers.to_html_string(new),
'<div><p>*some* <span>*more* <span>*text* <span>*here*</span> '
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index b10414e..7dab60a 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -7,6 +7,7 @@ continue to work as advertised. This used to be accomplished by doctests.
"""
+from __future__ import unicode_literals
import unittest
import markdown
diff --git a/tests/util.py b/tests/util.py
index 6690eed..bbf7aea 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -1,4 +1,8 @@
-from ConfigParser import SafeConfigParser
+import sys
+if sys.version_info[0] == 3:
+ from configparser import SafeConfigParser
+else:
+ from ConfigParser import SafeConfigParser
class MarkdownSyntaxError(Exception):
pass