Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Various minor syntax fixes in the test suite

  • Loading branch information...
commit 66021033381f154ddf8a9ecf93fcbb41a7abda17 1 parent 7d0f883
Claude Paroz claudep authored
2  tests/modeltests/files/tests.py
View
@@ -135,6 +135,6 @@ def test_context_manager(self):
def test_file_mode(self):
# Should not set mode to None if it is not present.
# See #14681, stdlib gzip module crashes if mode is set to None
- file = SimpleUploadedFile("mode_test.txt", "content")
+ file = SimpleUploadedFile("mode_test.txt", b"content")
self.assertFalse(hasattr(file, 'mode'))
g = gzip.GzipFile(fileobj=file)
2  tests/regressiontests/decorators/tests.py
View
@@ -220,7 +220,7 @@ def method(self):
self.assertEqual(getattr(Test.method, 'myattr2', False), True)
self.assertEqual(Test.method.__doc__, 'A method')
- self.assertEqual(Test.method.__func__.__name__, 'method')
+ self.assertEqual(Test.method.__name__, 'method')
class XFrameOptionsDecoratorsTests(TestCase):
5 tests/regressiontests/fixtures_regress/tests.py
View
@@ -13,7 +13,7 @@
from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature)
from django.test.utils import override_settings
-from django.utils.six import StringIO
+from django.utils.six import PY3, StringIO
from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
@@ -244,7 +244,8 @@ def test_field_value_coerce(self):
self.assertEqual(
pre_save_checks,
[
- ("Count = 42 (<type 'int'>)", "Weight = 1.2 (<type 'float'>)")
+ ("Count = 42 (<%s 'int'>)" % ('class' if PY3 else 'type'),
+ "Weight = 1.2 (<%s 'float'>)" % ('class' if PY3 else 'type'))
]
)
finally:
4 tests/regressiontests/forms/tests/models.py
View
@@ -178,7 +178,7 @@ class A(models.Model):
class Meta:
model=A
- self.assertRaises(ValueError, ModelFormMetaclass, b'Form', (ModelForm,), {'Meta': Meta})
+ self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta})
class B(models.Model):
pass
@@ -196,4 +196,4 @@ class B(models.Model):
class Meta:
model=A
- self.assertTrue(issubclass(ModelFormMetaclass(b'Form', (ModelForm,), {'Meta': Meta}), ModelForm))
+ self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm))
2  tests/regressiontests/generic_views/base.py
View
@@ -69,7 +69,7 @@ class ViewTest(unittest.TestCase):
def _assert_simple(self, response):
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'This is a simple view')
+ self.assertEqual(response.content, b'This is a simple view')
def test_no_init_kwargs(self):
"""
2  tests/regressiontests/generic_views/dates.py
View
@@ -480,7 +480,7 @@ def test_day_view_paginated(self):
def test_next_prev_context(self):
res = self.client.get('/dates/books/2008/oct/01/')
- self.assertEqual(res.content, "Archive for Oct. 1, 2008. Previous day is May 1, 2006")
+ self.assertEqual(res.content, b"Archive for Oct. 1, 2008. Previous day is May 1, 2006")
def test_custom_month_format(self):
res = self.client.get('/dates/books/2008/10/01/')
16 tests/regressiontests/httpwrappers/tests.py
View
@@ -260,29 +260,29 @@ def test_dict_behavior(self):
def test_non_string_content(self):
#Bug 16494: HttpResponse should behave consistently with non-strings
r = HttpResponse(12345)
- self.assertEqual(r.content, '12345')
+ self.assertEqual(r.content, b'12345')
#test content via property
r = HttpResponse()
r.content = 12345
- self.assertEqual(r.content, '12345')
+ self.assertEqual(r.content, b'12345')
def test_iter_content(self):
r = HttpResponse(['abc', 'def', 'ghi'])
- self.assertEqual(r.content, 'abcdefghi')
+ self.assertEqual(r.content, b'abcdefghi')
#test iter content via property
r = HttpResponse()
r.content = ['idan', 'alex', 'jacob']
- self.assertEqual(r.content, 'idanalexjacob')
+ self.assertEqual(r.content, b'idanalexjacob')
r = HttpResponse()
r.content = [1, 2, 3]
- self.assertEqual(r.content, '123')
+ self.assertEqual(r.content, b'123')
#test retrieval explicitly using iter and odd inputs
r = HttpResponse()
- r.content = ['1', '2', 3, unichr(1950)]
+ r.content = ['1', '2', 3, '\u079e']
result = []
my_iter = r.__iter__()
while True:
@@ -297,8 +297,8 @@ def test_iter_content(self):
#with Content-Encoding header
r = HttpResponse([1,1,2,4,8])
r['Content-Encoding'] = 'winning'
- self.assertEqual(r.content, '11248')
- r.content = [unichr(1950),]
+ self.assertEqual(r.content, b'11248')
+ r.content = ['\u079e',]
self.assertRaises(UnicodeEncodeError,
getattr, r, 'content')
14 tests/regressiontests/views/tests/shortcuts.py
View
@@ -12,44 +12,44 @@ class ShortcutTests(TestCase):
def test_render_to_response(self):
response = self.client.get('/shortcuts/render_to_response/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR..\n')
+ self.assertEqual(response.content, b'FOO.BAR..\n')
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
def test_render_to_response_with_request_context(self):
response = self.client.get('/shortcuts/render_to_response/request_context/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n')
+ self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
def test_render_to_response_with_mimetype(self):
response = self.client.get('/shortcuts/render_to_response/mimetype/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR..\n')
+ self.assertEqual(response.content, b'FOO.BAR..\n')
self.assertEqual(response['Content-Type'], 'application/x-rendertest')
def test_render(self):
response = self.client.get('/shortcuts/render/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n')
+ self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
self.assertEqual(response.context.current_app, None)
def test_render_with_base_context(self):
response = self.client.get('/shortcuts/render/base_context/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR..\n')
+ self.assertEqual(response.content, b'FOO.BAR..\n')
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
def test_render_with_content_type(self):
response = self.client.get('/shortcuts/render/content_type/')
self.assertEqual(response.status_code, 200)
- self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n')
+ self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
self.assertEqual(response['Content-Type'], 'application/x-rendertest')
def test_render_with_status(self):
response = self.client.get('/shortcuts/render/status/')
self.assertEqual(response.status_code, 403)
- self.assertEqual(response.content, 'FOO.BAR../path/to/static/media/\n')
+ self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n')
def test_render_with_current_app(self):
response = self.client.get('/shortcuts/render/current_app/')
Please sign in to comment.
Something went wrong with that request. Please try again.