diff options
-rw-r--r-- | markdown/__init__.py | 4 | ||||
-rw-r--r-- | tests/test_apis.py | 15 |
2 files changed, 10 insertions, 9 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py index cbcee58..fdfe8b8 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -221,6 +221,10 @@ class Markdown(object): # Assume string uses dot syntax (`path.to.some.module`) module = importlib.import_module(ext_name) logger.debug('Successfuly imported extension module "%s".' % ext_name) + # For backward compat (until deprecation) check that this is an extension + if '.' not in ext_name and not (hasattr(module, 'extendMarkdown') or (class_name and hasattr(module, class_name))): + # We have a name conflict (eg: extensions=['tables'] and PyTables is installed) + raise ImportError except ImportError: # Preppend `markdown.extensions.` to name module_name = '.'.join(['markdown.extensions', ext_name]) diff --git a/tests/test_apis.py b/tests/test_apis.py index 34cd6f0..8cb2c66 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -289,25 +289,22 @@ class TestErrors(unittest.TestCase): def testLoadBadExtension(self): """ Test loading of an Extension with no makeExtension function. """ - _create_fake_extension(name='fake_a', has_factory_func=False) - self.assertRaises(AttributeError, markdown.Markdown, extensions=['fake_a']) + self.assertRaises(AttributeError, markdown.Markdown, extensions=['markdown.util']) def testNonExtension(self): """ Test loading a non Extension object as an extension. """ - _create_fake_extension(name='fake_b', is_wrong_type=True) - self.assertRaises(TypeError, markdown.Markdown, extensions=['fake_b']) + self.assertRaises(TypeError, markdown.Markdown, extensions=[object]) def testBaseExtention(self): """ Test that the base Extension class will raise NotImplemented. """ - _create_fake_extension(name='fake_c') self.assertRaises(NotImplementedError, - markdown.Markdown, extensions=['fake_c']) + markdown.Markdown, extensions=[markdown.extensions.Extension()]) def testMdxExtention(self): """ Test that appending mdx_ raises a PendingDeprecationWarning. """ - _create_fake_extension(name='fake_d', use_old_style=True) + _create_fake_extension(name='fake', use_old_style=True) self.assertRaises(PendingDeprecationWarning, - markdown.Markdown, extensions=['fake_d']) + markdown.Markdown, extensions=['fake']) def testShortNameExtention(self): """ Test that using a short name raises a PendingDeprecationWarning. """ @@ -645,4 +642,4 @@ class TestCliOptionParsing(unittest.TestCase): PLACE_MARKER= ~~~footnotes~~~ """ self.create_config_file(config) - self.assertRaises(yaml.YAMLError, parse_options, ['-c', self.tempfile])
\ No newline at end of file + self.assertRaises(yaml.YAMLError, parse_options, ['-c', self.tempfile]) |