aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2018-05-04 13:28:40 -0700
committerDavid Lord <davidism@gmail.com>2018-05-04 13:28:40 -0700
commit3fe4a11f139eba8711c7194a4a05e5bbd9a36786 (patch)
tree68a34fb0ccc3ac579dafa8de35d6cc237e72f200 /tests
parent2f931bd8b101c572a431255d35efcf2c177e1630 (diff)
downloadmarkupsafe-3fe4a11f139eba8711c7194a4a05e5bbd9a36786.tar.gz
convert to pytest
Diffstat (limited to 'tests')
-rw-r--r--tests/test_escape.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_escape.py b/tests/test_escape.py
new file mode 100644
index 0000000..cf09d6a
--- /dev/null
+++ b/tests/test_escape.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+import pytest
+
+from markupsafe import Markup, _native
+
+try:
+ from markupsafe import _speedups
+except ImportError:
+ _speedups = None
+
+
+@pytest.mark.parametrize('mod', (
+ _native,
+ pytest.param(_speedups, marks=pytest.mark.skipif(
+ _speedups is None, reason='speedups unavailable')),
+))
+@pytest.mark.parametrize(('value', 'expect'), (
+ # empty
+ (u'', u''),
+ # ascii
+ (u'abcd&><\'"efgh', u'abcd&amp;&gt;&lt;&#39;&#34;efgh'),
+ (u'&><\'"efgh', u'&amp;&gt;&lt;&#39;&#34;efgh'),
+ (u'abcd&><\'"', u'abcd&amp;&gt;&lt;&#39;&#34;'),
+ # 2 byte
+ (u'こんにちは&><\'"こんばんは',
+ u'こんにちは&amp;&gt;&lt;&#39;&#34;こんばんは'),
+ (u'&><\'"こんばんは', u'&amp;&gt;&lt;&#39;&#34;こんばんは'),
+ (u'こんにちは&><\'"', u'こんにちは&amp;&gt;&lt;&#39;&#34;'),
+ # 4 byte
+ (u'\U0001F363\U0001F362&><\'"\U0001F37A xyz', u'\U0001F363\U0001F362&amp;&gt;&lt;&#39;&#34;\U0001F37A xyz'),
+ (u'&><\'"\U0001F37A xyz', u'&amp;&gt;&lt;&#39;&#34;\U0001F37A xyz'),
+ (u'\U0001F363\U0001F362&><\'"', u'\U0001F363\U0001F362&amp;&gt;&lt;&#39;&#34;'),
+))
+def test_escape(mod, value, expect):
+ assert mod.escape(value) == Markup(expect)