From 289fc1bfa54af563d17549ade8d77553711453a1 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 20 Jan 2017 15:24:05 +0100 Subject: [PATCH] Refs #23919 -- Removed str_prefix usage --- tests/distinct_on_fields/tests.py | 4 +- tests/forms_tests/tests/test_forms.py | 5 +-- tests/requests/tests.py | 14 +++---- .../filter_tests/test_make_list.py | 9 ++--- tests/test_client_regress/tests.py | 39 +++++++++---------- tests/validators/tests.py | 13 +++---- 6 files changed, 37 insertions(+), 47 deletions(-) diff --git a/tests/distinct_on_fields/tests.py b/tests/distinct_on_fields/tests.py index e1365dab88..6bb518d2b1 100644 --- a/tests/distinct_on_fields/tests.py +++ b/tests/distinct_on_fields/tests.py @@ -1,6 +1,5 @@ from django.db.models import Max from django.test import TestCase, skipUnlessDBFeature -from django.test.utils import str_prefix from .models import Celebrity, Fan, Staff, StaffTag, Tag @@ -78,8 +77,7 @@ class DistinctOnTests(TestCase): ( (Staff.objects.distinct('id').order_by('id', 'coworkers__name'). values_list('id', 'coworkers__name')), - [str_prefix("(1, %(_)s'p2')"), str_prefix("(2, %(_)s'p1')"), - str_prefix("(3, %(_)s'p1')"), "(4, None)"] + ["(1, 'p2')", "(2, 'p1')", "(3, 'p1')", "(4, None)"] ), ) for qset, expected in qsets: diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index dc70519dac..98c5ee8783 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -19,7 +19,6 @@ from django.forms.utils import ErrorList from django.http import QueryDict from django.template import Context, Template from django.test import SimpleTestCase -from django.test.utils import str_prefix from django.utils.datastructures import MultiValueDict from django.utils.encoding import force_text from django.utils.html import format_html @@ -2519,9 +2518,7 @@ Password: # Case 3: POST with valid data (the success message).) self.assertEqual( my_function('POST', {'username': 'adrian', 'password1': 'secret', 'password2': 'secret'}), - str_prefix( - "VALID: [('password1', %(_)s'secret'), ('password2', %(_)s'secret'), ('username', %(_)s'adrian')]" - ) + "VALID: [('password1', 'secret'), ('password2', 'secret'), ('username', 'adrian')]" ) def test_templates_with_forms(self): diff --git a/tests/requests/tests.py b/tests/requests/tests.py index 0dcaebbca5..ac331232aa 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -13,7 +13,7 @@ from django.http import ( from django.http.request import split_domain_port from django.test import RequestFactory, SimpleTestCase, override_settings 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.timezone import utc @@ -57,17 +57,17 @@ class RequestsTests(SimpleTestCase): request.POST = {'post-key': 'post-value'} request.COOKIES = {'post-key': 'post-value'} request.META = {'post-key': 'post-value'} - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") def test_httprequest_repr_invalid_method_and_path(self): request = HttpRequest() - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") request = HttpRequest() request.method = "GET" - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") request = HttpRequest() request.path = "" - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") def test_wsgirequest(self): request = WSGIRequest({ @@ -156,13 +156,13 @@ class RequestsTests(SimpleTestCase): def test_wsgirequest_repr(self): request = WSGIRequest({'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')}) - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')}) request.GET = {'get-key': 'get-value'} request.POST = {'post-key': 'post-value'} request.COOKIES = {'post-key': 'post-value'} request.META = {'post-key': 'post-value'} - self.assertEqual(repr(request), str_prefix("")) + self.assertEqual(repr(request), "") def test_wsgirequest_path_info(self): def wsgi_str(path_info, encoding='utf-8'): diff --git a/tests/template_tests/filter_tests/test_make_list.py b/tests/template_tests/filter_tests/test_make_list.py index 454b394d3b..17c4cac480 100644 --- a/tests/template_tests/filter_tests/test_make_list.py +++ b/tests/template_tests/filter_tests/test_make_list.py @@ -1,6 +1,5 @@ from django.template.defaultfilters import make_list from django.test import SimpleTestCase -from django.test.utils import str_prefix from django.utils.safestring import mark_safe from ..utils import setup @@ -15,22 +14,22 @@ class MakeListTests(SimpleTestCase): @setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'}) def test_make_list01(self): 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 }}'}) def test_make_list02(self): output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")}) - self.assertEqual(output, str_prefix("[%(_)s'&']")) + self.assertEqual(output, "['&']") @setup({'make_list03': '{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'}) def test_make_list03(self): 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 }}'}) def test_make_list04(self): output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")}) - self.assertEqual(output, str_prefix("[%(_)s'&']")) + self.assertEqual(output, "['&']") class FunctionTests(SimpleTestCase): diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 4589ac33bd..d3263d07a6 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -15,7 +15,7 @@ from django.test import ( Client, SimpleTestCase, TestCase, modify_settings, override_settings, ) 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.utils.translation import ugettext_lazy @@ -595,21 +595,19 @@ class AssertFormErrorTests(SimpleTestCase): self.assertFormError(response, 'form', 'email', 'Some error.') except AssertionError as e: self.assertIn( - str_prefix( - "The field 'email' on form 'form' in context 0 does not " - "contain the error 'Some error.' (actual errors: " - "[%(_)s'Enter a valid email address.'])" - ), str(e) + "The field 'email' on form 'form' in context 0 does not " + "contain the error 'Some error.' (actual errors: " + "['Enter a valid email address.'])", + str(e) ) try: self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc') except AssertionError as e: self.assertIn( - str_prefix( - "abc: The field 'email' on form 'form' in context 0 does " - "not contain the error 'Some error.' (actual errors: " - "[%(_)s'Enter a valid email address.'])", - ), str(e) + "abc: The field 'email' on form 'form' in context 0 does " + "not contain the error 'Some error.' (actual errors: " + "['Enter a valid email address.'])", + str(e) ) def test_unknown_nonfield_error(self): @@ -719,10 +717,10 @@ class AssertFormsetErrorTests(SimpleTestCase): def test_unknown_error(self): "An assertion is raised if the field doesn't contain the specified error" for prefix, kwargs in self.msg_prefixes: - msg = str_prefix( - prefix + "The field 'email' on formset 'my_formset', form 0 " + msg = prefix + ( + "The field 'email' on formset 'my_formset', form 0 " "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): 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): "An assertion is raised if the formsets non-field errors doesn't contain the provided error." for prefix, kwargs in self.msg_prefixes: - msg = str_prefix( - prefix + "The formset 'my_formset', form 0 in context 0 does not " + msg = prefix + ( + "The formset 'my_formset', form 0 in context 0 does not " "contain the non-field error 'Some error.' (actual errors: " - "[%(_)s'Non-field error.'])" + "['Non-field error.'])" ) with self.assertRaisesMessage(AssertionError, msg): 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): "An assertion is raised if the formsets non-form errors doesn't contain the provided error." for prefix, kwargs in self.msg_prefixes: - msg = str_prefix( - prefix + + msg = prefix + ( "The formset 'my_formset' in context 0 does not contain the " - "non-form error 'Some error.' (actual errors: [%(_)s'Forms " - "in a set must have distinct email addresses.'])" + "non-form error 'Some error.' (actual errors: ['Forms in a set " + "must have distinct email addresses.'])" ) with self.assertRaisesMessage(AssertionError, msg): self.assertFormsetError( diff --git a/tests/validators/tests.py b/tests/validators/tests.py index 124c2b1c68..ba7038094c 100644 --- a/tests/validators/tests.py +++ b/tests/validators/tests.py @@ -16,7 +16,6 @@ from django.core.validators import ( validate_unicode_slug, ) from django.test import SimpleTestCase -from django.test.utils import str_prefix try: from PIL import Image # noqa @@ -314,18 +313,18 @@ def create_simple_test_method(validator, expected, value, num): class TestSimpleValidators(SimpleTestCase): def test_single_message(self): v = ValidationError('Not Valid') - self.assertEqual(str(v), str_prefix("[%(_)s'Not Valid']")) - self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'Not Valid'])")) + self.assertEqual(str(v), "['Not Valid']") + self.assertEqual(repr(v), "ValidationError(['Not Valid'])") def test_message_list(self): v = ValidationError(['First Problem', 'Second Problem']) - self.assertEqual(str(v), str_prefix("[%(_)s'First Problem', %(_)s'Second Problem']")) - self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'First Problem', %(_)s'Second Problem'])")) + self.assertEqual(str(v), "['First Problem', 'Second Problem']") + self.assertEqual(repr(v), "ValidationError(['First Problem', 'Second Problem'])") def test_message_dict(self): v = ValidationError({'first': ['First Problem']}) - self.assertEqual(str(v), str_prefix("{%(_)s'first': [%(_)s'First Problem']}")) - self.assertEqual(repr(v), str_prefix("ValidationError({%(_)s'first': [%(_)s'First Problem']})")) + self.assertEqual(str(v), "{'first': ['First Problem']}") + self.assertEqual(repr(v), "ValidationError({'first': ['First Problem']})") def test_regex_validator_flags(self): with self.assertRaises(TypeError):