Commit 165f44aa authored by Claude Paroz's avatar Claude Paroz
Browse files

Combine consecutive with statements

Python 2.7 allows to combine several 'with' instructions.
parent 22c6497f
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -121,8 +121,7 @@ class AuthenticationFormTest(TestCase):
                         [force_text(form.error_messages['inactive'])])

    def test_inactive_user_i18n(self):
        with self.settings(USE_I18N=True):
            with translation.override('pt-br', deactivate=True):
        with self.settings(USE_I18N=True), translation.override('pt-br', deactivate=True):
            # The user is inactive.
            data = {
                'username': 'inactive',
+14 −15
Original line number Diff line number Diff line
@@ -77,14 +77,13 @@ class HumanizeTests(TransRealMixin, TestCase):
                       '100', '1,000', '10,123', '10,311', '1,000,000', '1,234,567.1234567', '1,234,567.1234567',
                     None)

        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False):
            with translation.override('en'):
        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=False), \
                translation.override('en'):
            self.humanize_tester(test_list, result_list, 'intcomma')

    def test_intcomma_without_number_grouping(self):
        # Regression for #17414
        with translation.override('ja'):
            with self.settings(USE_L10N=True):
        with translation.override('ja'), self.settings(USE_L10N=True):
            self.humanize_tester([100], ['100'], 'intcomma')

    def test_intword(self):
@@ -104,8 +103,8 @@ class HumanizeTests(TransRealMixin, TestCase):
                     '100', '1000', '10123', '10311', '1000000', None)
        result_list = ('100', '1.000', '10.123', '10.311', '1.000.000', '1.234.567,25',
                       '100', '1.000', '10.123', '10.311', '1.000.000', None)
        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
            with translation.override('de'):
        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True), \
                translation.override('de'):
            self.humanize_tester(test_list, result_list, 'intcomma')

    def test_i18n_intword(self):
@@ -113,8 +112,8 @@ class HumanizeTests(TransRealMixin, TestCase):
                     '1000000000', '2000000000', '6000000000000')
        result_list = ('100', '1,0 Million', '1,2 Millionen', '1,3 Millionen',
                       '1,0 Milliarde', '2,0 Milliarden', '6,0 Billionen')
        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True):
            with translation.override('de'):
        with self.settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True), \
                translation.override('de'):
            self.humanize_tester(test_list, result_list, 'intword')

    def test_apnumber(self):
@@ -162,8 +161,8 @@ class HumanizeTests(TransRealMixin, TestCase):

        orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime
        try:
            with override_settings(TIME_ZONE="America/Chicago", USE_TZ=True):
                with translation.override('en'):
            with override_settings(TIME_ZONE="America/Chicago", USE_TZ=True), \
                    translation.override('en'):
                self.humanize_tester([dt], ['yesterday'], 'naturalday')
        finally:
            humanize.datetime = orig_humanize_datetime
+10 −13
Original line number Diff line number Diff line
@@ -524,8 +524,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
        if the default language is non-English but the selected language
        is English. See #13388 and #3594 for more details.
        """
        with self.settings(LANGUAGE_CODE='fr'):
            with translation.override('en-us'):
        with self.settings(LANGUAGE_CODE='fr'), translation.override('en-us'):
            response = self.client.get('/test_admin/admin/jsi18n/')
            self.assertNotContains(response, 'Choisir une heure')

@@ -534,8 +533,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
        Makes sure that the fallback language is still working properly
        in cases where the selected language cannot be found.
        """
        with self.settings(LANGUAGE_CODE='fr'):
            with translation.override('none'):
        with self.settings(LANGUAGE_CODE='fr'), translation.override('none'):
            response = self.client.get('/test_admin/admin/jsi18n/')
            self.assertContains(response, 'Choisir une heure')

@@ -544,8 +542,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
        Check if L10N is deactivated, the JavaScript i18n view doesn't
        return localized date/time formats. Refs #14824.
        """
        with self.settings(LANGUAGE_CODE='ru', USE_L10N=False):
            with translation.override('none'):
        with self.settings(LANGUAGE_CODE='ru', USE_L10N=False), translation.override('none'):
            response = self.client.get('/test_admin/admin/jsi18n/')
            self.assertNotContains(response, '%d.%m.%Y %H:%M:%S')
            self.assertContains(response, '%Y-%m-%d %H:%M:%S')
+6 −7
Original line number Diff line number Diff line
@@ -295,8 +295,7 @@ class AdminSplitDateTimeWidgetTest(DjangoTestCase):
    def test_localization(self):
        w = widgets.AdminSplitDateTime()

        with self.settings(USE_L10N=True):
            with translation.override('de-at'):
        with self.settings(USE_L10N=True), translation.override('de-at'):
            w.is_localized = True
            self.assertHTMLEqual(
                w.render('test', datetime(2007, 12, 1, 9, 30)),
+18 −19
Original line number Diff line number Diff line
@@ -647,8 +647,7 @@ class DefaultFiltersI18NTests(TransRealMixin, TestCase):

    def test_localized_filesizeformat(self):
        # NOTE: \xa0 avoids wrapping between value and unit
        with self.settings(USE_L10N=True):
            with translation.override('de', deactivate=True):
        with self.settings(USE_L10N=True), translation.override('de', deactivate=True):
            self.assertEqual(filesizeformat(1023), '1023\xa0Bytes')
            self.assertEqual(filesizeformat(1024), '1,0\xa0KB')
            self.assertEqual(filesizeformat(10*1024), '10,0\xa0KB')
Loading