mirror of
https://github.com/django/django.git
synced 2025-04-25 09:44:36 +00:00
Refs #34986 -- Fixed some test assertions for PyPy.
These failures were due to minor inconsistencies or implementation differences between CPython and PyPy.
This commit is contained in:
parent
051dbb5388
commit
baf705f34a
@ -71,6 +71,6 @@ class EmailFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
|||||||
self.assertIsNone(f.clean(None))
|
self.assertIsNone(f.clean(None))
|
||||||
|
|
||||||
def test_emailfield_unable_to_set_strip_kwarg(self):
|
def test_emailfield_unable_to_set_strip_kwarg(self):
|
||||||
msg = "__init__() got multiple values for keyword argument 'strip'"
|
msg = "got multiple values for keyword argument 'strip'"
|
||||||
with self.assertRaisesMessage(TypeError, msg):
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
EmailField(strip=False)
|
EmailField(strip=False)
|
||||||
|
@ -136,7 +136,7 @@ class URLFieldTest(FormFieldAssertionsMixin, SimpleTestCase):
|
|||||||
self.assertIsNone(f.clean(None))
|
self.assertIsNone(f.clean(None))
|
||||||
|
|
||||||
def test_urlfield_unable_to_set_strip_kwarg(self):
|
def test_urlfield_unable_to_set_strip_kwarg(self):
|
||||||
msg = "__init__() got multiple values for keyword argument 'strip'"
|
msg = "got multiple values for keyword argument 'strip'"
|
||||||
with self.assertRaisesMessage(TypeError, msg):
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
URLField(strip=False)
|
URLField(strip=False)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from django.forms import DateField, Form, SelectDateWidget
|
|||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.dates import MONTHS_AP
|
from django.utils.dates import MONTHS_AP
|
||||||
|
from django.utils.version import PYPY
|
||||||
|
|
||||||
from .base import WidgetTest
|
from .base import WidgetTest
|
||||||
|
|
||||||
@ -611,7 +612,11 @@ class SelectDateWidgetTest(WidgetTest):
|
|||||||
((None, "12", "1"), None),
|
((None, "12", "1"), None),
|
||||||
(("2000", None, "1"), None),
|
(("2000", None, "1"), None),
|
||||||
(("2000", "12", None), None),
|
(("2000", "12", None), None),
|
||||||
((str(sys.maxsize + 1), "12", "1"), "0-0-0"),
|
(
|
||||||
|
(str(sys.maxsize + 1), "12", "1"),
|
||||||
|
# PyPy does not raise OverflowError.
|
||||||
|
f"{sys.maxsize + 1}-12-1" if PYPY else "0-0-0",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
for values, expected in tests:
|
for values, expected in tests:
|
||||||
with self.subTest(values=values):
|
with self.subTest(values=values):
|
||||||
|
@ -25,6 +25,7 @@ from django.test import SimpleTestCase, TestCase, ignore_warnings, skipUnlessDBF
|
|||||||
from django.test.utils import isolate_apps
|
from django.test.utils import isolate_apps
|
||||||
from django.utils.choices import BlankChoiceIterator
|
from django.utils.choices import BlankChoiceIterator
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
from django.utils.deprecation import RemovedInDjango60Warning
|
||||||
|
from django.utils.version import PYPY
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Article,
|
Article,
|
||||||
@ -3017,7 +3018,10 @@ class OtherModelFormTests(TestCase):
|
|||||||
return ", ".join(c.name for c in obj.colours.all())
|
return ", ".join(c.name for c in obj.colours.all())
|
||||||
|
|
||||||
field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours"))
|
field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related("colours"))
|
||||||
with self.assertNumQueries(3): # would be 4 if prefetch is ignored
|
# CPython calls ModelChoiceField.__len__() when coercing to tuple. PyPy
|
||||||
|
# doesn't call __len__() and so .count() isn't called on the QuerySet.
|
||||||
|
# The following would trigger an extra query if prefetch were ignored.
|
||||||
|
with self.assertNumQueries(2 if PYPY else 3):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
tuple(field.choices),
|
tuple(field.choices),
|
||||||
(
|
(
|
||||||
|
@ -22,6 +22,7 @@ from django.utils.encoding import (
|
|||||||
)
|
)
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
from django.utils.version import PYPY
|
||||||
|
|
||||||
|
|
||||||
class TestEncodingUtils(SimpleTestCase):
|
class TestEncodingUtils(SimpleTestCase):
|
||||||
@ -43,9 +44,10 @@ class TestEncodingUtils(SimpleTestCase):
|
|||||||
self.assertIs(type(force_str(s)), str)
|
self.assertIs(type(force_str(s)), str)
|
||||||
|
|
||||||
def test_force_str_DjangoUnicodeDecodeError(self):
|
def test_force_str_DjangoUnicodeDecodeError(self):
|
||||||
|
reason = "unexpected end of data" if PYPY else "invalid start byte"
|
||||||
msg = (
|
msg = (
|
||||||
"'utf-8' codec can't decode byte 0xff in position 0: invalid "
|
f"'utf-8' codec can't decode byte 0xff in position 0: {reason}. "
|
||||||
"start byte. You passed in b'\\xff' (<class 'bytes'>)"
|
"You passed in b'\\xff' (<class 'bytes'>)"
|
||||||
)
|
)
|
||||||
with self.assertRaisesMessage(DjangoUnicodeDecodeError, msg):
|
with self.assertRaisesMessage(DjangoUnicodeDecodeError, msg):
|
||||||
force_str(b"\xff")
|
force_str(b"\xff")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user