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. --- markdown/__init__.py | 2 +- markdown/extensions/admonition.py | 2 +- tests/test_apis.py | 304 +++++++++++++++++--------- tests/test_extensions.py | 435 ++++++++++++++++++++++++-------------- 4 files changed, 482 insertions(+), 261 deletions(-) diff --git a/markdown/__init__.py b/markdown/__init__.py index 0c4f271..12b53ba 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -32,7 +32,7 @@ License: BSD (see LICENSE for details). from __future__ import absolute_import from __future__ import unicode_literals -from .__version__ import version, version_info # flake8: noqa +from .__version__ import version, version_info # noqa import codecs import sys import logging diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py index 8fe3aee..87d8ec8 100644 --- a/markdown/extensions/admonition.py +++ b/markdown/extensions/admonition.py @@ -4,7 +4,7 @@ Admonition extension for Python-Markdown Adds rST-style admonitions. Inspired by [rST][] feature with the same name. -[rST]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions # flake8: noqa +[rST]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions # noqa See for documentation. 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) diff --git a/tests/test_extensions.py b/tests/test_extensions.py index efd9524..a037915 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -11,6 +11,7 @@ from __future__ import unicode_literals import unittest import markdown + class TestExtensionClass(unittest.TestCase): """ Test markdown.extensions.Extension. """ @@ -35,9 +36,13 @@ class TestExtensionClass(unittest.TestCase): self.assertEqual(self.ext.getConfigs(), {'foo': 'bar', 'bar': 'baz'}) def testGetConfigInfo(self): - self.assertEqual(dict(self.ext.getConfigInfo()), - dict([('foo', 'Description of foo'), - ('bar', 'Description of bar')])) + self.assertEqual( + dict(self.ext.getConfigInfo()), + dict([ + ('foo', 'Description of foo'), + ('bar', 'Description of bar') + ]) + ) def testSetConfig(self): self.ext.setConfig('foo', 'baz') @@ -63,18 +68,22 @@ class TestAbbr(unittest.TestCase): text = 'Some text with an ABBR and a REF. Ignore REFERENCE and ref.' + \ '\n\n*[ABBR]: Abbreviation\n' + \ '*[REF]: Abbreviation Reference' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

Some text with an ABBR ' 'and a REF. Ignore ' - 'REFERENCE and ref.

') + 'REFERENCE and ref.

' + ) def testNestedAbbr(self): """ Test Nested Abbreviations. """ text = '[ABBR](/foo) and _ABBR_\n\n' + \ '*[ABBR]: Abreviation' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

ABBR ' - 'and ABBR

') + 'and ABBR

' + ) class TestCodeHilite(unittest.TestCase): @@ -83,7 +92,7 @@ class TestCodeHilite(unittest.TestCase): def setUp(self): self.has_pygments = True try: - import pygments + import pygments # noqa except ImportError: self.has_pygments = False @@ -94,38 +103,49 @@ class TestCodeHilite(unittest.TestCase): # Pygments can use random lexer here as we did not specify the language self.assertTrue(md.convert(text).startswith('
'))
         else:
-            self.assertEqual(md.convert(text),
+            self.assertEqual(
+                md.convert(text),
                 '
# A Code Comment'
-                '
') - + '
' + ) + def testLinenumsTrue(self): text = '\t# A Code Comment' md = markdown.Markdown( extensions=[markdown.extensions.codehilite.CodeHiliteExtension(linenums=True)]) if self.has_pygments: # Different versions of pygments output slightly different markup. - # So we use 'startwith' and test just enough to confirm that + # So we use 'startwith' and test just enough to confirm that # pygments received and processed linenums. - self.assertTrue(md.convert(text).startswith( - '
')) + self.assertTrue( + md.convert(text).startswith( + '
' + ) + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
# A Code Comment'
-                '
') + '' + ) def testLinenumsFalse(self): text = '\t#!Python\n\t# A Code Comment' md = markdown.Markdown( extensions=[markdown.extensions.codehilite.CodeHiliteExtension(linenums=False)]) if self.has_pygments: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
' '
# A Code Comment\n'
-                '
') + '' + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
# A Code Comment'
-                '
') + '' + ) def testLinenumsNone(self): text = '\t# A Code Comment' @@ -135,9 +155,11 @@ class TestCodeHilite(unittest.TestCase): # Pygments can use random lexer here as we did not specify the language self.assertTrue(md.convert(text).startswith('
'))
         else:
-            self.assertEqual(md.convert(text),
+            self.assertEqual(
+                md.convert(text),
                 '
# A Code Comment'
-                '
') + '
' + ) def testLinenumsNoneWithShebang(self): text = '\t#!Python\n\t# A Code Comment' @@ -145,28 +167,38 @@ class TestCodeHilite(unittest.TestCase): extensions=[markdown.extensions.codehilite.CodeHiliteExtension(linenums=None)]) if self.has_pygments: # Differant versions of pygments output slightly different markup. - # So we use 'startwith' and test just enough to confirm that + # So we use 'startwith' and test just enough to confirm that # pygments received and processed linenums. - self.assertTrue(md.convert(text).startswith( - '
')) + self.assertTrue( + md.convert(text).startswith( + '
' + ) + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
# A Code Comment'
-                '
') + '' + ) def testLinenumsNoneWithColon(self): text = '\t:::Python\n\t# A Code Comment' md = markdown.Markdown( - extensions=[markdown.extensions.codehilite.CodeHiliteExtension(linenums=None)]) + extensions=[markdown.extensions.codehilite.CodeHiliteExtension(linenums=None)] + ) if self.has_pygments: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
' '
# A Code Comment\n'
-                '
') + '' + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
# A Code Comment'
-                '
') + '' + ) def testHighlightLinesWithColon(self): # Test with hl_lines delimited by single or double quotes. @@ -176,18 +208,23 @@ class TestCodeHilite(unittest.TestCase): for text in (text0, text1): md = markdown.Markdown(extensions=['markdown.extensions.codehilite']) if self.has_pygments: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
'
                     '#line 1\n'
                     '#line 2\n'
                     '#line 3\n'
-                    '
') + '' + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
'
                     '#line 1\n'
                     '#line 2\n'
-                    '#line 3
') + '#line 3' + ) + class TestFencedCode(unittest.TestCase): """ Test fenced_code extension. """ @@ -196,7 +233,7 @@ class TestFencedCode(unittest.TestCase): self.md = markdown.Markdown(extensions=['markdown.extensions.fenced_code']) self.has_pygments = True try: - import pygments + import pygments # noqa except ImportError: self.has_pygments = False @@ -208,18 +245,22 @@ A paragraph before a fenced code block: ~~~ Fenced code block ~~~''' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

A paragraph before a fenced code block:

\n' '
Fenced code block\n'
-            '
') + '' + ) def testSafeFence(self): """ Test Fenced Code with safe_mode. """ text = '~~~\nCode\n~~~' self.md.safeMode = 'replace' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '
Code\n'
-            '
') + '' + ) def testNestedFence(self): """ Test nested fence. """ @@ -229,10 +270,12 @@ Fenced code block ~~~~ ~~~~~~~~''' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '
\n'
             '~~~~\n'
-            '
') + '' + ) def testFencedLanguage(self): """ Test Language Tags. """ @@ -241,9 +284,11 @@ Fenced code block ~~~~{.python} # Some python code ~~~~''' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '
# Some python code\n'
-            '
') + '' + ) def testFencedBackticks(self): """ Test Code Fenced with Backticks. """ @@ -253,10 +298,12 @@ Fenced code block # Arbitrary code ~~~~~ # these tildes will not close the block `````''' - self.assertEqual(self.md.convert(text), - '
# Arbitrary code\n'
-        '~~~~~ # these tildes will not close the block\n'
-        '
') + self.assertEqual( + self.md.convert(text), + '
# Arbitrary code\n'
+            '~~~~~ # these tildes will not close the block\n'
+            '
' + ) def testFencedCodeWithHighlightLines(self): """ Test Fenced Code with Highlighted Lines. """ @@ -267,22 +314,29 @@ line 1 line 2 line 3 ```''' - md = markdown.Markdown(extensions=[ - markdown.extensions.codehilite.CodeHiliteExtension(linenums=None, guess_lang=False), - 'markdown.extensions.fenced_code']) + md = markdown.Markdown( + extensions=[ + markdown.extensions.codehilite.CodeHiliteExtension(linenums=None, guess_lang=False), + 'markdown.extensions.fenced_code' + ] + ) if self.has_pygments: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
'
                 'line 1\n'
                 'line 2\n'
                 'line 3\n'
-                '
') + '' + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
line 1\n'
                 'line 2\n'
-                'line 3
') + 'line 3' + ) def testFencedLanguageAndHighlightLines(self): """ Test Fenced Code with Highlighted Lines. """ @@ -300,22 +354,29 @@ line 3 #line 3 ~~~''' for text in (text0, text1): - md = markdown.Markdown(extensions=[ - markdown.extensions.codehilite.CodeHiliteExtension(linenums=None, guess_lang=False), - 'markdown.extensions.fenced_code']) - + md = markdown.Markdown( + extensions=[ + markdown.extensions.codehilite.CodeHiliteExtension(linenums=None, guess_lang=False), + 'markdown.extensions.fenced_code' + ] + ) if self.has_pygments: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
'
                     '#line 1\n'
                     '#line 2\n'
                     '#line 3\n'
-                    '
') + '' + ) else: - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '
#line 1\n'
                     '#line 2\n'
-                    '#line 3
') + '#line 3' + ) + class TestHeaderId(unittest.TestCase): """ Test HeaderId Extension. """ @@ -327,8 +388,10 @@ class TestHeaderId(unittest.TestCase): """ Test Basic HeaderID """ text = "# Some Header #" - self.assertEqual(self.md.convert(text), - '

Some Header

') + self.assertEqual( + self.md.convert(text), + '

Some Header

' + ) def testUniqueFunc(self): """ Test 'unique' function. """ @@ -341,10 +404,12 @@ class TestHeaderId(unittest.TestCase): """ Test Unique IDs. """ text = '#Header\n#Header\n#Header' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

Header

\n' '

Header

\n' - '

Header

') + '

Header

' + ) def testBaseLevel(self): """ Test Header Base Level. """ @@ -353,27 +418,34 @@ class TestHeaderId(unittest.TestCase): self.assertEqual( markdown.markdown(text, [markdown.extensions.headerid.HeaderIdExtension(level=3)]), '

Some Header

\n' - '

Next Level

') + '

Next Level

' + ) def testHeaderInlineMarkup(self): """ Test Header IDs with inline markup. """ text = '#Some *Header* with [markup](http://example.com).' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

Some Header with ' - 'markup.

') + 'markup.' + ) def testHtmlEntities(self): """ Test HeaderIDs with HTML Entities. """ text = '# Foo & bar' - self.assertEqual(self.md.convert(text), - '

Foo & bar

') + self.assertEqual( + self.md.convert(text), + '

Foo & bar

' + ) def testRawHtml(self): """ Test HeaderIDs with raw HTML. """ text = '# Foo Bar Baz.' - self.assertEqual(self.md.convert(text), - '

Foo Bar Baz.

') + self.assertEqual( + self.md.convert(text), + '

Foo Bar Baz.

' + ) def testNoAutoIds(self): """ Test HeaderIDs with no auto generated IDs. """ @@ -382,7 +454,8 @@ class TestHeaderId(unittest.TestCase): self.assertEqual( markdown.markdown(text, [markdown.extensions.headerid.HeaderIdExtension(forceid=False)]), '

Some Header

\n' - '

Another Header

') + '

Another Header

' + ) def testHeaderIdWithMetaData(self): """ Test Header IDs with MetaData extension. """ @@ -391,20 +464,27 @@ class TestHeaderId(unittest.TestCase): header_forceid: Off # A Header''' - self.assertEqual(markdown.markdown(text, ['markdown.extensions.headerid', 'markdown.extensions.meta']), - '

A Header

') + self.assertEqual( + markdown.markdown(text, ['markdown.extensions.headerid', 'markdown.extensions.meta']), + '

A Header

' + ) def testHeaderIdWithAttr_List(self): """ Test HeaderIDs with Attr_List extension. """ - + text = '# Header1 {: #foo }\n# Header2 {: .bar }' - self.assertEqual(markdown.markdown(text, ['markdown.extensions.headerid', 'markdown.extensions.attr_list']), + self.assertEqual( + markdown.markdown(text, ['markdown.extensions.headerid', 'markdown.extensions.attr_list']), '

Header1

\n' - '

Header2

') + '

Header2

' + ) # Switch order extensions are loaded - should be no change in behavior. - self.assertEqual(markdown.markdown(text, ['markdown.extensions.attr_list', 'markdown.extensions.headerid']), + self.assertEqual( + markdown.markdown(text, ['markdown.extensions.attr_list', 'markdown.extensions.headerid']), '

Header1

\n' - '

Header2

') + '

Header2

' + ) + class TestMetaData(unittest.TestCase): """ Test MetaData extension. """ @@ -421,20 +501,27 @@ Author: Waylan Limberg Blank_Data: The body. This is paragraph one.''' - self.assertEqual(self.md.convert(text), - '

The body. This is paragraph one.

') - self.assertEqual(self.md.Meta, - {'author': ['Waylan Limberg', 'John Doe'], - 'blank_data': [''], - 'title': ['A Test Doc.']}) + self.assertEqual( + self.md.convert(text), + '

The body. This is paragraph one.

' + ) + self.assertEqual( + self.md.Meta, { + 'author': ['Waylan Limberg', 'John Doe'], + 'blank_data': [''], + 'title': ['A Test Doc.'] + } + ) def testMissingMetaData(self): """ Test document without Meta Data. """ text = ' Some Code - not extra lines of meta data.' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '
Some Code - not extra lines of meta data.\n'
-            '
') + '' + ) self.assertEqual(self.md.Meta, {}) def testMetaDataWithoutNewline(self): @@ -454,24 +541,34 @@ class TestWikiLinks(unittest.TestCase): def testBasicWikilinks(self): """ Test [[wikilinks]]. """ - self.assertEqual(self.md.convert(self.text), + self.assertEqual( + self.md.convert(self.text), '

Some text with a ' - 'WikiLink.

') + 'WikiLink.

' + ) def testWikilinkWhitespace(self): """ Test whitespace in wikilinks. """ - self.assertEqual(self.md.convert('[[ foo bar_baz ]]'), - '

foo bar_baz

') - self.assertEqual(self.md.convert('foo [[ ]] bar'), - '

foo bar

') + self.assertEqual( + self.md.convert('[[ foo bar_baz ]]'), + '

foo bar_baz

' + ) + self.assertEqual( + self.md.convert('foo [[ ]] bar'), + '

foo bar

' + ) def testSimpleSettings(self): """ Test Simple Settings. """ - self.assertEqual(markdown.markdown(self.text, - [markdown.extensions.wikilinks.WikiLinkExtension(base_url='/wiki/', - end_url='.html', - html_class='foo')]), + self.assertEqual(markdown.markdown( + self.text, [ + markdown.extensions.wikilinks.WikiLinkExtension( + base_url='/wiki/', + end_url='.html', + html_class='foo') + ] + ), '

Some text with a ' 'WikiLink.

') @@ -479,15 +576,21 @@ class TestWikiLinks(unittest.TestCase): """ Test Complex Settings. """ md = markdown.Markdown( - extensions = ['markdown.extensions.wikilinks'], - extension_configs = {'markdown.extensions.wikilinks': [ - ('base_url', 'http://example.com/'), - ('end_url', '.html'), - ('html_class', '') ]}, - safe_mode = True) - self.assertEqual(md.convert(self.text), + extensions=['markdown.extensions.wikilinks'], + extension_configs={ + 'markdown.extensions.wikilinks': [ + ('base_url', 'http://example.com/'), + ('end_url', '.html'), + ('html_class', '') + ] + }, + safe_mode=True + ) + self.assertEqual( + md.convert(self.text), '

Some text with a ' - 'WikiLink.

') + 'WikiLink.

' + ) def testWikilinksMetaData(self): """ test MetaData with Wikilinks Extension. """ @@ -498,25 +601,33 @@ wiki_html_class: Some text with a [[WikiLink]].""" md = markdown.Markdown(extensions=['markdown.extensions.meta', 'markdown.extensions.wikilinks']) - self.assertEqual(md.convert(text), + self.assertEqual( + md.convert(text), '

Some text with a ' - 'WikiLink.

') + 'WikiLink.

' + ) # MetaData should not carry over to next document: - self.assertEqual(md.convert("No [[MetaData]] here."), + self.assertEqual( + md.convert("No [[MetaData]] here."), '

No MetaData ' - 'here.

') + 'here.

' + ) 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=[WikiLinkExtension(build_url=my_url_builder)]) - self.assertEqual(md.convert('[[foo]]'), - '

foo

') + self.assertEqual( + md.convert('[[foo]]'), + '

foo

' + ) + class TestAdmonition(unittest.TestCase): """ Test Admonition Extension. """ @@ -534,74 +645,82 @@ class TestAdmonition(unittest.TestCase): for test, expected in tests: self.assertEqual(RE.match(test).groups(), expected) + class TestTOC(unittest.TestCase): """ Test TOC Extension. """ - + def setUp(self): self.md = markdown.Markdown(extensions=['markdown.extensions.toc']) def testMarker(self): """ Test TOC with a Marker. """ text = '[TOC]\n\n# Header 1\n\n## Header 2' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '
\n' - '\n' + '
    \n' # noqa + '
  • Header 1' # noqa + '\n' # noqa + '
  • \n' # noqa + '
\n' # noqa '
\n' '

Header 1

\n' - '

Header 2

') - + '

Header 2

' + ) + def testNoMarker(self): """ Test TOC without a Marker. """ text = '# Header 1\n\n## Header 2' - self.assertEqual(self.md.convert(text), + self.assertEqual( + self.md.convert(text), '

Header 1

\n' - '

Header 2

') - self.assertEqual(self.md.toc, + '

Header 2

' + ) + self.assertEqual( + self.md.toc, '
\n' - '\n' - '
\n') + '
    \n' # noqa + '
  • Header 1' # noqa + '\n' # noqa + '
  • \n' # noqa + '
\n' # noqa + '\n' + ) class TestSmarty(unittest.TestCase): def setUp(self): config = { - 'markdown.extensions.smarty': [ - ('smart_angled_quotes', True), - ('substitutions', { - 'ndash': '\u2013', - 'mdash': '\u2014', - 'ellipsis': '\u2026', - 'left-single-quote': '‚', # sb is not a typo! - 'right-single-quote': '‘', - 'left-double-quote': '„', - 'right-double-quote': '“', - 'left-angle-quote': '[', - 'right-angle-quote': ']', - }),] + 'markdown.extensions.smarty': [ + ('smart_angled_quotes', True), + ('substitutions', { + 'ndash': '\u2013', + 'mdash': '\u2014', + 'ellipsis': '\u2026', + 'left-single-quote': '‚', # sb is not a typo! + 'right-single-quote': '‘', + 'left-double-quote': '„', + 'right-double-quote': '“', + 'left-angle-quote': '[', + 'right-angle-quote': ']', + }), + ] } - self.md = markdown.Markdown(extensions=['markdown.extensions.smarty'], - extension_configs=config) - + self.md = markdown.Markdown( + extensions=['markdown.extensions.smarty'], + extension_configs=config + ) + def testCustomSubstitutions(self): - text = \ -"""<< The "Unicode char of the year 2014" + text = """<< The "Unicode char of the year 2014" is the 'mdash': --- Must not be confused with 'ndash' (--) ... >> """ - correct = \ -"""

[ The „Unicode char of the year 2014“ + correct = """

[ The „Unicode char of the year 2014“ is the ‚mdash‘: \u2014 Must not be confused with ‚ndash‘ (\u2013) \u2026 ]

""" self.assertEqual(self.md.convert(text), correct) -- cgit v1.2.3