-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed markup tests to not fail if required modules are not installed
git-svn-id: http://code.djangoproject.com/svn/django/trunk@483 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
1 changed file
with
46 additions
and
24 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,45 +1,67 @@ | |||
# Quick tests for the markup templatetags (django.contrib.markup) | # Quick tests for the markup templatetags (django.contrib.markup) | ||
# | |||
# Requires that all supported markup modules be installed | |||
# (http://dealmeida.net/projects/textile/, | |||
# http://www.freewisdom.org/projects/python-markdown, and | |||
# http://docutils.sf.net/) | |||
|
|||
|
|
||
from django.core.template import Template, Context | from django.core.template import Template, Context | ||
import django.contrib.markup.templatetags.markup # this registers the filters | import django.contrib.markup.templatetags.markup # this registers the filters | ||
|
|
||
# find out if markup modules are installed and tailor the test appropriately | |||
try: | |||
import textile | |||
except ImportError: | |||
textile = None | |||
|
|||
try: | |||
import markdown | |||
except ImportError: | |||
markdown = None | |||
|
|||
try: | |||
import docutils | |||
except ImportError: | |||
docutils = None | |||
|
|||
# simple examples 'cause this isn't actually testing the markup, just | # simple examples 'cause this isn't actually testing the markup, just | ||
# that the filters work as advertised | # that the filters work as advertised | ||
|
|
||
### test textile | |||
|
|||
textile_content = """Paragraph 1 | textile_content = """Paragraph 1 | ||
Paragraph 2 with "quotes" and @code@""" | Paragraph 2 with "quotes" and @code@""" | ||
|
|
||
markdown_content = """Paragraph 1 | t = Template("{{ textile_content|textile }}") | ||
rendered = t.render(Context(locals())).strip() | |||
if textile: | |||
assert rendered == """<p>Paragraph 1</p> | |||
## An h2 with *italics*""" | <p>Paragraph 2 with “quotes” and <code>code</code></p>""" | ||
else: | |||
assert rendered == textile_content | |||
|
|||
### test markdown | |||
|
|
||
rest_content = """Paragraph 1 | markdown_content = """Paragraph 1 | ||
Paragraph 2 with a link_ | ## An h2""" | ||
|
|
||
.. _link: http://www.example.com/""" | t = Template("{{ markdown_content|markdown }}") | ||
rendered = t.render(Context(locals())).strip() | |||
if textile: | |||
assert rendered == """<p>Paragraph 1</p><h2>An h2</h2>""" | |||
else: | |||
assert rendered == markdown_content | |||
|
|
||
t = Template("""{{ textile_content|textile }} | ### test rest | ||
---- | |||
{{ markdown_content|markdown }} | |||
---- | |||
{{ rest_content|restructuredtext }}""") | |||
|
|
||
rendered = t.render(Context(locals())) | rest_content = """Paragraph 1 | ||
assert rendered.strip() == """<p>Paragraph 1</p> | Paragraph 2 with a link_ | ||
<p>Paragraph 2 with “quotes” and <code>code</code></p> | .. _link: http://www.example.com/""" | ||
---- | |||
<p>Paragraph 1</p><h2>An h2 with *italics*</h2> | |||
|
|
||
---- | t = Template("{{ rest_content|restructuredtext }}") | ||
<p>Paragraph 1</p> | rendered = t.render(Context(locals())).strip() | ||
<p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>""" | if docutils: | ||
assert rendered =="""<p>Paragraph 1</p> | |||
<p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>""" | |||
else: | |||
assert rendered == rest_content |