From b206ec0d03e3d28d810f20dfeffb48b962731c69 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 20 Nov 2014 20:36:22 -0500 Subject: Completed flake8 cleanup. I've decided to go with longer lines in the tests. Also fixed a couple errors with the previous cleanup. --- tests/test_apis.py | 304 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 203 insertions(+), 101 deletions(-) (limited to 'tests/test_apis.py') 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), - "

foo

") + self.assertEqual( + markdown.serializers.to_xhtml_string(root), + "

foo

" + ) 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()), - "

foo

bar

baz\n
") + self.assertEqual( + markdown.serializers.to_xhtml_string(tree.getroot()), + "

foo

bar

baz\n
" + ) 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', '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', '') + self.assertEqual( + markdown.serializers.to_html_string(self.comment), + '' + ) 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), - '\n') + self.assertEqual( + markdown.serializers.to_html_string(self.comment), + '\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), - '

foo


') + markdown.util.etree.SubElement(el, 'hr') + self.assertEqual( + markdown.serializers.to_html_string(el), + '

foo


' + ) 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), - '

foo


') + markdown.util.etree.SubElement(el, 'hr') + self.assertEqual( + markdown.serializers.to_xhtml_string(el), + '

foo


' + ) 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), - 'not valid html
') - + markdown.util.etree.SubElement(el, 'HR') + self.assertEqual( + markdown.serializers.to_xhtml_string(el), + 'not valid html
' + ) 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'), - '

foo

') + self.assertEqual( + markdown.markdown( + 'baz', extensions=[self.buildExtension()], output_format='fake' + ), + '

foo

' + ) 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), - '

some text

') + self.assertEqual( + markdown.serializers.to_html_string(new), + '

some text

' + ) 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), - '

some *text*

') + self.assertEqual( + markdown.serializers.to_html_string(new), + '

some *text*

' + ) 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), '

*some* *more* *text* *here* ' - '*to* *test* *with*

') + '*to* *test* *with*

' + ) + 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) -- cgit v1.2.3