summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2017-05-22 23:41:58 -0700
committerBert JW Regeer <bertjw@regeer.org>2017-05-22 23:41:58 -0700
commit8035b7a17b4c0a9a327249fbca60717b9008761c (patch)
tree71f0d0f980a84e5836fa56fbf4f935771a8f9b89
parenta1fcaab98587fc75dc863912a9745fe712739c1d (diff)
downloadwebob-cleanup/testing.tar.gz
Use pytest.parametrize instead of loopingcleanup/testing
-rw-r--r--tests/test_misc.py82
1 files changed, 45 insertions, 37 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 3767c0c..f9d3930 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -1,46 +1,13 @@
+import pytest
+
from webob.util import html_escape
from webob.compat import (
text_,
PY3
)
-def test_html_escape():
- if PY3:
- EXPECTED_LT = 'expected a &#x27;&lt;&#x27;.'
- else:
- EXPECTED_LT = "expected a '&lt;'."
- for v, s in [
- # unsafe chars
- ('these chars: < > & "', 'these chars: &lt; &gt; &amp; &quot;'),
- (' ', ' '),
- ('&egrave;', '&amp;egrave;'),
- # The apostrophe is *not* escaped, which some might consider to be
- # a serious bug (see, e.g. http://www.cvedetails.com/cve/CVE-2010-2480/)
- (text_('the majestic m\xf8ose'), 'the majestic m&#248;ose'),
- # ("'", "&#39;")
-
- # 8-bit strings are passed through
- (text_('\xe9'), '&#233;'),
- # (text_(b'the majestic m\xf8ose').encode('utf-8'),
- # 'the majestic m\xc3\xb8ose'),
-
- # ``None`` is treated specially, and returns the empty string.
- (None, ''),
-
- # Objects that define a ``__html__`` method handle their own escaping
- (t_esc_HTML(), '<div>hello</div>'),
-
- # Things that are not strings are converted to strings and then escaped
- (42, '42'),
- (Exception("expected a '<'."), EXPECTED_LT),
-
- # If an object implements both ``__str__`` and ``__unicode__``, the latter
- # is preferred
- (t_esc_SuperMoose(), 'm&#248;ose'),
- (t_esc_Unicode(), '&#233;'),
- (t_esc_UnsafeAttrs(), '&lt;UnsafeAttrs&gt;'),
- ]:
- assert html_escape(v) == s
+py2only = pytest.mark.skipif("sys.version_info >= (3, 0)")
+py3only = pytest.mark.skipif("sys.version_info < (3, 0)")
class t_esc_HTML(object):
def __html__(self):
@@ -63,3 +30,44 @@ class t_esc_SuperMoose(object):
return text_(b'm\xf8ose').encode('utf-8')
def __unicode__(self):
return text_(b'm\xf8ose')
+
+
+@pytest.mark.parametrize("input,expected", [
+ ('these chars: < > & "', 'these chars: &lt; &gt; &amp; &quot;'),
+ (' ', ' '),
+ ('&egrave;', '&amp;egrave;'),
+
+ # The apostrophe is *not* escaped, which some might consider to be
+ # a serious bug (see, e.g. http://www.cvedetails.com/cve/CVE-2010-2480/)
+ pytest.param("'", "'", marks=py2only),
+ pytest.param("'", "&#x27;", marks=py3only),
+
+ (text_('the majestic m\xf8ose'), 'the majestic m&#248;ose'),
+
+ # 8-bit strings are passed through
+ (text_('\xe9'), '&#233;'),
+
+ # ``None`` is treated specially, and returns the empty string.
+ (None, ''),
+
+ # Objects that define a ``__html__`` method handle their own escaping
+ (t_esc_HTML(), '<div>hello</div>'),
+
+ # Things that are not strings are converted to strings and then escaped
+ (42, '42'),
+
+ # If an object implements both ``__str__`` and ``__unicode__``, the latter
+ # is preferred
+ (t_esc_SuperMoose(), 'm&#248;ose'),
+ (t_esc_Unicode(), '&#233;'),
+ (t_esc_UnsafeAttrs(), '&lt;UnsafeAttrs&gt;'),
+
+ pytest.param(Exception("expected a '<'."), "expected a '&lt;'.", marks=py2only),
+ pytest.param(
+ Exception("expected a '<'."),
+ "expected a &#x27;&lt;&#x27;.",
+ marks=py3only
+ ),
+])
+def test_html_escape(input, expected):
+ assert expected == html_escape(input)