From 05232a2604725400358c012fa17ac705c875a9f4 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Fri, 4 Feb 2011 16:17:45 +0000 Subject: [PATCH] [1.2.X] Modified a few tests methods to make sure no leaks of activated locale or USE_L10N setting value happen between tests. Backport of [15411] from trunk git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15412 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/admin_widgets/tests.py | 18 ++++++++++-------- tests/regressiontests/i18n/tests.py | 17 +++++------------ 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/regressiontests/admin_widgets/tests.py b/tests/regressiontests/admin_widgets/tests.py index 51d883f13a..e43ab83e9d 100644 --- a/tests/regressiontests/admin_widgets/tests.py +++ b/tests/regressiontests/admin_widgets/tests.py @@ -209,14 +209,16 @@ class AdminSplitDateTimeWidgetTest(TestCase): activate('de-at') old_USE_L10N = settings.USE_L10N - settings.USE_L10N = True - w.is_localized = True - self.assertEqual( - conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))), - '

Datum:
Zeit:

', - ) - deactivate() - settings.USE_L10N = old_USE_L10N + try: + settings.USE_L10N = True + w.is_localized = True + self.assertEqual( + conditional_escape(w.render('test', datetime(2007, 12, 1, 9, 30))), + '

Datum:
Zeit:

', + ) + finally: + deactivate() + settings.USE_L10N = old_USE_L10N class AdminFileWidgetTest(DjangoTestCase): diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index e7f78814b0..f1ab1e9aa0 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -233,10 +233,8 @@ class FormattingTests(TestCase): deactivate() def test_l10n_enabled(self): - """ - Catalan locale - """ settings.USE_L10N = True + # Catalan locale activate('ca') try: self.assertEqual('j \de F \de Y', get_format('DATE_FORMAT')) @@ -324,8 +322,6 @@ class FormattingTests(TestCase): deactivate() # English locale - - settings.USE_L10N = True activate('en') try: self.assertEqual('N j, Y', get_format('DATE_FORMAT')) @@ -459,13 +455,10 @@ class FormattingTests(TestCase): Tests the iter_format_modules function always yields format modules in a stable and correct order in presence of both base ll and ll_CC formats. """ - try: - old_l10n, settings.USE_L10N = settings.USE_L10N, True - en_format_mod = import_module('django.conf.locale.en.formats') - en_gb_format_mod = import_module('django.conf.locale.en_GB.formats') - self.assertEqual(list(iter_format_modules('en-gb')), [en_gb_format_mod, en_format_mod]) - finally: - settings.USE_L10N = old_l10n + settings.USE_L10N = True + en_format_mod = import_module('django.conf.locale.en.formats') + en_gb_format_mod = import_module('django.conf.locale.en_GB.formats') + self.assertEqual(list(iter_format_modules('en-gb')), [en_gb_format_mod, en_format_mod]) def test_get_format_modules_stability(self): activate('de')