diff options
Diffstat (limited to 'tests/test_apis.py')
-rw-r--r-- | tests/test_apis.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/tests/test_apis.py b/tests/test_apis.py index a5e0d73..e347cf9 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -40,6 +40,19 @@ class TestMarkdownBasics(unittest.TestCase): """ Test simple input. """ self.assertEqual(self.md.convert('foo'), '<p>foo</p>') + def testInstanceExtension(self): + """ Test Extension loading with a class instance. """ + from markdown.extensions.footnotes import FootnoteExtension + markdown.Markdown(extensions=[FootnoteExtension()]) + + def testNamedExtension(self): + """ Test Extension loading with Name (`path.to.module`). """ + markdown.Markdown(extensions=['markdown.extensions.footnotes']) + + def TestNamedExtensionWithClass(self): + """ Test Extension loading with class name (`path.to.module:Class`). """ + markdown.Markdown(extensions=['markdown.extensions.footnotes:FootnoteExtension']) + class TestBlockParser(unittest.TestCase): """ Tests of the BlockParser class. """ @@ -276,24 +289,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_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']) + 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) @@ -563,7 +585,7 @@ class TestCliOptionParsing(unittest.TestCase): 'end_url': '.html', 'html_class': 'test', }, - 'footnotes': { + 'footnotes:FootnotesExtension': { 'PLACE_MARKER': '~~~footnotes~~~' } } @@ -579,7 +601,7 @@ class TestCliOptionParsing(unittest.TestCase): 'end_url': '.html', 'html_class': 'test', }, - 'footnotes': { + 'footnotes:FootnotesExtension': { 'PLACE_MARKER': '~~~footnotes~~~' } } |