diff --git a/tests/test_syntax/extensions/test_code_hilite.py b/tests/test_syntax/extensions/test_code_hilite.py
index 3e36ae506..709aa963d 100644
--- a/tests/test_syntax/extensions/test_code_hilite.py
+++ b/tests/test_syntax/extensions/test_code_hilite.py
@@ -21,6 +21,7 @@
from markdown.test_tools import TestCase
from markdown.extensions.codehilite import CodeHiliteExtension, CodeHilite
+import os
try:
import pygments # noqa
@@ -28,10 +29,19 @@
except ImportError:
has_pygments = False
+# The version required by the tests is the version specified and installed in the 'pygments' tox env.
+# In any environment where the PYGMENTS_VERSION environment variabe is either not defined or doesn't
+# match the version of Pygments installed, all tests which rely in pygments will be skipped.
+required_pygments_version = os.environ.get('PYGMENTS_VERSION', '')
+
class TestCodeHiliteClass(TestCase):
""" Test the markdown.extensions.codehilite.CodeHilite class. """
+ def setUp(self):
+ if has_pygments and pygments.__version__ != required_pygments_version:
+ self.skipTest(f'Pygments=={required_pygments_version} is required')
+
maxDiff = None
def assertOutputEquals(self, source, expected, **options):
@@ -340,6 +350,10 @@ def test_codehilite_startinline(self):
class TestCodeHiliteExtension(TestCase):
""" Test codehilite extension. """
+ def setUp(self):
+ if has_pygments and pygments.__version__ != required_pygments_version:
+ self.skipTest(f'Pygments=={required_pygments_version} is required')
+
maxDiff = None
def testBasicCodeHilite(self):
diff --git a/tests/test_syntax/extensions/test_fenced_code.py b/tests/test_syntax/extensions/test_fenced_code.py
index a78c18c0b..ac6ce17ab 100644
--- a/tests/test_syntax/extensions/test_fenced_code.py
+++ b/tests/test_syntax/extensions/test_fenced_code.py
@@ -23,19 +23,19 @@
import markdown
import os
+try:
+ import pygments # noqa
+ has_pygments = True
+except ImportError:
+ has_pygments = False
-class TestFencedCode(TestCase):
+# The version required by the tests is the version specified and installed in the 'pygments' tox env.
+# In any environment where the PYGMENTS_VERSION environment variabe is either not defined or doesn't
+# match the version of Pygments installed, all tests which rely in pygments will be skipped.
+required_pygments_version = os.environ.get('PYGMENTS_VERSION', '')
- def setUp(self):
- # Only set self.has_pygments to True if pygments is installed and the version matches
- # the version expected by the tests. The version expected by the tests is the version
- # specified and installed in the 'pygments' tox env. Outside of the tox env, an environment
- # variable named PYGMENTS_VERSION will need to be defined to force the tests to use pygments.
- try:
- import pygments # noqa
- self.has_pygments = pygments.__version__ == os.environ.get('PYGMENTS_VERSION', '')
- except ImportError:
- self.has_pygments = False
+
+class TestFencedCode(TestCase):
def testBasicFence(self):
self.assertMarkdownRenders(
@@ -134,8 +134,255 @@ def testFencedLanguageWithDot(self):
extensions=['fenced_code']
)
+ def test_fenced_code_in_raw_html(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ """
+
+
+ Begone placeholders!
+
# Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedMultipleClassesInAttr(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` {.python .foo .bar}
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedIdInAttr(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { #foo }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedIdAndLangInAttr(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python #foo }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedIdAndLangAndClassInAttr(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python #foo .bar }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedLanguageIdAndPygmentsDisabledInAttrNoCodehilite(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python #foo use_pygments=False }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedLanguageIdAndPygmentsEnabledInAttrNoCodehilite(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python #foo use_pygments=True }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code']
+ )
+
+ def testFencedLanguageNoCodehiliteWithAttrList(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python foo=bar }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code', 'attr_list']
+ )
+
+ def testFencedLanguagePygmentsDisabledInAttrNoCodehiliteWithAttrList(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python foo=bar use_pygments=False }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code', 'attr_list']
+ )
+
+ def testFencedLanguagePygmentsEnabledInAttrNoCodehiliteWithAttrList(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` { .python foo=bar use_pygments=True }
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=['fenced_code', 'attr_list']
+ )
+
+ def testFencedLanguageNoPrefix(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` python
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=[markdown.extensions.fenced_code.FencedCodeExtension(lang_prefix='')]
+ )
+
+ def testFencedLanguageAltPrefix(self):
+ self.assertMarkdownRenders(
+ self.dedent(
+ '''
+ ``` python
+ # Some python code
+ ```
+ '''
+ ),
+ self.dedent(
+ '''
+ # Some python code
+
+ '''
+ ),
+ extensions=[markdown.extensions.fenced_code.FencedCodeExtension(lang_prefix='lang-')]
+ )
+
+
+class TestFencedCodeWithCodehilite(TestCase):
+
+ def setUp(self):
+ if has_pygments and pygments.__version__ != required_pygments_version:
+ self.skipTest(f'Pygments=={required_pygments_version} is required')
+
def testFencedCodeWithHighlightLines(self):
- if self.has_pygments:
+ if has_pygments:
expected = self.dedent(
'''
line 1
@@ -171,7 +418,7 @@ def testFencedCodeWithHighlightLines(self):
)
def testFencedLanguageAndHighlightLines(self):
- if self.has_pygments:
+ if has_pygments:
expected = (
''
'line 1\n'
@@ -227,7 +474,7 @@ def testFencedLanguageAndPygmentsDisabled(self):
)
def testFencedLanguageDoubleEscape(self):
- if self.has_pygments:
+ if has_pygments:
expected = (
''
'<span'
@@ -258,7 +505,7 @@ def testFencedLanguageDoubleEscape(self):
)
def testFencedAmps(self):
- if self.has_pygments:
+ if has_pygments:
expected = self.dedent(
'''
&
@@ -293,122 +540,8 @@ def testFencedAmps(self):
]
)
- def test_fenced_code_in_raw_html(self):
- self.assertMarkdownRenders(
- self.dedent(
- """
-
- ```
- Begone placeholders!
- ```
-
- """
- ),
- self.dedent(
- """
-
-
- Begone placeholders!
-
-
-
- """
- ),
- extensions=['fenced_code']
- )
-
- def testFencedLanguageInAttr(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` {.python}
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
- def testFencedMultipleClassesInAttr(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` {.python .foo .bar}
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
- def testFencedIdInAttr(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { #foo }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
- def testFencedIdAndLangInAttr(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python #foo }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
- def testFencedIdAndLangAndClassInAttr(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python #foo .bar }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
def testFencedCodeWithHighlightLinesInAttr(self):
- if self.has_pygments:
+ if has_pygments:
expected = self.dedent(
'''
line 1
@@ -444,7 +577,7 @@ def testFencedCodeWithHighlightLinesInAttr(self):
)
def testFencedLanguageAndHighlightLinesInAttr(self):
- if self.has_pygments:
+ if has_pygments:
expected = (
''
'line 1\n'
@@ -517,44 +650,8 @@ def testFencedLanguageIdAndPygmentsDisabledInAttr(self):
extensions=['codehilite', 'fenced_code']
)
- def testFencedLanguageIdAndPygmentsDisabledInAttrNoCodehilite(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python #foo use_pygments=False }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
- def testFencedLanguageIdAndPygmentsEnabledInAttrNoCodehilite(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python #foo use_pygments=True }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code']
- )
-
def testFencedLanguageAttrCssclass(self):
- if self.has_pygments:
+ if has_pygments:
expected = self.dedent(
'''
# Some python code
@@ -579,7 +676,7 @@ def testFencedLanguageAttrCssclass(self):
)
def testFencedLanguageAttrLinenums(self):
- if self.has_pygments:
+ if has_pygments:
expected = (
''
'1
'
@@ -606,7 +703,7 @@ def testFencedLanguageAttrLinenums(self):
)
def testFencedLanguageAttrGuesslang(self):
- if self.has_pygments:
+ if has_pygments:
expected = self.dedent(
'''
# Some python code
@@ -631,7 +728,7 @@ def testFencedLanguageAttrGuesslang(self):
)
def testFencedLanguageAttrNoclasses(self):
- if self.has_pygments:
+ if has_pygments:
expected = (
''
''
@@ -654,93 +751,3 @@ def testFencedLanguageAttrNoclasses(self):
expected,
extensions=['codehilite', 'fenced_code']
)
-
- def testFencedLanguageNoCodehiliteWithAttrList(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python foo=bar }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code', 'attr_list']
- )
-
- def testFencedLanguagePygmentsDisabledInAttrNoCodehiliteWithAttrList(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python foo=bar use_pygments=False }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code', 'attr_list']
- )
-
- def testFencedLanguagePygmentsEnabledInAttrNoCodehiliteWithAttrList(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` { .python foo=bar use_pygments=True }
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=['fenced_code', 'attr_list']
- )
-
- def testFencedLanguageNoPrefix(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` python
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=[markdown.extensions.fenced_code.FencedCodeExtension(lang_prefix='')]
- )
-
- def testFencedLanguageAltPrefix(self):
- self.assertMarkdownRenders(
- self.dedent(
- '''
- ``` python
- # Some python code
- ```
- '''
- ),
- self.dedent(
- '''
- # Some python code
-
- '''
- ),
- extensions=[markdown.extensions.fenced_code.FencedCodeExtension(lang_prefix='lang-')]
- )