2013-11-02 09:28:22 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django import conf
|
2013-11-05 13:30:31 +00:00
|
|
|
from django.contrib import admin
|
2013-11-02 09:28:22 +00:00
|
|
|
from django.test import TestCase, override_settings
|
|
|
|
from django.utils.autoreload import gen_filenames
|
|
|
|
|
|
|
|
LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
|
|
|
|
|
|
|
|
|
|
|
|
class TestFilenameGenerator(TestCase):
|
2014-07-05 12:43:12 +00:00
|
|
|
def setUp(self):
|
|
|
|
# Empty cached variables
|
|
|
|
from django.utils import autoreload
|
|
|
|
autoreload._cached_modules = set()
|
|
|
|
autoreload._cached_filenames = []
|
|
|
|
|
2013-11-02 09:28:22 +00:00
|
|
|
def test_django_locales(self):
|
|
|
|
"""
|
|
|
|
Test that gen_filenames() also yields the built-in django locale files.
|
|
|
|
"""
|
|
|
|
filenames = list(gen_filenames())
|
2013-11-05 13:30:31 +00:00
|
|
|
self.assertIn(os.path.join(os.path.dirname(conf.__file__), 'locale',
|
|
|
|
'nl', 'LC_MESSAGES', 'django.mo'),
|
|
|
|
filenames)
|
2013-11-02 09:28:22 +00:00
|
|
|
|
2013-11-05 13:30:31 +00:00
|
|
|
@override_settings(LOCALE_PATHS=(LOCALE_PATH,))
|
|
|
|
def test_locale_paths_setting(self):
|
|
|
|
"""
|
|
|
|
Test that gen_filenames also yields from LOCALE_PATHS locales.
|
|
|
|
"""
|
|
|
|
filenames = list(gen_filenames())
|
|
|
|
self.assertIn(os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
|
|
|
|
filenames)
|
2013-11-02 09:28:22 +00:00
|
|
|
|
2013-12-23 09:37:34 +00:00
|
|
|
@override_settings(INSTALLED_APPS=[])
|
2013-11-05 13:30:31 +00:00
|
|
|
def test_project_root_locale(self):
|
|
|
|
"""
|
|
|
|
Test that gen_filenames also yields from the current directory (project
|
|
|
|
root).
|
|
|
|
"""
|
|
|
|
old_cwd = os.getcwd()
|
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
try:
|
2013-12-23 09:37:34 +00:00
|
|
|
filenames = list(gen_filenames())
|
2013-11-05 13:30:31 +00:00
|
|
|
self.assertIn(
|
|
|
|
os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
|
|
|
|
filenames)
|
|
|
|
finally:
|
|
|
|
os.chdir(old_cwd)
|
2013-11-02 09:28:22 +00:00
|
|
|
|
2013-12-23 09:37:34 +00:00
|
|
|
@override_settings(INSTALLED_APPS=['django.contrib.admin'])
|
2013-11-02 09:28:22 +00:00
|
|
|
def test_app_locales(self):
|
|
|
|
"""
|
2013-12-19 21:33:46 +00:00
|
|
|
Test that gen_filenames also yields from locale dirs in installed apps.
|
2013-11-02 09:28:22 +00:00
|
|
|
"""
|
2013-12-23 09:37:34 +00:00
|
|
|
filenames = list(gen_filenames())
|
2013-11-05 13:30:31 +00:00
|
|
|
self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale',
|
|
|
|
'nl', 'LC_MESSAGES', 'django.mo'),
|
2013-11-02 09:28:22 +00:00
|
|
|
filenames)
|
2013-11-05 13:30:31 +00:00
|
|
|
|
|
|
|
@override_settings(USE_I18N=False)
|
|
|
|
def test_no_i18n(self):
|
|
|
|
"""
|
|
|
|
If i18n machinery is disabled, there is no need for watching the
|
|
|
|
locale files.
|
|
|
|
"""
|
|
|
|
filenames = list(gen_filenames())
|
|
|
|
self.assertNotIn(
|
|
|
|
os.path.join(os.path.dirname(conf.__file__), 'locale', 'nl',
|
|
|
|
'LC_MESSAGES', 'django.mo'),
|
|
|
|
filenames)
|
2014-07-05 12:43:12 +00:00
|
|
|
|
|
|
|
def test_only_new_files(self):
|
|
|
|
"""
|
|
|
|
When calling a second time gen_filenames with only_new = True, only
|
|
|
|
files from newly loaded modules should be given.
|
|
|
|
"""
|
|
|
|
filenames1 = list(gen_filenames())
|
|
|
|
from fractions import Fraction
|
|
|
|
filenames2 = list(gen_filenames(only_new=True))
|
|
|
|
self.assertEqual(len(filenames2), 1)
|
|
|
|
self.assertTrue(filenames2[0].endswith('fractions.py'))
|