From bb0a9a070b9570c85bcb17346dae6513e4ba6e76 Mon Sep 17 00:00:00 2001 From: Martin Brochhaus Date: Mon, 19 May 2014 13:23:45 +0800 Subject: Fixed #20477: Allowed list of modules for FORMAT_MODULE_PATH Previously the FORMAT_MODULE_PATH setting only accepted one string (dotted module path). A feature has been added to also allow a list of strings. This is useful when using several reusable third party apps that define new formats. We can now use them all and we can even override some of the formats by providing a project-wide format module. --- tests/i18n/other2/__init__.py | 0 tests/i18n/other2/locale/__init__.py | 0 tests/i18n/other2/locale/de/__init__.py | 0 tests/i18n/other2/locale/de/formats.py | 0 tests/i18n/tests.py | 24 ++++++++++++++++++++---- 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 tests/i18n/other2/__init__.py create mode 100644 tests/i18n/other2/locale/__init__.py create mode 100644 tests/i18n/other2/locale/de/__init__.py create mode 100644 tests/i18n/other2/locale/de/formats.py (limited to 'tests') diff --git a/tests/i18n/other2/__init__.py b/tests/i18n/other2/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/i18n/other2/locale/__init__.py b/tests/i18n/other2/locale/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/i18n/other2/locale/de/__init__.py b/tests/i18n/other2/locale/de/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/i18n/other2/locale/de/formats.py b/tests/i18n/other2/locale/de/formats.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 8d0fc963af..d07c0d94a0 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -738,11 +738,27 @@ class FormattingTests(TestCase): """ Tests the iter_format_modules function. """ + # Importing some format modules so that we can compare the returned + # modules with these expected modules + default_mod = import_module('django.conf.locale.de.formats') + test_mod = import_module('i18n.other.locale.de.formats') + test_mod2 = import_module('i18n.other2.locale.de.formats') + with translation.override('de-at', deactivate=True): - de_format_mod = import_module('django.conf.locale.de.formats') - self.assertEqual(list(iter_format_modules('de')), [de_format_mod]) - test_de_format_mod = import_module('i18n.other.locale.de.formats') - self.assertEqual(list(iter_format_modules('de', 'i18n.other.locale')), [test_de_format_mod, de_format_mod]) + # Should return the correct default module when no setting is set + self.assertEqual(list(iter_format_modules('de')), [default_mod]) + + # When the setting is a string, should return the given module and + # the default module + self.assertEqual( + list(iter_format_modules('de', 'i18n.other.locale')), + [test_mod, default_mod]) + + # When setting is a list of strings, should return the given + # modules and the default module + self.assertEqual( + list(iter_format_modules('de', ['i18n.other.locale', 'i18n.other2.locale'])), + [test_mod, test_mod2, default_mod]) def test_iter_format_modules_stability(self): """ -- cgit v1.3