summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-12-01 11:38:01 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-18 16:21:28 +0100
commitc716fe87821df00f9f03ecc761c914d1682591a2 (patch)
tree0436706cdb190acbc76fb5fcf6d66f16e09fafa3 /tests/utils_tests
parente63d98b7beb16d1410168a2315cbe04c43c9c80d (diff)
Refs #23919 -- Removed six.PY2/PY3 usage
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/utils_tests')
-rw-r--r--tests/utils_tests/test_encoding.py29
-rw-r--r--tests/utils_tests/test_functional.py15
-rw-r--r--tests/utils_tests/test_glob.py13
-rw-r--r--tests/utils_tests/test_html.py50
-rw-r--r--tests/utils_tests/test_http.py18
-rw-r--r--tests/utils_tests/test_simplelazyobject.py7
6 files changed, 28 insertions, 104 deletions
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
index 1d6976fc77..b4e7b9c0ac 100644
--- a/tests/utils_tests/test_encoding.py
+++ b/tests/utils_tests/test_encoding.py
@@ -21,10 +21,8 @@ class TestEncodingUtils(unittest.TestCase):
__unicode__ = __str__
- # str(s) raises a TypeError on python 3 if the result is not a text type.
- # python 2 fails when it tries converting from str to unicode (via ASCII).
- exception = TypeError if six.PY3 else UnicodeError
- with self.assertRaises(exception):
+ # str(s) raises a TypeError if the result is not a text type.
+ with self.assertRaises(TypeError):
force_text(MyString())
def test_force_text_lazy(self):
@@ -47,26 +45,15 @@ class TestEncodingUtils(unittest.TestCase):
def test_smart_text(self):
class Test:
- if six.PY3:
- def __str__(self):
- return 'ŠĐĆŽćžšđ'
- else:
- def __str__(self):
- return 'ŠĐĆŽćžšđ'.encode('utf-8')
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
class TestU:
- if six.PY3:
- def __str__(self):
- return 'ŠĐĆŽćžšđ'
-
- def __bytes__(self):
- return b'Foo'
- else:
- def __str__(self):
- return b'Foo'
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
- def __unicode__(self):
- return '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+ def __bytes__(self):
+ return b'Foo'
self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
self.assertEqual(smart_text(TestU()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py
index f7b12724af..0ca534445f 100644
--- a/tests/utils_tests/test_functional.py
+++ b/tests/utils_tests/test_functional.py
@@ -38,18 +38,11 @@ class FunctionalTestCase(unittest.TestCase):
def test_lazy_object_to_string(self):
class Klazz(object):
- if six.PY3:
- def __str__(self):
- return "Î am ā Ǩlâzz."
+ def __str__(self):
+ return "Î am ā Ǩlâzz."
- def __bytes__(self):
- return b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz."
- else:
- def __unicode__(self):
- return "Î am ā Ǩlâzz."
-
- def __str__(self):
- return b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz."
+ def __bytes__(self):
+ return b"\xc3\x8e am \xc4\x81 binary \xc7\xa8l\xc3\xa2zz."
t = lazy(lambda: Klazz(), Klazz)()
self.assertEqual(six.text_type(t), "Î am ā Ǩlâzz.")
diff --git a/tests/utils_tests/test_glob.py b/tests/utils_tests/test_glob.py
deleted file mode 100644
index 5cd7fbbe28..0000000000
--- a/tests/utils_tests/test_glob.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from django.test import SimpleTestCase
-from django.utils.glob import glob_escape
-
-
-class TestUtilsGlob(SimpleTestCase):
- def test_glob_escape(self):
- filename = '/my/file?/name[with special chars*'
- expected = '/my/file[?]/name[[]with special chars[*]'
- filename_b = b'/my/file?/name[with special chars*'
- expected_b = b'/my/file[?]/name[[]with special chars[*]'
-
- self.assertEqual(glob_escape(filename), expected)
- self.assertEqual(glob_escape(filename_b), expected_b)
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index ec818318b4..8f887fd011 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -2,7 +2,7 @@ import os
from datetime import datetime
from django.test import SimpleTestCase
-from django.utils import html, safestring, six
+from django.utils import html, safestring
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazystr
@@ -168,12 +168,8 @@ class TestUtilsHtml(SimpleTestCase):
def test_html_safe(self):
@html.html_safe
class HtmlClass(object):
- if six.PY2:
- def __unicode__(self):
- return "<h1>I'm a html class!</h1>"
- else:
- def __str__(self):
- return "<h1>I'm a html class!</h1>"
+ def __str__(self):
+ return "<h1>I'm a html class!</h1>"
html_obj = HtmlClass()
self.assertTrue(hasattr(HtmlClass, '__html__'))
@@ -181,34 +177,19 @@ class TestUtilsHtml(SimpleTestCase):
self.assertEqual(force_text(html_obj), html_obj.__html__())
def test_html_safe_subclass(self):
- if six.PY2:
- class BaseClass(object):
- def __html__(self):
- # defines __html__ on its own
- return 'some html content'
+ class BaseClass(object):
+ def __html__(self):
+ # defines __html__ on its own
+ return 'some html content'
- def __unicode__(self):
- return 'some non html content'
+ def __str__(self):
+ return 'some non html content'
- @html.html_safe
- class Subclass(BaseClass):
- def __unicode__(self):
- # overrides __unicode__ and is marked as html_safe
- return 'some html safe content'
- else:
- class BaseClass(object):
- def __html__(self):
- # defines __html__ on its own
- return 'some html content'
-
- def __str__(self):
- return 'some non html content'
-
- @html.html_safe
- class Subclass(BaseClass):
- def __str__(self):
- # overrides __str__ and is marked as html_safe
- return 'some html safe content'
+ @html.html_safe
+ class Subclass(BaseClass):
+ def __str__(self):
+ # overrides __str__ and is marked as html_safe
+ return 'some html safe content'
subclass_obj = Subclass()
self.assertEqual(force_text(subclass_obj), subclass_obj.__html__())
@@ -222,8 +203,7 @@ class TestUtilsHtml(SimpleTestCase):
return "<h1>I'm a html class!</h1>"
def test_html_safe_doesnt_define_str(self):
- method_name = '__unicode__()' if six.PY2 else '__str__()'
- msg = "can't apply @html_safe to HtmlClass because it doesn't define %s." % method_name
+ msg = "can't apply @html_safe to HtmlClass because it doesn't define __str__()."
with self.assertRaisesMessage(ValueError, msg):
@html.html_safe
class HtmlClass(object):
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index 30a8846021..281fb77fbb 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -1,9 +1,8 @@
-import sys
import unittest
from datetime import datetime
from django.test import ignore_warnings
-from django.utils import http, six
+from django.utils import http
from django.utils.datastructures import MultiValueDict
from django.utils.deprecation import RemovedInDjango21Warning
@@ -51,15 +50,10 @@ class TestUtilsHttp(unittest.TestCase):
# reciprocity works
for n in [0, 1, 1000, 1000000]:
self.assertEqual(n, http.base36_to_int(http.int_to_base36(n)))
- if six.PY2:
- self.assertEqual(sys.maxint, http.base36_to_int(http.int_to_base36(sys.maxint)))
# bad input
with self.assertRaises(ValueError):
http.int_to_base36(-1)
- if six.PY2:
- with self.assertRaises(ValueError):
- http.int_to_base36(sys.maxint + 1)
for n in ['1', 'foo', {1: 2}, (1, 2, 3), 3.141]:
with self.assertRaises(TypeError):
http.int_to_base36(n)
@@ -132,16 +126,6 @@ class TestUtilsHttp(unittest.TestCase):
"%s should be allowed" % good_url,
)
- if six.PY2:
- # Check binary URLs, regression tests for #26308
- self.assertTrue(
- http.is_safe_url(b'https://testserver/', allowed_hosts={'testserver'}),
- "binary URLs should be allowed on Python 2"
- )
- self.assertFalse(http.is_safe_url(b'\x08//example.com', allowed_hosts={'testserver'}))
- self.assertTrue(http.is_safe_url('àview/'.encode('utf-8'), allowed_hosts={'testserver'}))
- self.assertFalse(http.is_safe_url('àview'.encode('latin-1'), allowed_hosts={'testserver'}))
-
# Valid basic auth credentials are allowed.
self.assertTrue(http.is_safe_url(r'http://user:pass@testserver/', allowed_hosts={'user:pass@testserver'}))
# A path without host is allowed.
diff --git a/tests/utils_tests/test_simplelazyobject.py b/tests/utils_tests/test_simplelazyobject.py
index 8501b89e92..a83c78bf4c 100644
--- a/tests/utils_tests/test_simplelazyobject.py
+++ b/tests/utils_tests/test_simplelazyobject.py
@@ -2,7 +2,6 @@ import pickle
from django.contrib.auth.models import User
from django.test import TestCase
-from django.utils import six
from django.utils.functional import SimpleLazyObject
@@ -21,9 +20,3 @@ class TestUtilsSimpleLazyObjectDjangoTestCase(TestCase):
pickle.dumps(x, 0)
pickle.dumps(x, 1)
pickle.dumps(x, 2)
-
- if six.PY2:
- import cPickle
-
- # This would fail with "TypeError: expected string or Unicode object, NoneType found".
- cPickle.dumps(x)