[py3] Various minor syntax fixes in the test suite

This commit is contained in:
Claude Paroz 2012-08-11 22:29:18 +02:00
parent 7d0f883192
commit 6602103338
8 changed files with 24 additions and 23 deletions

View File

@ -135,6 +135,6 @@ class FileTests(unittest.TestCase):
def test_file_mode(self): def test_file_mode(self):
# Should not set mode to None if it is not present. # Should not set mode to None if it is not present.
# See #14681, stdlib gzip module crashes if mode is set to None # 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')) self.assertFalse(hasattr(file, 'mode'))
g = gzip.GzipFile(fileobj=file) g = gzip.GzipFile(fileobj=file)

View File

@ -220,7 +220,7 @@ class MethodDecoratorTests(TestCase):
self.assertEqual(getattr(Test.method, 'myattr2', False), True) self.assertEqual(getattr(Test.method, 'myattr2', False), True)
self.assertEqual(Test.method.__doc__, 'A method') self.assertEqual(Test.method.__doc__, 'A method')
self.assertEqual(Test.method.__func__.__name__, 'method') self.assertEqual(Test.method.__name__, 'method')
class XFrameOptionsDecoratorsTests(TestCase): class XFrameOptionsDecoratorsTests(TestCase):

View File

@ -13,7 +13,7 @@ from django.db.models import signals
from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature) skipUnlessDBFeature)
from django.test.utils import override_settings 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, from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3, Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
@ -244,7 +244,8 @@ class TestFixtures(TestCase):
self.assertEqual( self.assertEqual(
pre_save_checks, 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: finally:

View File

@ -178,7 +178,7 @@ class RelatedModelFormTests(TestCase):
class Meta: class Meta:
model=A model=A
self.assertRaises(ValueError, ModelFormMetaclass, b'Form', (ModelForm,), {'Meta': Meta}) self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta})
class B(models.Model): class B(models.Model):
pass pass
@ -196,4 +196,4 @@ class RelatedModelFormTests(TestCase):
class Meta: class Meta:
model=A model=A
self.assertTrue(issubclass(ModelFormMetaclass(b'Form', (ModelForm,), {'Meta': Meta}), ModelForm)) self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm))

View File

@ -69,7 +69,7 @@ class ViewTest(unittest.TestCase):
def _assert_simple(self, response): def _assert_simple(self, response):
self.assertEqual(response.status_code, 200) 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): def test_no_init_kwargs(self):
""" """

View File

@ -480,7 +480,7 @@ class DayArchiveViewTests(TestCase):
def test_next_prev_context(self): def test_next_prev_context(self):
res = self.client.get('/dates/books/2008/oct/01/') 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): def test_custom_month_format(self):
res = self.client.get('/dates/books/2008/10/01/') res = self.client.get('/dates/books/2008/10/01/')

View File

@ -260,29 +260,29 @@ class HttpResponseTests(unittest.TestCase):
def test_non_string_content(self): def test_non_string_content(self):
#Bug 16494: HttpResponse should behave consistently with non-strings #Bug 16494: HttpResponse should behave consistently with non-strings
r = HttpResponse(12345) r = HttpResponse(12345)
self.assertEqual(r.content, '12345') self.assertEqual(r.content, b'12345')
#test content via property #test content via property
r = HttpResponse() r = HttpResponse()
r.content = 12345 r.content = 12345
self.assertEqual(r.content, '12345') self.assertEqual(r.content, b'12345')
def test_iter_content(self): def test_iter_content(self):
r = HttpResponse(['abc', 'def', 'ghi']) r = HttpResponse(['abc', 'def', 'ghi'])
self.assertEqual(r.content, 'abcdefghi') self.assertEqual(r.content, b'abcdefghi')
#test iter content via property #test iter content via property
r = HttpResponse() r = HttpResponse()
r.content = ['idan', 'alex', 'jacob'] r.content = ['idan', 'alex', 'jacob']
self.assertEqual(r.content, 'idanalexjacob') self.assertEqual(r.content, b'idanalexjacob')
r = HttpResponse() r = HttpResponse()
r.content = [1, 2, 3] r.content = [1, 2, 3]
self.assertEqual(r.content, '123') self.assertEqual(r.content, b'123')
#test retrieval explicitly using iter and odd inputs #test retrieval explicitly using iter and odd inputs
r = HttpResponse() r = HttpResponse()
r.content = ['1', '2', 3, unichr(1950)] r.content = ['1', '2', 3, '\u079e']
result = [] result = []
my_iter = r.__iter__() my_iter = r.__iter__()
while True: while True:
@ -297,8 +297,8 @@ class HttpResponseTests(unittest.TestCase):
#with Content-Encoding header #with Content-Encoding header
r = HttpResponse([1,1,2,4,8]) r = HttpResponse([1,1,2,4,8])
r['Content-Encoding'] = 'winning' r['Content-Encoding'] = 'winning'
self.assertEqual(r.content, '11248') self.assertEqual(r.content, b'11248')
r.content = [unichr(1950),] r.content = ['\u079e',]
self.assertRaises(UnicodeEncodeError, self.assertRaises(UnicodeEncodeError,
getattr, r, 'content') getattr, r, 'content')

View File

@ -12,44 +12,44 @@ class ShortcutTests(TestCase):
def test_render_to_response(self): def test_render_to_response(self):
response = self.client.get('/shortcuts/render_to_response/') response = self.client.get('/shortcuts/render_to_response/')
self.assertEqual(response.status_code, 200) 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') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
def test_render_to_response_with_request_context(self): def test_render_to_response_with_request_context(self):
response = self.client.get('/shortcuts/render_to_response/request_context/') response = self.client.get('/shortcuts/render_to_response/request_context/')
self.assertEqual(response.status_code, 200) 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['Content-Type'], 'text/html; charset=utf-8')
def test_render_to_response_with_mimetype(self): def test_render_to_response_with_mimetype(self):
response = self.client.get('/shortcuts/render_to_response/mimetype/') response = self.client.get('/shortcuts/render_to_response/mimetype/')
self.assertEqual(response.status_code, 200) 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') self.assertEqual(response['Content-Type'], 'application/x-rendertest')
def test_render(self): def test_render(self):
response = self.client.get('/shortcuts/render/') response = self.client.get('/shortcuts/render/')
self.assertEqual(response.status_code, 200) 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['Content-Type'], 'text/html; charset=utf-8')
self.assertEqual(response.context.current_app, None) self.assertEqual(response.context.current_app, None)
def test_render_with_base_context(self): def test_render_with_base_context(self):
response = self.client.get('/shortcuts/render/base_context/') response = self.client.get('/shortcuts/render/base_context/')
self.assertEqual(response.status_code, 200) 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') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
def test_render_with_content_type(self): def test_render_with_content_type(self):
response = self.client.get('/shortcuts/render/content_type/') response = self.client.get('/shortcuts/render/content_type/')
self.assertEqual(response.status_code, 200) 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') self.assertEqual(response['Content-Type'], 'application/x-rendertest')
def test_render_with_status(self): def test_render_with_status(self):
response = self.client.get('/shortcuts/render/status/') response = self.client.get('/shortcuts/render/status/')
self.assertEqual(response.status_code, 403) 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): def test_render_with_current_app(self):
response = self.client.get('/shortcuts/render/current_app/') response = self.client.get('/shortcuts/render/current_app/')