From 8f878c37dc3613b7279a0787bdcaf2d66b348d74 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 25 Sep 2014 22:26:07 -0400 Subject: Added a temp workwround for deprecated short ext names. As we chnaged the order in import trys for short names extensions (no dot syntax), an extra test was added to the import code for the occassion when a naming conflict exists. For example, if PyTables is installed (module name is tables) and the user tries to use the short name 'tables' instead of 'markdown.extensions.tables'. Fixes #341. Of course, this code will get ripped out when the old behavior is fully deprecated. --- markdown/__init__.py | 4 ++++ 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]) -- cgit v1.2.3