From fa08d27fb714534670b431fde0cd04a17d637585 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 4 Nov 2015 21:50:16 +0100 Subject: Fixed #25677 -- Prevented decoding errors in/after Popen calls Thanks Gavin Wahl for the report and Tim Graham for the review. --- .../i18n/commands/locale/ko/LC_MESSAGES/django.po | 24 +++++++++++++++++ tests/i18n/test_compilation.py | 30 ++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 tests/i18n/commands/locale/ko/LC_MESSAGES/django.po (limited to 'tests') diff --git a/tests/i18n/commands/locale/ko/LC_MESSAGES/django.po b/tests/i18n/commands/locale/ko/LC_MESSAGES/django.po new file mode 100644 index 0000000000..30ed4f1bd9 --- /dev/null +++ b/tests/i18n/commands/locale/ko/LC_MESSAGES/django.po @@ -0,0 +1,24 @@ +# This file intentionally contains a wrong msgstr that will produce +# a msgfmt error. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-11-04 12:01-0700\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: foo/password_validation.py:17 +#, python-brace-format +msgid "Your password must contain a symbol: {symbols}" +msgstr "[Ẏǿŭř ƥȧşşẇǿřḓ ḿŭşŧ ƈǿƞŧȧīƞ ȧ şẏḿƀǿŀ: {şẏḿƀǿŀş} ΐΰϖΐ ϖΐẛϕϐ]" diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index e784b0a991..8508ecb855 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import gettext as gettext_module import os @@ -12,7 +13,7 @@ from django.core.management import ( from django.core.management.utils import find_command from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, captured_stdout -from django.utils import translation +from django.utils import six, translation from django.utils._os import upath from django.utils.encoding import force_text from django.utils.six import StringIO @@ -154,17 +155,26 @@ class ExcludedLocaleCompilationTests(MessageCompilationTests): class CompilationErrorHandling(MessageCompilationTests): - - LOCALE = 'ja' - MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE - - def setUp(self): - super(CompilationErrorHandling, self).setUp() - self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.MO_FILE)) - def test_error_reported_by_msgfmt(self): + # po file contains wrong po formatting. + mo_file = 'locale/ja/LC_MESSAGES/django.mo' + self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file)) with self.assertRaises(CommandError): - call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO()) + call_command('compilemessages', locale=['ja'], verbosity=0) + + def test_msgfmt_error_including_non_ascii(self): + # po file contains invalid msgstr content (triggers non-ascii error content). + mo_file = 'locale/ko/LC_MESSAGES/django.mo' + self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file)) + if six.PY2: + # Various assertRaises on PY2 don't support unicode error messages. + try: + call_command('compilemessages', locale=['ko'], verbosity=0) + except CommandError as err: + self.assertIn("'�' cannot start a field name", six.text_type(err)) + else: + with self.assertRaisesMessage(CommandError, "'�' cannot start a field name"): + call_command('compilemessages', locale=['ko'], verbosity=0) class ProjectAndAppTests(MessageCompilationTests): -- cgit v1.3