aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_apis.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2014-11-20 20:36:22 -0500
committerWaylan Limberg <waylan.limberg@icloud.com>2014-11-20 20:36:22 -0500
commitb206ec0d03e3d28d810f20dfeffb48b962731c69 (patch)
treeb3f079a60ef2eaf5b73ff7e44d2d1eca252926e2 /tests/test_apis.py
parent8f66a94eab1389d97041944ed24afd2bf7c4389c (diff)
downloadmarkdown-b206ec0d03e3d28d810f20dfeffb48b962731c69.tar.gz
markdown-b206ec0d03e3d28d810f20dfeffb48b962731c69.tar.bz2
markdown-b206ec0d03e3d28d810f20dfeffb48b962731c69.zip
Completed flake8 cleanup.
I've decided to go with longer lines in the tests. Also fixed a couple errors with the previous cleanup.
Diffstat (limited to 'tests/test_apis.py')
-rw-r--r--tests/test_apis.py304
1 files changed, 203 insertions, 101 deletions
diff --git a/tests/test_apis.py b/tests/test_apis.py
index f89dba9..769ac83 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -21,6 +21,7 @@ import tempfile
PY3 = sys.version_info[0] == 3
+
class TestMarkdownBasics(unittest.TestCase):
""" Tests basics of the Markdown class. """
@@ -53,6 +54,7 @@ class TestMarkdownBasics(unittest.TestCase):
""" 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. """
@@ -65,8 +67,10 @@ class TestBlockParser(unittest.TestCase):
root = markdown.util.etree.Element("div")
text = 'foo'
self.parser.parseChunk(root, text)
- self.assertEqual(markdown.serializers.to_xhtml_string(root),
- "<div><p>foo</p></div>")
+ self.assertEqual(
+ markdown.serializers.to_xhtml_string(root),
+ "<div><p>foo</p></div>"
+ )
def testParseDocument(self):
""" Test BlockParser.parseDocument. """
@@ -74,8 +78,10 @@ class TestBlockParser(unittest.TestCase):
tree = self.parser.parseDocument(lines)
self.assertTrue(isinstance(tree, markdown.util.etree.ElementTree))
self.assertTrue(markdown.util.etree.iselement(tree.getroot()))
- self.assertEqual(markdown.serializers.to_xhtml_string(tree.getroot()),
- "<div><h1>foo</h1><p>bar</p><pre><code>baz\n</code></pre></div>")
+ self.assertEqual(
+ markdown.serializers.to_xhtml_string(tree.getroot()),
+ "<div><h1>foo</h1><p>bar</p><pre><code>baz\n</code></pre></div>"
+ )
class TestBlockParserState(unittest.TestCase):
@@ -115,9 +121,10 @@ class TestBlockParserState(unittest.TestCase):
self.state.reset()
self.assertEqual(self.state, ['state1'])
+
class TestHtmlStash(unittest.TestCase):
""" Test Markdown's HtmlStash. """
-
+
def setUp(self):
self.stash = markdown.util.HtmlStash()
self.placeholder = self.stash.store('foo')
@@ -133,14 +140,18 @@ class TestHtmlStash(unittest.TestCase):
placeholder = self.stash.store('bar')
self.assertEqual(placeholder, self.stash.get_placeholder(1))
self.assertEqual(self.stash.html_counter, 2)
- self.assertEqual(self.stash.rawHtmlBlocks,
- [('foo', False), ('bar', False)])
+ self.assertEqual(
+ self.stash.rawHtmlBlocks,
+ [('foo', False), ('bar', False)]
+ )
def testSafeStore(self):
""" Test HtmlStash.store with 'safe' html. """
self.stash.store('bar', True)
- self.assertEqual(self.stash.rawHtmlBlocks,
- [('foo', False), ('bar', True)])
+ self.assertEqual(
+ self.stash.rawHtmlBlocks,
+ [('foo', False), ('bar', True)]
+ )
def testReset(self):
""" Test HtmlStash.reset. """
@@ -184,49 +195,86 @@ class TestOrderedDict(unittest.TestCase):
def testKeys(self):
""" Test output of OrderedDict.keys(). """
- self.assertEqual(list(self.odict.keys()),
- ['first', 'third', 'fourth', 'fifth'])
+ self.assertEqual(
+ list(self.odict.keys()),
+ ['first', 'third', 'fourth', 'fifth']
+ )
def testItems(self):
""" Test output of OrderedDict.items(). """
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test')
+ ]
+ )
def testAddBefore(self):
""" Test adding an OrderedDict item before a given key. """
self.odict.add('second', 'is', '<third')
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('second', 'is'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('second', 'is'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test')
+ ]
+ )
def testAddAfter(self):
""" Test adding an OrderDict item after a given key. """
self.odict.add('second', 'is', '>first')
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('second', 'is'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('second', 'is'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test')
+ ]
+ )
def testAddAfterEnd(self):
""" Test adding an OrderedDict item after the last key. """
self.odict.add('sixth', '.', '>fifth')
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test'),
+ ('sixth', '.')
+ ]
+ )
def testAdd_begin(self):
""" Test adding an OrderedDict item using "_begin". """
self.odict.add('zero', 'CRAZY', '_begin')
- self.assertEqual(list(self.odict.items()),
- [('zero', 'CRAZY'), ('first', 'This'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('zero', 'CRAZY'),
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test')
+ ]
+ )
def testAdd_end(self):
""" Test adding an OrderedDict item using "_end". """
self.odict.add('sixth', '.', '_end')
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test'),
+ ('sixth', '.')
+ ]
+ )
def testAddBadLocation(self):
""" Test Error on bad location in OrderedDict.add(). """
@@ -236,30 +284,48 @@ class TestOrderedDict(unittest.TestCase):
def testDeleteItem(self):
""" Test deletion of an OrderedDict item. """
del self.odict['fourth']
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()),
+ [('first', 'This'), ('third', 'a'), ('fifth', 'test')]
+ )
def testChangeValue(self):
""" Test OrderedDict change value. """
self.odict['fourth'] = 'CRAZY'
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'),
- ('fourth', 'CRAZY'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'CRAZY'),
+ ('fifth', 'test')
+ ]
+ )
def testChangeOrder(self):
""" Test OrderedDict change order. """
self.odict.link('fourth', '<third')
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('fourth', 'self'),
- ('third', 'a'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('fourth', 'self'),
+ ('third', 'a'),
+ ('fifth', 'test')
+ ]
+ )
def textBadLink(self):
""" Test OrderedDict change order with bad location. """
self.assertRaises(ValueError, self.odict.link('fourth', '<bad'))
# Check for data integrity ("fourth" wasn't deleted).'
- self.assertEqual(list(self.odict.items()),
- [('first', 'This'), ('third', 'a'),
- ('fourth', 'self'), ('fifth', 'test')])
+ self.assertEqual(
+ list(self.odict.items()), [
+ ('first', 'This'),
+ ('third', 'a'),
+ ('fourth', 'self'),
+ ('fifth', 'test')
+ ]
+ )
+
class TestErrors(unittest.TestCase):
""" Test Error Reporting. """
@@ -275,7 +341,7 @@ class TestErrors(unittest.TestCase):
def testNonUnicodeSource(self):
""" Test falure on non-unicode source text. """
if sys.version_info < (3, 0):
- source = "foo".encode('utf-16')
+ source = "foo".encode('utf-16')
self.assertRaises(UnicodeDecodeError, markdown.markdown, source)
def testBadOutputFormat(self):
@@ -284,8 +350,10 @@ class TestErrors(unittest.TestCase):
def testLoadExtensionFailure(self):
""" Test failure of an extension to load. """
- self.assertRaises(ImportError,
- markdown.Markdown, extensions=['non_existant_ext'])
+ self.assertRaises(
+ ImportError,
+ markdown.Markdown, extensions=['non_existant_ext']
+ )
def testLoadBadExtension(self):
""" Test loading of an Extension with no makeExtension function. """
@@ -297,24 +365,32 @@ class TestErrors(unittest.TestCase):
def testBaseExtention(self):
""" Test that the base Extension class will raise NotImplemented. """
- self.assertRaises(NotImplementedError,
- markdown.Markdown, extensions=[markdown.extensions.Extension()])
+ self.assertRaises(
+ NotImplementedError,
+ markdown.Markdown, extensions=[markdown.extensions.Extension()]
+ )
def testMdxExtention(self):
""" Test that appending mdx_ raises a PendingDeprecationWarning. """
_create_fake_extension(name='fake', use_old_style=True)
- self.assertRaises(PendingDeprecationWarning,
- markdown.Markdown, extensions=['fake'])
+ self.assertRaises(
+ PendingDeprecationWarning,
+ markdown.Markdown, extensions=['fake']
+ )
def testShortNameExtention(self):
""" Test that using a short name raises a PendingDeprecationWarning. """
- self.assertRaises(PendingDeprecationWarning,
- markdown.Markdown, extensions=['footnotes'])
+ self.assertRaises(
+ PendingDeprecationWarning,
+ markdown.Markdown, extensions=['footnotes']
+ )
def testStringConfigExtention(self):
""" Test that passing configs to an Extension in the name raises a PendingDeprecationWarning. """
- self.assertRaises(PendingDeprecationWarning,
- markdown.Markdown, extensions=['markdown.extension.footnotes(PLACE_MARKER=FOO)'])
+ self.assertRaises(
+ PendingDeprecationWarning,
+ markdown.Markdown, extensions=['markdown.extension.footnotes(PLACE_MARKER=FOO)']
+ )
def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False, use_old_style=False):
@@ -327,21 +403,23 @@ def _create_fake_extension(name, has_factory_func=True, is_wrong_type=False, use
# mod_name must be bytes in Python 2.x
mod_name = bytes(mod_name)
ext_mod = types.ModuleType(mod_name)
+
def makeExtension(*args, **kwargs):
if is_wrong_type:
return object
else:
return markdown.extensions.Extension(*args, **kwargs)
+
if has_factory_func:
ext_mod.makeExtension = makeExtension
- # Warning: this brute forces the extenson module onto the system. Either
- # this needs to be specificly overriden or a new python session needs to
+ # Warning: this brute forces the extenson module onto the system. Either
+ # this needs to be specificly overriden or a new python session needs to
# be started to get rid of this. This should be ok in a testing context.
- sys.modules[mod_name] = ext_mod
+ sys.modules[mod_name] = ext_mod
class testETreeComments(unittest.TestCase):
- """
+ """
Test that ElementTree Comments work.
These tests should only be a concern when using cElementTree with third
@@ -369,15 +447,19 @@ class testETreeComments(unittest.TestCase):
def testCommentSerialization(self):
""" Test that an ElementTree Comment serializes properly. """
- self.assertEqual(markdown.serializers.to_html_string(self.comment),
- '<!--foo-->')
+ self.assertEqual(
+ markdown.serializers.to_html_string(self.comment),
+ '<!--foo-->'
+ )
def testCommentPrettify(self):
""" Test that an ElementTree Comment is prettified properly. """
pretty = markdown.treeprocessors.PrettifyTreeprocessor()
pretty.run(self.comment)
- self.assertEqual(markdown.serializers.to_html_string(self.comment),
- '<!--foo-->\n')
+ self.assertEqual(
+ markdown.serializers.to_html_string(self.comment),
+ '<!--foo-->\n'
+ )
class testElementTailTests(unittest.TestCase):
@@ -402,18 +484,22 @@ class testSerializers(unittest.TestCase):
el = markdown.util.etree.Element('div')
p = markdown.util.etree.SubElement(el, 'p')
p.text = 'foo'
- hr = markdown.util.etree.SubElement(el, 'hr')
- self.assertEqual(markdown.serializers.to_html_string(el),
- '<div><p>foo</p><hr></div>')
+ markdown.util.etree.SubElement(el, 'hr')
+ self.assertEqual(
+ markdown.serializers.to_html_string(el),
+ '<div><p>foo</p><hr></div>'
+ )
def testXhtml(self):
"""" Test XHTML serialization. """
el = markdown.util.etree.Element('div')
p = markdown.util.etree.SubElement(el, 'p')
p.text = 'foo'
- hr = markdown.util.etree.SubElement(el, 'hr')
- self.assertEqual(markdown.serializers.to_xhtml_string(el),
- '<div><p>foo</p><hr /></div>')
+ markdown.util.etree.SubElement(el, 'hr')
+ self.assertEqual(
+ markdown.serializers.to_xhtml_string(el),
+ '<div><p>foo</p><hr /></div>'
+ )
def testMixedCaseTags(self):
"""" Test preservation of tag case. """
@@ -421,10 +507,11 @@ class testSerializers(unittest.TestCase):
el.text = 'not valid '
em = markdown.util.etree.SubElement(el, 'EMPHASIS')
em.text = 'html'
- hr = markdown.util.etree.SubElement(el, 'HR')
- self.assertEqual(markdown.serializers.to_xhtml_string(el),
- '<MixedCase>not valid <EMPHASIS>html</EMPHASIS><HR /></MixedCase>')
-
+ markdown.util.etree.SubElement(el, 'HR')
+ self.assertEqual(
+ markdown.serializers.to_xhtml_string(el),
+ '<MixedCase>not valid <EMPHASIS>html</EMPHASIS><HR /></MixedCase>'
+ )
def buildExtension(self):
""" Build an extension which registers fakeSerializer. """
@@ -439,9 +526,12 @@ class testSerializers(unittest.TestCase):
return registerFakeSerializer()
def testRegisterSerializer(self):
- self.assertEqual(markdown.markdown('baz',
- extensions=[self.buildExtension()], output_format='fake'),
- '<p>foo</p>')
+ self.assertEqual(
+ markdown.markdown(
+ 'baz', extensions=[self.buildExtension()], output_format='fake'
+ ),
+ '<p>foo</p>'
+ )
class testAtomicString(unittest.TestCase):
@@ -457,8 +547,10 @@ class testAtomicString(unittest.TestCase):
p = markdown.util.etree.SubElement(tree, 'p')
p.text = 'some *text*'
new = self.inlineprocessor.run(tree)
- self.assertEqual(markdown.serializers.to_html_string(new),
- '<div><p>some <em>text</em></p></div>')
+ self.assertEqual(
+ markdown.serializers.to_html_string(new),
+ '<div><p>some <em>text</em></p></div>'
+ )
def testSimpleAtomicString(self):
""" Test that a simple AtomicString is not parsed. """
@@ -466,8 +558,10 @@ class testAtomicString(unittest.TestCase):
p = markdown.util.etree.SubElement(tree, 'p')
p.text = markdown.util.AtomicString('some *text*')
new = self.inlineprocessor.run(tree)
- self.assertEqual(markdown.serializers.to_html_string(new),
- '<div><p>some *text*</p></div>')
+ self.assertEqual(
+ markdown.serializers.to_html_string(new),
+ '<div><p>some *text*</p></div>'
+ )
def testNestedAtomicString(self):
""" Test that a nested AtomicString is not parsed. """
@@ -484,9 +578,12 @@ class testAtomicString(unittest.TestCase):
span2.tail = markdown.util.AtomicString(' *test*')
span1.tail = markdown.util.AtomicString(' *with*')
new = self.inlineprocessor.run(tree)
- self.assertEqual(markdown.serializers.to_html_string(new),
+ self.assertEqual(
+ markdown.serializers.to_html_string(new),
'<div><p>*some* <span>*more* <span>*text* <span>*here*</span> '
- '*to*</span> *test*</span> *with*</p></div>')
+ '*to*</span> *test*</span> *with*</p></div>'
+ )
+
class TestConfigParsing(unittest.TestCase):
def assertParses(self, value, result):
@@ -507,6 +604,7 @@ class TestConfigParsing(unittest.TestCase):
def testInvalidBooleansParsing(self):
self.assertRaises(ValueError, markdown.util.parseBoolValue, 'novalue')
+
class TestCliOptionParsing(unittest.TestCase):
""" Test parsing of Command Line Interface Options. """
@@ -519,7 +617,7 @@ class TestCliOptionParsing(unittest.TestCase):
'output_format': 'xhtml1',
'lazy_ol': True,
'extensions': [],
- 'extension_configs': {},
+ 'extension_configs': {},
}
self.tempfile = ''
@@ -531,7 +629,7 @@ class TestCliOptionParsing(unittest.TestCase):
options, logging_level = parse_options([])
self.assertEqual(options, self.default_options)
self.assertEqual(logging_level, CRITICAL)
-
+
def testQuietOption(self):
options, logging_level = parse_options(['-q'])
self.assertTrue(logging_level > CRITICAL)
@@ -586,10 +684,14 @@ class TestCliOptionParsing(unittest.TestCase):
self.assertEqual(options, self.default_options)
def testMultipleExtensionOptions(self):
- options, logging_level = parse_options(['-x', 'markdown.extensions.footnotes',
- '-x', 'markdown.extensions.smarty'])
- self.default_options['extensions'] = ['markdown.extensions.footnotes',
- 'markdown.extensions.smarty']
+ options, logging_level = parse_options([
+ '-x', 'markdown.extensions.footnotes',
+ '-x', 'markdown.extensions.smarty'
+ ])
+ self.default_options['extensions'] = [
+ 'markdown.extensions.footnotes',
+ 'markdown.extensions.smarty'
+ ]
self.assertEqual(options, self.default_options)
def create_config_file(self, config):
@@ -603,13 +705,13 @@ class TestCliOptionParsing(unittest.TestCase):
def testExtensionConfigOption(self):
config = {
- 'markdown.extensions.wikilinks': {
- 'base_url': 'http://example.com/',
- 'end_url': '.html',
- 'html_class': 'test',
+ 'markdown.extensions.wikilinks': {
+ 'base_url': 'http://example.com/',
+ 'end_url': '.html',
+ 'html_class': 'test',
},
- 'markdown.extensions.footnotes:FootnotesExtension': {
- 'PLACE_MARKER': '~~~footnotes~~~'
+ 'markdown.extensions.footnotes:FootnotesExtension': {
+ 'PLACE_MARKER': '~~~footnotes~~~'
}
}
self.create_config_file(config)
@@ -619,10 +721,10 @@ class TestCliOptionParsing(unittest.TestCase):
def textBoolExtensionConfigOption(self):
config = {
- 'markdown.extensions.toc': {
- 'title': 'Some Title',
- 'anchorlink': True,
- 'permalink': True
+ 'markdown.extensions.toc': {
+ 'title': 'Some Title',
+ 'anchorlink': True,
+ 'permalink': True
}
}
self.create_config_file(config)
@@ -632,13 +734,13 @@ class TestCliOptionParsing(unittest.TestCase):
def testExtensonConfigOptionAsJSON(self):
config = {
- 'markdown.extensions.wikilinks': {
- 'base_url': 'http://example.com/',
- 'end_url': '.html',
- 'html_class': 'test',
+ 'markdown.extensions.wikilinks': {
+ 'base_url': 'http://example.com/',
+ 'end_url': '.html',
+ 'html_class': 'test',
},
- 'markdown.extensions.footnotes:FootnotesExtension': {
- 'PLACE_MARKER': '~~~footnotes~~~'
+ 'markdown.extensions.footnotes:FootnotesExtension': {
+ 'PLACE_MARKER': '~~~footnotes~~~'
}
}
import json
@@ -652,7 +754,7 @@ class TestCliOptionParsing(unittest.TestCase):
def testExtensonConfigOptionBadFormat(self):
config = """
-[footnotes]
+[footnotes]
PLACE_MARKER= ~~~footnotes~~~
"""
self.create_config_file(config)