Commit 8fe40686 authored by Justin Hamade's avatar Justin Hamade Committed by Claude Paroz
Browse files

Fixed #22336 -- Added path matching for makemessages ignore option

This fixes a regression introduced by 9012a9e2.
parent 09c0fa2c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
{% load i18n %}
{% trans "This subdir should be ignored too." %}
+29 −17
Original line number Diff line number Diff line
@@ -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()
        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):