forked from Python-Markdown/markdown
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As a part of the Markdown lib, test tools can be used by third party extensions. Also keeps test dir clean as it only contains actual tests. More work in this vein to come as the need for Nose is removed. Tests are defined as Unittests rather than in text files allowing features to be more easily broken into units and run individually. Based completely on standard lib unittest with no external dependencies. Use `python -m unittest tests.test_syntax` to run. Pulled some tests from https://github.com/karlcow/markdown-testsuite. Many more test units to pull from that source. As we encounter the need to edit an existing textfile-based test, or add a new test, a new test should be created with this framework and the old test should be deleted. Also need to delete existing testfile-based tests which are covered in the new tests included here.
- Loading branch information
Showing
7 changed files
with
1,349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import unittest | ||
import textwrap | ||
from markdown import markdown | ||
|
||
|
||
class TestCase(unittest.TestCase): | ||
""" | ||
A unittest.TestCase subclass with helpers for testing Markdown output. | ||
Define `default_kwargs` as a dict of keywords to pass to Markdown for each | ||
test. The defaults can be overridden on individual tests. | ||
The `assertMarkdownRenders` method accepts the source text, the expected | ||
output, and any keywords to pass to Markdown. The `default_kwargs` are used | ||
except where overridden by `kwargs`. The ouput and expected ouput are passed | ||
to `TestCase.assertMultiLineEqual`. An AssertionError is raised with a diff | ||
if the actual output does not equal the expected output. | ||
The `dedent` method is available to dedent triple-quoted strings if | ||
necessary. | ||
In all other respects, behaves as unittest.TestCase. | ||
""" | ||
|
||
default_kwargs = {} | ||
|
||
def assertMarkdownRenders(self, source, expected, **kwargs): | ||
""" | ||
Test that source Markdown text renders to expected output with given keywords. | ||
""" | ||
|
||
kws = self.default_kwargs.copy() | ||
kws.update(kwargs) | ||
output = markdown(source, **kws) | ||
self.assertMultiLineEqual(output, expected) | ||
|
||
def dedent(self, text): | ||
""" | ||
Dedent text. | ||
""" | ||
|
||
# TODO: If/when actual output ends with a newline, then use: | ||
# return textwrap.dedent(text.strip('/n')) | ||
return textwrap.dedent(text).strip() |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from markdown.test_tools import TestCase | ||
|
||
|
||
class TestCodeBlocks(TestCase): | ||
|
||
def test_spaced_codeblock(self): | ||
self.assertMarkdownRenders( | ||
' # A code block.', | ||
|
||
self.dedent( | ||
""" | ||
<pre><code># A code block. | ||
</code></pre> | ||
""" | ||
) | ||
) | ||
|
||
def test_tabbed_codeblock(self): | ||
self.assertMarkdownRenders( | ||
'\t# A code block.', | ||
|
||
self.dedent( | ||
""" | ||
<pre><code># A code block. | ||
</code></pre> | ||
""" | ||
) | ||
) | ||
|
||
def test_multiline_codeblock(self): | ||
self.assertMarkdownRenders( | ||
' # Line 1\n # Line 2\n', | ||
|
||
self.dedent( | ||
""" | ||
<pre><code># Line 1 | ||
# Line 2 | ||
</code></pre> | ||
""" | ||
) | ||
) | ||
|
||
def test_codeblock_with_blankline(self): | ||
self.assertMarkdownRenders( | ||
' # Line 1\n\n # Line 2\n', | ||
|
||
self.dedent( | ||
""" | ||
<pre><code># Line 1 | ||
# Line 2 | ||
</code></pre> | ||
""" | ||
) | ||
) | ||
|
||
def test_codeblock_escape(self): | ||
self.assertMarkdownRenders( | ||
' <foo & bar>', | ||
|
||
self.dedent( | ||
""" | ||
<pre><code><foo & bar> | ||
</code></pre> | ||
""" | ||
) | ||
) |
Oops, something went wrong.