aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2014-08-27 13:34:19 -0400
committerWaylan Limberg <waylan.limberg@icloud.com>2014-08-27 13:34:19 -0400
commit44e718ed82ed4c8e8e0f0fe1dbdb73d441747b19 (patch)
tree4006dad4eb9fa86169ededd817ede082bf720270 /tests
parent8c29487fe973f9007510dd6c4f32083b8d4d0896 (diff)
downloadmarkdown-44e718ed82ed4c8e8e0f0fe1dbdb73d441747b19.tar.gz
markdown-44e718ed82ed4c8e8e0f0fe1dbdb73d441747b19.tar.bz2
markdown-44e718ed82ed4c8e8e0f0fe1dbdb73d441747b19.zip
Refactored extension importing.
We now use importlib which means we no longer support Python 2.6. Also, this refactor properly imports third party extensions which reside at the root of PYTHONPATH. Previously, either `markdown.extensions.` or `mdx_` would be appended to any extension name that did not contain a dot, which required third party extensions to either be in submodules or use the old `mdx_` naming convention. This commit is also in preperation for #336. It will now be much easier to deprecate (and later remove) support for the old ways of handling extension names.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_apis.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/test_apis.py b/tests/test_apis.py
index a5e0d73..f0c7f3d 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -276,24 +276,33 @@ class TestErrors(unittest.TestCase):
def testLoadBadExtension(self):
""" Test loading of an Extension with no makeExtension function. """
- _create_fake_extension(name='fake', has_factory_func=False)
- self.assertRaises(AttributeError, markdown.Markdown, extensions=['fake'])
+ _create_fake_extension(name='fake_a', has_factory_func=False)
+ self.assertRaises(AttributeError, markdown.Markdown, extensions=['fake_a'])
def testNonExtension(self):
""" Test loading a non Extension object as an extension. """
- _create_fake_extension(name='fake', is_wrong_type=True)
- self.assertRaises(TypeError, markdown.Markdown, extensions=['fake'])
+ _create_fake_extension(name='fake_b', is_wrong_type=True)
+ self.assertRaises(TypeError, markdown.Markdown, extensions=['fake_b'])
def testBaseExtention(self):
""" Test that the base Extension class will raise NotImplemented. """
- _create_fake_extension(name='fake')
+ _create_fake_extension(name='fake_c')
self.assertRaises(NotImplementedError,
- markdown.Markdown, extensions=['fake'])
+ markdown.Markdown, extensions=['fake_c'])
+
+ def testDotSyntaxExtention(self):
+ """ Test that dot syntax imports properly (not using mdx_). """
+ _create_fake_extension(name='fake_d', use_old_style=False)
+ self.assertRaises(NotImplementedError,
+ markdown.Markdown, extensions=['fake_d'])
-def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False):
+def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False, use_old_style=True):
""" Create a fake extension module for testing. """
- mod_name = '_'.join(['mdx', name])
+ if use_old_style:
+ mod_name = '_'.join(['mdx', name])
+ else:
+ mod_name = name
if not PY3:
# mod_name must be bytes in Python 2.x
mod_name = bytes(mod_name)