From 8fe406864c5bbdd20e32d6127d377ed292006c5c Mon Sep 17 00:00:00 2001 From: Justin Hamade Date: Fri, 8 Aug 2014 22:47:35 +0200 Subject: [PATCH] Fixed #22336 -- Added path matching for makemessages ignore option This fixes a regression introduced by 9012a9e200. --- .../core/management/commands/makemessages.py | 3 +- .../commands/templates/subdir/ignored.html | 2 + tests/i18n/test_extraction.py | 46 ++++++++++++------- 3 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 tests/i18n/commands/templates/subdir/ignored.html diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index ae6a834b99..335cfab238 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -360,7 +360,8 @@ class Command(BaseCommand): Check if the given path should be ignored or not. """ filename = os.path.basename(path) - ignore = lambda pattern: fnmatch.fnmatchcase(filename, pattern) + ignore = lambda pattern: (fnmatch.fnmatchcase(filename, pattern) or + fnmatch.fnmatchcase(path, pattern)) return any(ignore(pattern) for pattern in ignore_patterns) dir_suffix = '%s*' % os.sep diff --git a/tests/i18n/commands/templates/subdir/ignored.html b/tests/i18n/commands/templates/subdir/ignored.html new file mode 100644 index 0000000000..d36a6fe881 --- /dev/null +++ b/tests/i18n/commands/templates/subdir/ignored.html @@ -0,0 +1,2 @@ +{% load i18n %} +{% trans "This subdir should be ignored too." %} diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index c4cb56e65e..cc8b067c81 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -360,35 +360,47 @@ class JavascriptExtractorTests(ExtractorTests): class IgnoredExtractorTests(ExtractorTests): - def test_ignore_option(self): + def _run_makemessages(self, **options): os.chdir(self.test_dir) - ignore_patterns = [ - os.path.join('ignore_dir', '*'), - 'xxx_*', - ] stdout = StringIO() management.call_command('makemessages', locale=[LOCALE], verbosity=2, - ignore_patterns=ignore_patterns, stdout=stdout) + stdout=stdout, **options) data = stdout.getvalue() - self.assertTrue("ignoring directory ignore_dir" in data) - self.assertTrue("ignoring file xxx_ignored.html" in data) self.assertTrue(os.path.exists(self.PO_FILE)) with open(self.PO_FILE, 'r') as fp: po_contents = fp.read() - self.assertMsgId('This literal should be included.', po_contents) - self.assertNotMsgId('This should be ignored.', po_contents) - self.assertNotMsgId('This should be ignored too.', po_contents) + return data, po_contents + + def test_ignore_directory(self): + out, po_contents = self._run_makemessages(ignore_patterns=[ + os.path.join('ignore_dir', '*'), + ]) + self.assertTrue("ignoring directory ignore_dir" in out) + self.assertMsgId('This literal should be included.', po_contents) + self.assertNotMsgId('This should be ignored.', po_contents) + + def test_ignore_subdirectory(self): + out, po_contents = self._run_makemessages(ignore_patterns=[ + 'templates/*/ignore.html', + 'templates/subdir/*', + ]) + self.assertTrue("ignoring directory subdir" in out) + self.assertNotMsgId('This subdir should be ignored too.', po_contents) + + def test_ignore_file_patterns(self): + out, po_contents = self._run_makemessages(ignore_patterns=[ + 'xxx_*', + ]) + self.assertTrue("ignoring file xxx_ignored.html" in out) + self.assertNotMsgId('This should be ignored too.', po_contents) @override_settings( STATIC_ROOT=os.path.join(this_directory, 'commands', 'static_root/'), MEDIA_ROOT=os.path.join(this_directory, 'commands', 'media_root/')) def test_media_static_dirs_ignored(self): - os.chdir(self.test_dir) - stdout = StringIO() - management.call_command('makemessages', locale=[LOCALE], verbosity=2, stdout=stdout) - data = stdout.getvalue() - self.assertIn("ignoring directory static_root", data) - self.assertIn("ignoring directory media_root", data) + out, _ = self._run_makemessages() + self.assertIn("ignoring directory static_root", out) + self.assertIn("ignoring directory media_root", out) class SymlinkExtractorTests(ExtractorTests):