Bumped Markdown version to 3.3 (#7590)

This commit is contained in:
David Smith 2020-10-13 17:27:08 +01:00 committed by GitHub
parent 95f0b0867a
commit 04e0c2b9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 182 additions and 193 deletions

View File

@ -1,6 +1,7 @@
# Optional packages which may be used with REST framework. # Optional packages which may be used with REST framework.
psycopg2-binary>=2.8.5, <2.9 psycopg2-binary>=2.8.5, <2.9
markdown==3.1.1 markdown==3.3;python_version>="3.6"
markdown==3.2.2;python_version=="3.5"
pygments==2.4.2 pygments==2.4.2
django-guardian==2.2.0 django-guardian==2.2.0
django-filter>=2.2.0, <2.3 django-filter>=2.2.0, <2.3

View File

@ -1,192 +1,180 @@
from django.test import TestCase import sys
from rest_framework.compat import apply_markdown import pytest
from rest_framework.utils.formatting import dedent from django.test import TestCase
from rest_framework.views import APIView
from rest_framework.compat import apply_markdown
# We check that docstrings get nicely un-indented. from rest_framework.utils.formatting import dedent
DESCRIPTION = """an example docstring from rest_framework.views import APIView
====================
# We check that docstrings get nicely un-indented.
* list DESCRIPTION = """an example docstring
* list ====================
another header * list
-------------- * list
code block another header
--------------
indented
code block
# hash style header #
indented
``` json
[{ # hash style header #
"alpha": 1,
"beta: "this is a string" ``` json
}] [{
```""" "alpha": 1,
"beta: "this is a string"
}]
# If markdown is installed we also test it's working ```"""
# (and that our wrapped forces '=' to h2 and '-' to h3)
MARKED_DOWN_HILITE = """
<div class="highlight"><pre><span></span><span \ # If markdown is installed we also test it's working
class="p">[{</span><br /> <span class="nt">&quot;alpha&quot;</span><span\ # (and that our wrapped forces '=' to h2 and '-' to h3)
class="p">:</span> <span class="mi">1</span><span class="p">,</span><br />\ MARKDOWN_BASE = """<h2 id="an-example-docstring">an example docstring</h2>
<span class="nt">&quot;beta: &quot;</span><span class="err">this</span>\ <ul>
<span class="err">is</span> <span class="err">a</span> <span class="err">\ <li>list</li>
string&quot;</span><br /><span class="p">}]</span><br /></pre></div> <li>list</li>
</ul>
<p><br /></p>""" <h3 id="another-header">another header</h3>
<pre><code>code block
MARKED_DOWN_NOT_HILITE = """ </code></pre>
<p><code>json <p>indented</p>
[{ <h2 id="hash-style-header">hash style header</h2>%s"""
"alpha": 1,
"beta: "this is a string" MARKDOWN_gte_33 = """
}]</code></p>""" <div class="highlight"><pre><span></span><span class="p">[{</span><br />\
<span class="nt">&quot;alpha&quot;</span><span class="p">:</span>\
# We support markdown < 2.1 and markdown >= 2.1 <span class="mi">1</span><span class="p">,</span><br />\
MARKED_DOWN_lt_21 = """<h2>an example docstring</h2> <span class="nt">&quot;beta: &quot;</span><span class="err">this\
<ul> </span> <span class="err">is</span> <span class="err">a</span> \
<li>list</li> <span class="err">string&quot;</span><br /><span class="p">}]</span>\
<li>list</li> <br /></pre></div>
</ul> <p><br /></p>"""
<h3>another header</h3>
<pre><code>code block MARKDOWN_lt_33 = """
</code></pre> <div class="highlight"><pre><span></span><span class="p">[{</span><br />\
<p>indented</p> <span class="nt">&quot;alpha&quot;</span><span class="p">:</span>\
<h2 id="hash_style_header">hash style header</h2>%s""" <span class="mi">1</span><span class="p">,</span><br />\
<span class="nt">&quot;beta: &quot;</span><span class="err">this\
MARKED_DOWN_gte_21 = """<h2 id="an-example-docstring">an example docstring</h2> </span> <span class="err">is</span> <span class="err">a</span>\
<ul> <span class="err">string&quot;</span><br /><span class="p">}]</span>\
<li>list</li> <br /></pre></div>
<li>list</li>
</ul> <p><br /></p>"""
<h3 id="another-header">another header</h3>
<pre><code>code block
</code></pre> class TestViewNamesAndDescriptions(TestCase):
<p>indented</p> def test_view_name_uses_class_name(self):
<h2 id="hash-style-header">hash style header</h2>%s""" """
Ensure view names are based on the class name.
"""
class TestViewNamesAndDescriptions(TestCase): class MockView(APIView):
def test_view_name_uses_class_name(self): pass
""" assert MockView().get_view_name() == 'Mock'
Ensure view names are based on the class name.
""" def test_view_name_uses_name_attribute(self):
class MockView(APIView): class MockView(APIView):
pass name = 'Foo'
assert MockView().get_view_name() == 'Mock' assert MockView().get_view_name() == 'Foo'
def test_view_name_uses_name_attribute(self): def test_view_name_uses_suffix_attribute(self):
class MockView(APIView): class MockView(APIView):
name = 'Foo' suffix = 'List'
assert MockView().get_view_name() == 'Foo' assert MockView().get_view_name() == 'Mock List'
def test_view_name_uses_suffix_attribute(self): def test_view_name_preferences_name_over_suffix(self):
class MockView(APIView): class MockView(APIView):
suffix = 'List' name = 'Foo'
assert MockView().get_view_name() == 'Mock List' suffix = 'List'
assert MockView().get_view_name() == 'Foo'
def test_view_name_preferences_name_over_suffix(self):
class MockView(APIView): def test_view_description_uses_docstring(self):
name = 'Foo' """Ensure view descriptions are based on the docstring."""
suffix = 'List' class MockView(APIView):
assert MockView().get_view_name() == 'Foo' """an example docstring
====================
def test_view_description_uses_docstring(self):
"""Ensure view descriptions are based on the docstring.""" * list
class MockView(APIView): * list
"""an example docstring
==================== another header
--------------
* list
* list code block
another header indented
--------------
# hash style header #
code block
``` json
indented [{
"alpha": 1,
# hash style header # "beta: "this is a string"
}]
``` json ```"""
[{
"alpha": 1, assert MockView().get_view_description() == DESCRIPTION
"beta: "this is a string"
}] def test_view_description_uses_description_attribute(self):
```""" class MockView(APIView):
description = 'Foo'
assert MockView().get_view_description() == DESCRIPTION assert MockView().get_view_description() == 'Foo'
def test_view_description_uses_description_attribute(self): def test_view_description_allows_empty_description(self):
class MockView(APIView): class MockView(APIView):
description = 'Foo' """Description."""
assert MockView().get_view_description() == 'Foo' description = ''
assert MockView().get_view_description() == ''
def test_view_description_allows_empty_description(self):
class MockView(APIView): def test_view_description_can_be_empty(self):
"""Description.""" """
description = '' Ensure that if a view has no docstring,
assert MockView().get_view_description() == '' then it's description is the empty string.
"""
def test_view_description_can_be_empty(self): class MockView(APIView):
""" pass
Ensure that if a view has no docstring, assert MockView().get_view_description() == ''
then it's description is the empty string.
""" def test_view_description_can_be_promise(self):
class MockView(APIView): """
pass Ensure a view may have a docstring that is actually a lazily evaluated
assert MockView().get_view_description() == '' class that can be converted to a string.
def test_view_description_can_be_promise(self): See: https://github.com/encode/django-rest-framework/issues/1708
""" """
Ensure a view may have a docstring that is actually a lazily evaluated # use a mock object instead of gettext_lazy to ensure that we can't end
class that can be converted to a string. # up with a test case string in our l10n catalog
See: https://github.com/encode/django-rest-framework/issues/1708 class MockLazyStr:
""" def __init__(self, string):
# use a mock object instead of gettext_lazy to ensure that we can't end self.s = string
# up with a test case string in our l10n catalog
def __str__(self):
class MockLazyStr: return self.s
def __init__(self, string):
self.s = string class MockView(APIView):
__doc__ = MockLazyStr("a gettext string")
def __str__(self):
return self.s assert MockView().get_view_description() == 'a gettext string'
class MockView(APIView): @pytest.mark.skipif(not apply_markdown, reason="Markdown is not installed")
__doc__ = MockLazyStr("a gettext string") def test_markdown(self):
"""
assert MockView().get_view_description() == 'a gettext string' Ensure markdown to HTML works as expected.
"""
def test_markdown(self): # Markdown 3.3 is only supported on Python 3.6 and higher
""" if sys.version_info >= (3, 6):
Ensure markdown to HTML works as expected. assert apply_markdown(DESCRIPTION) == MARKDOWN_BASE % MARKDOWN_gte_33
""" else:
if apply_markdown: assert apply_markdown(DESCRIPTION) == MARKDOWN_BASE % MARKDOWN_lt_33
md_applied = apply_markdown(DESCRIPTION)
gte_21_match = (
md_applied == ( def test_dedent_tabs():
MARKED_DOWN_gte_21 % MARKED_DOWN_HILITE) or result = 'first string\n\nsecond string'
md_applied == ( assert dedent(" first string\n\n second string") == result
MARKED_DOWN_gte_21 % MARKED_DOWN_NOT_HILITE)) assert dedent("first string\n\n second string") == result
lt_21_match = ( assert dedent("\tfirst string\n\n\tsecond string") == result
md_applied == ( assert dedent("first string\n\n\tsecond string") == result
MARKED_DOWN_lt_21 % MARKED_DOWN_HILITE) or
md_applied == (
MARKED_DOWN_lt_21 % MARKED_DOWN_NOT_HILITE))
assert gte_21_match or lt_21_match
def test_dedent_tabs():
result = 'first string\n\nsecond string'
assert dedent(" first string\n\n second string") == result
assert dedent("first string\n\n second string") == result
assert dedent("\tfirst string\n\n\tsecond string") == result
assert dedent("first string\n\n\tsecond string") == result