summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-01-29 21:05:42 -0800
committerDavid Lord <davidism@gmail.com>2020-01-29 22:20:50 -0800
commitc3d647d951981135e1e4a501a40fb6481b4b534a (patch)
treeca951757a32e038c5904a770215a4385a9b438de /tests
parent1ca1c38cc851ac0708dc8ab48c47ca0c33404683 (diff)
downloadmarkupsafe-c3d647d951981135e1e4a501a40fb6481b4b534a.tar.gz
use _mod fixture in more testsdrop-python2
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py5
-rw-r--r--tests/test_exception_custom_html.py4
-rw-r--r--tests/test_leak.py4
-rw-r--r--tests/test_markupsafe.py21
4 files changed, 23 insertions, 11 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 296cd58..7141547 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -34,4 +34,9 @@ def escape_silent(_mod):
@pytest.fixture(scope="session")
def soft_str(_mod):
+ return _mod.soft_str
+
+
+@pytest.fixture(scope="session")
+def soft_unicode(_mod):
return _mod.soft_unicode
diff --git a/tests/test_exception_custom_html.py b/tests/test_exception_custom_html.py
index 5cf1e8e..ec2f10b 100644
--- a/tests/test_exception_custom_html.py
+++ b/tests/test_exception_custom_html.py
@@ -1,14 +1,12 @@
import pytest
-from markupsafe import escape
-
class CustomHtmlThatRaises:
def __html__(self):
raise ValueError(123)
-def test_exception_custom_html():
+def test_exception_custom_html(escape):
"""Checks whether exceptions in custom __html__ implementations are
propagated correctly.
diff --git a/tests/test_leak.py b/tests/test_leak.py
index 5ed906a..55b10b9 100644
--- a/tests/test_leak.py
+++ b/tests/test_leak.py
@@ -1,5 +1,5 @@
import gc
-import sys
+import platform
import pytest
@@ -20,7 +20,7 @@ def test_markup_leaks():
escape("foo")
escape("<foo>")
- if hasattr(sys, "pypy_version_info"):
+ if platform.python_implementation() == "PyPy":
gc.collect()
counts.add(len(gc.get_objects()))
diff --git a/tests/test_markupsafe.py b/tests/test_markupsafe.py
index c17d1a8..bd42d98 100644
--- a/tests/test_markupsafe.py
+++ b/tests/test_markupsafe.py
@@ -1,11 +1,9 @@
import pytest
-from markupsafe import escape
-from markupsafe import escape_silent
from markupsafe import Markup
-def test_adding():
+def test_adding(escape):
unsafe = '<script type="application/x-some-script">alert("foo");</script>'
safe = Markup("<em>username</em>")
assert unsafe + safe == str(escape(unsafe)) + str(safe)
@@ -63,7 +61,7 @@ def test_dict_interpol():
assert result == expect
-def test_escaping():
+def test_escaping(escape):
assert escape("\"<>&'") == "&#34;&lt;&gt;&amp;&#39;"
assert Markup("<em>Foo &amp; Bar</em>").striptags() == "Foo & Bar"
@@ -155,7 +153,7 @@ def test_all_set():
getattr(markup, item)
-def test_escape_silent():
+def test_escape_silent(escape, escape_silent):
assert escape_silent(None) == Markup()
assert escape(None) == Markup(None)
assert escape_silent("<foo>") == Markup("&lt;foo&gt;")
@@ -172,7 +170,7 @@ def test_mul():
assert Markup("a") * 3 == Markup("aaa")
-def test_escape_return_type():
+def test_escape_return_type(escape):
assert isinstance(escape("a"), Markup)
assert isinstance(escape(Markup("a")), Markup)
@@ -181,3 +179,14 @@ def test_escape_return_type():
return "<strong>Foo</strong>"
assert isinstance(escape(Foo()), Markup)
+
+
+def test_soft_str(soft_str):
+ assert type(soft_str("")) is str
+ assert type(soft_str(Markup())) is Markup
+ assert type(soft_str(15)) is str
+
+
+def test_soft_unicode_deprecated(soft_unicode):
+ with pytest.warns(DeprecationWarning):
+ assert type(soft_unicode(Markup())) is Markup