aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_extensions.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2014-07-31 22:40:33 -0400
committerWaylan Limberg <waylan@gmail.com>2014-07-31 22:40:33 -0400
commit47372051cf9724f1355b1c07c63c4beff9a5f626 (patch)
tree82130393bfa7118cab45a80579fbed2eeed05261 /tests/test_extensions.py
parentaae373860b5c5cbb40f126bf5acb9693dc577c4a (diff)
downloadmarkdown-47372051cf9724f1355b1c07c63c4beff9a5f626.tar.gz
markdown-47372051cf9724f1355b1c07c63c4beff9a5f626.tar.bz2
markdown-47372051cf9724f1355b1c07c63c4beff9a5f626.zip
Update extensions for Extension.__init__ refactor
Fixes #325. All extensions can now accept a dict of configs or **kwargs, not just a list of tuples. Third party extensions may want to follow suite. Extensions may only accept keyword arguments in the future. These changes still need to be documented. A couple things of note: The CodeHilite extension previously issued a DeprecationWarning if the old config key `force_linenos` was used. With thins change, a KeyError will now be raised. The `markdown.util.parseBoolValue` function gained a new argument: `preserve_none` (defaults to False), which when set to True, will pass None through unaltered (will not convert it to False).
Diffstat (limited to 'tests/test_extensions.py')
-rw-r--r--tests/test_extensions.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index e763576..b98295c 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -16,7 +16,10 @@ class TestExtensionClass(unittest.TestCase):
def setUp(self):
class TestExtension(markdown.extensions.Extension):
- config = {'foo': ['bar', 'Description of foo']}
+ config = {
+ 'foo': ['bar', 'Description of foo'],
+ 'bar': ['baz', 'Description of bar']
+ }
self.ext = TestExtension()
self.ExtKlass = TestExtension
@@ -29,38 +32,39 @@ class TestExtensionClass(unittest.TestCase):
self.assertEqual(self.ext.getConfig('baz', default='missing'), 'missing')
def testGetConfigs(self):
- self.assertEqual(self.ext.getConfigs(), {'foo': 'bar'})
+ self.assertEqual(self.ext.getConfigs(), {'foo': 'bar', 'bar': 'baz'})
def testGetConfigInfo(self):
- self.assertEqual(self.ext.getConfigInfo(), [('foo', 'Description of foo')])
+ self.assertEqual(self.ext.getConfigInfo(), [('foo', 'Description of foo'),
+ ('bar', 'Description of bar')])
def testSetConfig(self):
self.ext.setConfig('foo', 'baz')
- self.assertEqual(self.ext.getConfigs(), {'foo': 'baz'})
+ self.assertEqual(self.ext.getConfigs(), {'foo': 'baz', 'bar': 'baz'})
def testSetConfigWithBadKey(self):
# self.ext.setConfig('bad', 'baz) ==> KeyError
self.assertRaises(KeyError, self.ext.setConfig, 'bad', 'baz')
def testConfigAsArgListOnInit(self):
- ext = self.ExtKlass([('foo', 'baz')])
- self.assertEqual(ext.getConfigs(), {'foo': 'baz'})
+ ext = self.ExtKlass([('foo', 'baz'), ('bar', 'blah')])
+ self.assertEqual(ext.getConfigs(), {'foo': 'baz', 'bar': 'blah'})
def testConfigAsArgDictOnInit(self):
- ext = self.ExtKlass({'foo': 'baz'})
- self.assertEqual(ext.getConfigs(), {'foo': 'baz'})
+ ext = self.ExtKlass({'foo': 'baz', 'bar': 'blah', 'bar': 'blah'})
+ self.assertEqual(ext.getConfigs(), {'foo': 'baz', 'bar': 'blah'})
def testConfigAsKwargListOnInit(self):
- ext = self.ExtKlass(configs=[('foo', 'baz')])
- self.assertEqual(ext.getConfigs(), {'foo': 'baz'})
+ ext = self.ExtKlass(configs=[('foo', 'baz'), ('bar', 'blah')])
+ self.assertEqual(ext.getConfigs(), {'foo': 'baz', 'bar': 'blah'})
def testConfigAsKwargDictOnInit(self):
- ext = self.ExtKlass(configs={'foo': 'baz'})
- self.assertEqual(ext.getConfigs(), {'foo': 'baz'})
+ ext = self.ExtKlass(configs={'foo': 'baz', 'bar': 'blah'})
+ self.assertEqual(ext.getConfigs(), {'foo': 'baz', 'bar': 'blah'})
def testConfigAsKwargsOnInit(self):
- ext = self.ExtKlass(foo='baz')
- self.assertEqual(ext.getConfigs(), {'foo': 'baz'})
+ ext = self.ExtKlass(foo='baz', bar='blah')
+ self.assertEqual(ext.getConfigs(), {'foo': 'baz', 'bar': 'blah'})
class TestAbbr(unittest.TestCase):
@@ -515,11 +519,12 @@ Some text with a [[WikiLink]]."""
def testURLCallback(self):
""" Test used of a custom URL builder. """
+
+ from markdown.extensions.wikilinks import WikiLinkExtension
def my_url_builder(label, base, end):
return '/bar/'
- md = markdown.Markdown(extensions=['wikilinks'],
- extension_configs={'wikilinks' : [('build_url', my_url_builder)]})
+ md = markdown.Markdown(extensions=[WikiLinkExtension(build_url=my_url_builder)])
self.assertEqual(md.convert('[[foo]]'),
'<p><a class="wikilink" href="/bar/">foo</a></p>')