Refs #23919 -- Removed str_prefix usage

This commit is contained in:
Claude Paroz 2017-01-20 15:24:05 +01:00
parent 7aba69145d
commit 289fc1bfa5
6 changed files with 37 additions and 47 deletions

View File

@ -1,6 +1,5 @@
from django.db.models import Max from django.db.models import Max
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import str_prefix
from .models import Celebrity, Fan, Staff, StaffTag, Tag from .models import Celebrity, Fan, Staff, StaffTag, Tag
@ -78,8 +77,7 @@ class DistinctOnTests(TestCase):
( (
(Staff.objects.distinct('id').order_by('id', 'coworkers__name'). (Staff.objects.distinct('id').order_by('id', 'coworkers__name').
values_list('id', 'coworkers__name')), values_list('id', 'coworkers__name')),
[str_prefix("(1, %(_)s'p2')"), str_prefix("(2, %(_)s'p1')"), ["(1, 'p2')", "(2, 'p1')", "(3, 'p1')", "(4, None)"]
str_prefix("(3, %(_)s'p1')"), "(4, None)"]
), ),
) )
for qset, expected in qsets: for qset, expected in qsets:

View File

@ -19,7 +19,6 @@ from django.forms.utils import ErrorList
from django.http import QueryDict from django.http import QueryDict
from django.template import Context, Template from django.template import Context, Template
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.test.utils import str_prefix
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.encoding import force_text from django.utils.encoding import force_text
from django.utils.html import format_html from django.utils.html import format_html
@ -2519,9 +2518,7 @@ Password: <input type="password" name="password" required />
# Case 3: POST with valid data (the success message).) # Case 3: POST with valid data (the success message).)
self.assertEqual( self.assertEqual(
my_function('POST', {'username': 'adrian', 'password1': 'secret', 'password2': 'secret'}), my_function('POST', {'username': 'adrian', 'password1': 'secret', 'password2': 'secret'}),
str_prefix( "VALID: [('password1', 'secret'), ('password2', 'secret'), ('username', 'adrian')]"
"VALID: [('password1', %(_)s'secret'), ('password2', %(_)s'secret'), ('username', %(_)s'adrian')]"
)
) )
def test_templates_with_forms(self): def test_templates_with_forms(self):

View File

@ -13,7 +13,7 @@ from django.http import (
from django.http.request import split_domain_port from django.http.request import split_domain_port
from django.test import RequestFactory, SimpleTestCase, override_settings from django.test import RequestFactory, SimpleTestCase, override_settings
from django.test.client import FakePayload from django.test.client import FakePayload
from django.test.utils import freeze_time, str_prefix from django.test.utils import freeze_time
from django.utils.http import cookie_date, urlencode from django.utils.http import cookie_date, urlencode
from django.utils.timezone import utc from django.utils.timezone import utc
@ -57,17 +57,17 @@ class RequestsTests(SimpleTestCase):
request.POST = {'post-key': 'post-value'} request.POST = {'post-key': 'post-value'}
request.COOKIES = {'post-key': 'post-value'} request.COOKIES = {'post-key': 'post-value'}
request.META = {'post-key': 'post-value'} request.META = {'post-key': 'post-value'}
self.assertEqual(repr(request), str_prefix("<HttpRequest: GET '/somepath/'>")) self.assertEqual(repr(request), "<HttpRequest: GET '/somepath/'>")
def test_httprequest_repr_invalid_method_and_path(self): def test_httprequest_repr_invalid_method_and_path(self):
request = HttpRequest() request = HttpRequest()
self.assertEqual(repr(request), str_prefix("<HttpRequest>")) self.assertEqual(repr(request), "<HttpRequest>")
request = HttpRequest() request = HttpRequest()
request.method = "GET" request.method = "GET"
self.assertEqual(repr(request), str_prefix("<HttpRequest>")) self.assertEqual(repr(request), "<HttpRequest>")
request = HttpRequest() request = HttpRequest()
request.path = "" request.path = ""
self.assertEqual(repr(request), str_prefix("<HttpRequest>")) self.assertEqual(repr(request), "<HttpRequest>")
def test_wsgirequest(self): def test_wsgirequest(self):
request = WSGIRequest({ request = WSGIRequest({
@ -156,13 +156,13 @@ class RequestsTests(SimpleTestCase):
def test_wsgirequest_repr(self): def test_wsgirequest_repr(self):
request = WSGIRequest({'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')}) request = WSGIRequest({'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
self.assertEqual(repr(request), str_prefix("<WSGIRequest: GET '/'>")) self.assertEqual(repr(request), "<WSGIRequest: GET '/'>")
request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')}) request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
request.GET = {'get-key': 'get-value'} request.GET = {'get-key': 'get-value'}
request.POST = {'post-key': 'post-value'} request.POST = {'post-key': 'post-value'}
request.COOKIES = {'post-key': 'post-value'} request.COOKIES = {'post-key': 'post-value'}
request.META = {'post-key': 'post-value'} request.META = {'post-key': 'post-value'}
self.assertEqual(repr(request), str_prefix("<WSGIRequest: GET '/somepath/'>")) self.assertEqual(repr(request), "<WSGIRequest: GET '/somepath/'>")
def test_wsgirequest_path_info(self): def test_wsgirequest_path_info(self):
def wsgi_str(path_info, encoding='utf-8'): def wsgi_str(path_info, encoding='utf-8'):

View File

@ -1,6 +1,5 @@
from django.template.defaultfilters import make_list from django.template.defaultfilters import make_list
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.test.utils import str_prefix
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from ..utils import setup from ..utils import setup
@ -15,22 +14,22 @@ class MakeListTests(SimpleTestCase):
@setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'}) @setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'})
def test_make_list01(self): def test_make_list01(self):
output = self.engine.render_to_string('make_list01', {"a": mark_safe("&")}) output = self.engine.render_to_string('make_list01', {"a": mark_safe("&")})
self.assertEqual(output, str_prefix("[%(_)s'&']")) self.assertEqual(output, "['&']")
@setup({'make_list02': '{{ a|make_list }}'}) @setup({'make_list02': '{{ a|make_list }}'})
def test_make_list02(self): def test_make_list02(self):
output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")}) output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")})
self.assertEqual(output, str_prefix("[%(_)s&#39;&amp;&#39;]")) self.assertEqual(output, "[&#39;&amp;&#39;]")
@setup({'make_list03': '{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'}) @setup({'make_list03': '{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'})
def test_make_list03(self): def test_make_list03(self):
output = self.engine.render_to_string('make_list03', {"a": mark_safe("&")}) output = self.engine.render_to_string('make_list03', {"a": mark_safe("&")})
self.assertEqual(output, str_prefix("[%(_)s'&']")) self.assertEqual(output, "['&']")
@setup({'make_list04': '{{ a|make_list|stringformat:"s"|safe }}'}) @setup({'make_list04': '{{ a|make_list|stringformat:"s"|safe }}'})
def test_make_list04(self): def test_make_list04(self):
output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")}) output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")})
self.assertEqual(output, str_prefix("[%(_)s'&']")) self.assertEqual(output, "['&']")
class FunctionTests(SimpleTestCase): class FunctionTests(SimpleTestCase):

View File

@ -15,7 +15,7 @@ from django.test import (
Client, SimpleTestCase, TestCase, modify_settings, override_settings, Client, SimpleTestCase, TestCase, modify_settings, override_settings,
) )
from django.test.client import RedirectCycleError, RequestFactory, encode_file from django.test.client import RedirectCycleError, RequestFactory, encode_file
from django.test.utils import ContextList, str_prefix from django.test.utils import ContextList
from django.urls import NoReverseMatch, reverse from django.urls import NoReverseMatch, reverse
from django.utils.translation import ugettext_lazy from django.utils.translation import ugettext_lazy
@ -595,21 +595,19 @@ class AssertFormErrorTests(SimpleTestCase):
self.assertFormError(response, 'form', 'email', 'Some error.') self.assertFormError(response, 'form', 'email', 'Some error.')
except AssertionError as e: except AssertionError as e:
self.assertIn( self.assertIn(
str_prefix(
"The field 'email' on form 'form' in context 0 does not " "The field 'email' on form 'form' in context 0 does not "
"contain the error 'Some error.' (actual errors: " "contain the error 'Some error.' (actual errors: "
"[%(_)s'Enter a valid email address.'])" "['Enter a valid email address.'])",
), str(e) str(e)
) )
try: try:
self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc') self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc')
except AssertionError as e: except AssertionError as e:
self.assertIn( self.assertIn(
str_prefix(
"abc: The field 'email' on form 'form' in context 0 does " "abc: The field 'email' on form 'form' in context 0 does "
"not contain the error 'Some error.' (actual errors: " "not contain the error 'Some error.' (actual errors: "
"[%(_)s'Enter a valid email address.'])", "['Enter a valid email address.'])",
), str(e) str(e)
) )
def test_unknown_nonfield_error(self): def test_unknown_nonfield_error(self):
@ -719,10 +717,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
def test_unknown_error(self): def test_unknown_error(self):
"An assertion is raised if the field doesn't contain the specified error" "An assertion is raised if the field doesn't contain the specified error"
for prefix, kwargs in self.msg_prefixes: for prefix, kwargs in self.msg_prefixes:
msg = str_prefix( msg = prefix + (
prefix + "The field 'email' on formset 'my_formset', form 0 " "The field 'email' on formset 'my_formset', form 0 "
"in context 0 does not contain the error 'Some error.' " "in context 0 does not contain the error 'Some error.' "
"(actual errors: [%(_)s'Enter a valid email address.'])" "(actual errors: ['Enter a valid email address.'])"
) )
with self.assertRaisesMessage(AssertionError, msg): with self.assertRaisesMessage(AssertionError, msg):
self.assertFormsetError(self.response_form_errors, 'my_formset', 0, 'email', 'Some error.', **kwargs) self.assertFormsetError(self.response_form_errors, 'my_formset', 0, 'email', 'Some error.', **kwargs)
@ -743,10 +741,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
def test_unknown_nonfield_error(self): def test_unknown_nonfield_error(self):
"An assertion is raised if the formsets non-field errors doesn't contain the provided error." "An assertion is raised if the formsets non-field errors doesn't contain the provided error."
for prefix, kwargs in self.msg_prefixes: for prefix, kwargs in self.msg_prefixes:
msg = str_prefix( msg = prefix + (
prefix + "The formset 'my_formset', form 0 in context 0 does not " "The formset 'my_formset', form 0 in context 0 does not "
"contain the non-field error 'Some error.' (actual errors: " "contain the non-field error 'Some error.' (actual errors: "
"[%(_)s'Non-field error.'])" "['Non-field error.'])"
) )
with self.assertRaisesMessage(AssertionError, msg): with self.assertRaisesMessage(AssertionError, msg):
self.assertFormsetError(self.response_form_errors, 'my_formset', 0, None, 'Some error.', **kwargs) self.assertFormsetError(self.response_form_errors, 'my_formset', 0, None, 'Some error.', **kwargs)
@ -766,11 +764,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
def test_unknown_nonform_error(self): def test_unknown_nonform_error(self):
"An assertion is raised if the formsets non-form errors doesn't contain the provided error." "An assertion is raised if the formsets non-form errors doesn't contain the provided error."
for prefix, kwargs in self.msg_prefixes: for prefix, kwargs in self.msg_prefixes:
msg = str_prefix( msg = prefix + (
prefix +
"The formset 'my_formset' in context 0 does not contain the " "The formset 'my_formset' in context 0 does not contain the "
"non-form error 'Some error.' (actual errors: [%(_)s'Forms " "non-form error 'Some error.' (actual errors: ['Forms in a set "
"in a set must have distinct email addresses.'])" "must have distinct email addresses.'])"
) )
with self.assertRaisesMessage(AssertionError, msg): with self.assertRaisesMessage(AssertionError, msg):
self.assertFormsetError( self.assertFormsetError(

View File

@ -16,7 +16,6 @@ from django.core.validators import (
validate_unicode_slug, validate_unicode_slug,
) )
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.test.utils import str_prefix
try: try:
from PIL import Image # noqa from PIL import Image # noqa
@ -314,18 +313,18 @@ def create_simple_test_method(validator, expected, value, num):
class TestSimpleValidators(SimpleTestCase): class TestSimpleValidators(SimpleTestCase):
def test_single_message(self): def test_single_message(self):
v = ValidationError('Not Valid') v = ValidationError('Not Valid')
self.assertEqual(str(v), str_prefix("[%(_)s'Not Valid']")) self.assertEqual(str(v), "['Not Valid']")
self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'Not Valid'])")) self.assertEqual(repr(v), "ValidationError(['Not Valid'])")
def test_message_list(self): def test_message_list(self):
v = ValidationError(['First Problem', 'Second Problem']) v = ValidationError(['First Problem', 'Second Problem'])
self.assertEqual(str(v), str_prefix("[%(_)s'First Problem', %(_)s'Second Problem']")) self.assertEqual(str(v), "['First Problem', 'Second Problem']")
self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'First Problem', %(_)s'Second Problem'])")) self.assertEqual(repr(v), "ValidationError(['First Problem', 'Second Problem'])")
def test_message_dict(self): def test_message_dict(self):
v = ValidationError({'first': ['First Problem']}) v = ValidationError({'first': ['First Problem']})
self.assertEqual(str(v), str_prefix("{%(_)s'first': [%(_)s'First Problem']}")) self.assertEqual(str(v), "{'first': ['First Problem']}")
self.assertEqual(repr(v), str_prefix("ValidationError({%(_)s'first': [%(_)s'First Problem']})")) self.assertEqual(repr(v), "ValidationError({'first': ['First Problem']})")
def test_regex_validator_flags(self): def test_regex_validator_flags(self):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):