summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-10-31 01:36:26 -0500
committerMichael Merickel <michael@merickel.org>2018-11-12 21:39:23 -0600
commit6b0e4625da2c53a1e3fdb4857fc7c6ba6ce562cf (patch)
tree5d115273784eb021e5550539e39f552672921329 /tests
parent7429fcb5a96aa10bbe86da08bd0b30c9292efdde (diff)
downloadpyramid-6b0e4625da2c53a1e3fdb4857fc7c6ba6ce562cf.tar.gz
pyramid-6b0e4625da2c53a1e3fdb4857fc7c6ba6ce562cf.tar.bz2
pyramid-6b0e4625da2c53a1e3fdb4857fc7c6ba6ce562cf.zip
initial work to remove py2 from the codebase
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config/test_adapters.py6
-rw-r--r--tests/test_config/test_factories.py7
-rw-r--r--tests/test_config/test_init.py3
-rw-r--r--tests/test_path.py6
-rw-r--r--tests/test_request.py7
-rw-r--r--tests/test_session.py8
-rw-r--r--tests/test_traversal.py7
-rw-r--r--tests/test_urldispatch.py7
-rw-r--r--tests/test_util.py27
9 files changed, 15 insertions, 63 deletions
diff --git a/tests/test_config/test_adapters.py b/tests/test_config/test_adapters.py
index d871e8825..60a4f3090 100644
--- a/tests/test_config/test_adapters.py
+++ b/tests/test_config/test_adapters.py
@@ -1,6 +1,5 @@
import unittest
-from pyramid.compat import PY2
from . import IDummy
@@ -270,10 +269,7 @@ class AdaptersConfiguratorMixinTests(unittest.TestCase):
from pyramid.interfaces import IResponse
config = self._makeOne(autocommit=True)
- if PY2:
- str_name = '__builtin__.str'
- else:
- str_name = 'builtins.str'
+ str_name = 'builtins.str'
config.add_response_adapter('pyramid.response.Response', str_name)
result = config.registry.queryAdapter('foo', IResponse)
self.assertTrue(result.body, b'foo')
diff --git a/tests/test_config/test_factories.py b/tests/test_config/test_factories.py
index c03d3f68b..cca528275 100644
--- a/tests/test_config/test_factories.py
+++ b/tests/test_config/test_factories.py
@@ -161,7 +161,6 @@ class TestFactoriesMixin(unittest.TestCase):
self.assertRaises(AttributeError, config.add_request_method)
def test_add_request_method_with_text_type_name(self):
- from pyramid.compat import text_, PY2
from pyramid.exceptions import ConfigurationError
config = self._makeOne(autocommit=True)
@@ -170,11 +169,7 @@ class TestFactoriesMixin(unittest.TestCase):
pass
def get_bad_name():
- if PY2:
- name = text_(b'La Pe\xc3\xb1a', 'utf-8')
- else:
- name = b'La Pe\xc3\xb1a'
-
+ name = b'La Pe\xc3\xb1a'
config.add_request_method(boomshaka, name=name)
self.assertRaises(ConfigurationError, get_bad_name)
diff --git a/tests/test_config/test_init.py b/tests/test_config/test_init.py
index 811672fb3..1cd63f113 100644
--- a/tests/test_config/test_init.py
+++ b/tests/test_config/test_init.py
@@ -2,7 +2,6 @@ import os
import unittest
from pyramid.compat import im_func
-from pyramid.testing import skip_on
from . import dummy_tween_factory
from . import dummy_include
@@ -1157,7 +1156,6 @@ test_config.dummy_include2"""
"@view_config(name='two', renderer='string')" in which
)
- @skip_on('py3')
def test_hook_zca(self):
from zope.component import getSiteManager
@@ -1173,7 +1171,6 @@ test_config.dummy_include2"""
finally:
getSiteManager.reset()
- @skip_on('py3')
def test_unhook_zca(self):
from zope.component import getSiteManager
diff --git a/tests/test_path.py b/tests/test_path.py
index 626bb1139..da7cd64e1 100644
--- a/tests/test_path.py
+++ b/tests/test_path.py
@@ -1,6 +1,5 @@
import unittest
import os
-from pyramid.compat import PY2
here = os.path.abspath(os.path.dirname(__file__))
@@ -429,10 +428,7 @@ class TestDottedNameResolver(unittest.TestCase):
def test_zope_dottedname_style_resolve_builtin(self):
typ = self._makeOne()
- if PY2:
- result = typ._zope_dottedname_style('__builtin__.str', None)
- else:
- result = typ._zope_dottedname_style('builtins.str', None)
+ result = typ._zope_dottedname_style('builtins.str', None)
self.assertEqual(result, str)
def test_zope_dottedname_style_resolve_absolute(self):
diff --git a/tests/test_request.py b/tests/test_request.py
index dcac501aa..60cc2b31a 100644
--- a/tests/test_request.py
+++ b/tests/test_request.py
@@ -1,7 +1,7 @@
import unittest
from pyramid import testing
-from pyramid.compat import PY2, text_, bytes_, native_
+from pyramid.compat import text_, bytes_, native_
from pyramid.security import AuthenticationAPIMixin, AuthorizationAPIMixin
@@ -352,10 +352,7 @@ class TestRequest(unittest.TestCase):
inp = text_(
b'/\xe6\xb5\x81\xe8\xa1\x8c\xe8\xb6\x8b\xe5\x8a\xbf', 'utf-8'
)
- if PY2:
- body = json.dumps({'a': inp}).decode('utf-8').encode('utf-16')
- else:
- body = bytes(json.dumps({'a': inp}), 'utf-16')
+ body = bytes(json.dumps({'a': inp}), 'utf-16')
request.body = body
request.content_type = 'application/json; charset=utf-16'
self.assertEqual(request.json_body, {'a': inp})
diff --git a/tests/test_session.py b/tests/test_session.py
index 5e2a1ff55..f7e7bab05 100644
--- a/tests/test_session.py
+++ b/tests/test_session.py
@@ -607,13 +607,7 @@ class DummySerializer(object):
return base64.b64encode(json.dumps(value).encode('utf-8'))
def loads(self, value):
- try:
- return json.loads(base64.b64decode(value).decode('utf-8'))
-
- # base64.b64decode raises a TypeError on py2 instead of a ValueError
- # and a ValueError is required for the session to handle it properly
- except TypeError:
- raise ValueError
+ return json.loads(base64.b64decode(value).decode('utf-8'))
class DummySessionFactory(dict):
diff --git a/tests/test_traversal.py b/tests/test_traversal.py
index 61e480cbc..b517fa646 100644
--- a/tests/test_traversal.py
+++ b/tests/test_traversal.py
@@ -3,7 +3,7 @@ import unittest
from pyramid.testing import cleanUp
-from pyramid.compat import text_, native_, text_type, url_quote, PY2
+from pyramid.compat import text_, native_, text_type, url_quote
class TraversalPathTests(unittest.TestCase):
@@ -346,10 +346,7 @@ class ResourceTreeTraverserTests(unittest.TestCase):
foo = DummyContext(bar, path)
root = DummyContext(foo, 'root')
policy = self._makeOne(root)
- if PY2:
- vhm_root = b'/Qu\xc3\xa9bec'
- else:
- vhm_root = b'/Qu\xc3\xa9bec'.decode('latin-1')
+ vhm_root = b'/Qu\xc3\xa9bec'.decode('latin-1')
environ = self._getEnviron(HTTP_X_VHM_ROOT=vhm_root)
request = DummyRequest(environ, path_info=text_('/bar'))
result = policy(request)
diff --git a/tests/test_urldispatch.py b/tests/test_urldispatch.py
index 772250e89..b50e86b99 100644
--- a/tests/test_urldispatch.py
+++ b/tests/test_urldispatch.py
@@ -1,6 +1,6 @@
import unittest
from pyramid import testing
-from pyramid.compat import text_, PY2
+from pyramid.compat import text_
class TestRoute(unittest.TestCase):
@@ -132,10 +132,7 @@ class RoutesMapperTests(unittest.TestCase):
from pyramid.exceptions import URLDecodeError
mapper = self._makeOne()
- if PY2:
- path_info = b'\xff\xfe\xe6\x00'
- else:
- path_info = b'\xff\xfe\xe6\x00'.decode('latin-1')
+ path_info = b'\xff\xfe\xe6\x00'.decode('latin-1')
request = self._getRequest(PATH_INFO=path_info)
self.assertRaises(URLDecodeError, mapper, request)
diff --git a/tests/test_util.py b/tests/test_util.py
index a36655f6f..8af5fe557 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -1,5 +1,5 @@
import unittest
-from pyramid.compat import PY2, text_, bytes_
+from pyramid.compat import text_, bytes_
class Test_InstancePropertyHelper(unittest.TestCase):
@@ -170,14 +170,10 @@ class Test_InstancePropertyHelper(unittest.TestCase):
self.assertEqual(2, foo.y)
def test_make_property_unicode(self):
- from pyramid.compat import text_
from pyramid.exceptions import ConfigurationError
cls = self._getTargetClass()
- if PY2:
- name = text_(b'La Pe\xc3\xb1a', 'utf-8')
- else:
- name = b'La Pe\xc3\xb1a'
+ name = b'La Pe\xc3\xb1a'
def make_bad_name():
cls.make_property(lambda x: 1, name=name, reify=True)
@@ -498,10 +494,7 @@ class Test_object_description(unittest.TestCase):
self.assertEqual(self._callFUT(('a', 'b')), "('a', 'b')")
def test_set(self):
- if PY2:
- self.assertEqual(self._callFUT(set(['a'])), "set(['a'])")
- else:
- self.assertEqual(self._callFUT(set(['a'])), "{'a'}")
+ self.assertEqual(self._callFUT(set(['a'])), "{'a'}")
def test_list(self):
self.assertEqual(self._callFUT(['a']), "['a']")
@@ -841,26 +834,16 @@ class TestSentinel(unittest.TestCase):
class TestCallableName(unittest.TestCase):
def test_valid_ascii(self):
from pyramid.util import get_callable_name
- from pyramid.compat import text_
-
- if PY2:
- name = text_(b'hello world', 'utf-8')
- else:
- name = b'hello world'
+ name = b'hello world'
self.assertEqual(get_callable_name(name), 'hello world')
def test_invalid_ascii(self):
from pyramid.util import get_callable_name
- from pyramid.compat import text_
from pyramid.exceptions import ConfigurationError
def get_bad_name():
- if PY2:
- name = text_(b'La Pe\xc3\xb1a', 'utf-8')
- else:
- name = b'La Pe\xc3\xb1a'
-
+ name = b'La Pe\xc3\xb1a'
get_callable_name(name)
self.assertRaises(ConfigurationError, get_bad_name)