From 36ab0c387f84485444e60480382caafb7a807fd6 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 14 Feb 2013 16:04:24 -0500 Subject: Allow better linenum override in CodeHilite Fixes #148. The "force_linenos" config setting of the CodeHilite extension has been marked as Pending Deprecation and a new setting "linenums" has been added to replace it. See documentation for the [CodeHilite Extension] for an explaination of the new "linenums" setting. The new setting will honor the old "force_linenos" if it is set, but it will raise a PendingDeprecationWarning and will likely be removed in a future version of Python-Markdown. [CodeHilite Extension]: extensions/codehilite.html --- tests/test_extensions.py | 78 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_extensions.py b/tests/test_extensions.py index fd77e5e..bee270a 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -31,8 +31,6 @@ class TestCodeHilite(unittest.TestCase): """ Test codehilite extension. """ def setUp(self): - self.md = markdown.Markdown(extensions=['codehilite']) - self.has_pygments = True try: import pygments @@ -41,16 +39,88 @@ class TestCodeHilite(unittest.TestCase): def testBasicCodeHilite(self): text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '
' + '
# A Code Comment\n'
+                '
') + else: + self.assertEqual(md.convert(text), + '
# A Code Comment'
+                '
') + + def testLinenumsTrue(self): + text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=True)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '' + '' + '' + '
1
' + '
# A Code Comment\n
' + '
\n
') + else: + self.assertEqual(md.convert(text), + '
# A Code Comment'
+                '
') + + def testLinenumsFalse(self): + text = '\t#!Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=False)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '
' + '
# A Code Comment\n'
+                '
') + else: + self.assertEqual(md.convert(text), + '
# A Code Comment'
+                '
') + + def testLinenumsNone(self): + text = '\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) if self.has_pygments: - self.assertEqual(self.md.convert(text), + self.assertEqual(md.convert(text), '
' '
# A Code Comment\n'
                 '
') else: - self.assertEqual(self.md.convert(text), + self.assertEqual(md.convert(text), '
# A Code Comment'
                 '
') + def testLinenumsNoneWithShebang(self): + text = '\t#!Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '' + '' + '' + '
1
' + '
# A Code Comment\n
' + '
\n
') + else: + self.assertEqual(md.convert(text), + '
# A Code Comment'
+                '
') + + def testLinenumsNoneWithColon(self): + text = '\t:::Python\n\t# A Code Comment' + md = markdown.Markdown(extensions=['codehilite(linenums=None)']) + if self.has_pygments: + self.assertEqual(md.convert(text), + '
' + '
# A Code Comment\n'
+                '
') + else: + self.assertEqual(md.convert(text), + '
# A Code Comment'
+                '
') + class TestFencedCode(unittest.TestCase): """ Test fenced_code extension. """ -- cgit v1.2.3