diff options
Diffstat (limited to 'tests/test_misc.py')
| -rw-r--r-- | tests/test_misc.py | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/tests/test_misc.py b/tests/test_misc.py index 1b6c629..e356f33 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,23 +1,19 @@ import pytest -from webob.util import html_escape -from webob.compat import text_ +from webob.util import html_escape, text_ -py2only = pytest.mark.skipif("sys.version_info >= (3, 0)") -py3only = pytest.mark.skipif("sys.version_info < (3, 0)") - -class t_esc_HTML(object): +class t_esc_HTML: def __html__(self): return "<div>hello</div>" -class t_esc_Unicode(object): - def __unicode__(self): - return text_(b"\xe9") +class t_esc_Unicode: + def __str__(self): + return "\xe9" -class t_esc_UnsafeAttrs(object): +class t_esc_UnsafeAttrs: attr = "value" def __getattr__(self, k): @@ -27,12 +23,9 @@ class t_esc_UnsafeAttrs(object): return "<UnsafeAttrs>" -class t_esc_SuperMoose(object): +class t_esc_SuperMoose: def __str__(self): - return text_(b"m\xf8ose").encode("utf-8") - - def __unicode__(self): - return text_(b"m\xf8ose") + return "m\xf8ose" @pytest.mark.parametrize( @@ -43,26 +36,20 @@ class t_esc_SuperMoose(object): ("è", "&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("'", "'", marks=py3only), - (text_("the majestic m\xf8ose"), "the majestic møose"), + pytest.param("'", "'"), + ("the majestic m\xf8ose", "the majestic møose"), # 8-bit strings are passed through - (text_("\xe9"), "é"), + ("\xe9", "é"), # ``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øose"), (t_esc_Unicode(), "é"), (t_esc_UnsafeAttrs(), "<UnsafeAttrs>"), - pytest.param(Exception("expected a '<'."), "expected a '<'.", marks=py2only), - pytest.param( - Exception("expected a '<'."), "expected a '<'.", marks=py3only - ), + pytest.param(Exception("expected a '<'."), "expected a '<'."), ], ) def test_html_escape(input, expected): |
