diff options
| author | Tai Lee <tai.lee@3030.com.au> | 2013-05-06 13:32:07 +1000 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2013-05-07 21:36:51 +0200 |
| commit | 23b234a9d9ea26acb9bb12ba14231ce8844d2e53 (patch) | |
| tree | a9a929e29f880ea123d2795d00c0765d6626e8ca /tests | |
| parent | acd9dc3888aa8af881b917028062c3bdca6e610c (diff) | |
[1.5.x] Fixed #20354 -- `makemessages` no longer crashes with `UnicodeDecodeError`
Handle the `UnicodeDecodeError` exception, send a warning to `stdout` with the
file name and location, and continue processing other files.
Backport of 99a6f0e77 from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/i18n/commands/extraction.py | 15 | ||||
| -rw-r--r-- | tests/regressiontests/i18n/commands/not_utf8.sample | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index aa5efe1967..47d58c4d63 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -27,6 +27,10 @@ class ExtractorTests(TestCase): return shutil.rmtree(dname) + def rmfile(self, filepath): + if os.path.exists(filepath): + os.remove(filepath) + def tearDown(self): os.chdir(self.test_dir) try: @@ -120,12 +124,21 @@ class BasicExtractorTests(ExtractorTests): # Check that the temporary file was cleaned up self.assertFalse(os.path.exists('./templates/template_with_error.html.py')) + def test_unicode_decode_error(self): + os.chdir(self.test_dir) + shutil.copyfile('./not_utf8.sample', './not_utf8.txt') + self.addCleanup(self.rmfile, os.path.join(self.test_dir, 'not_utf8.txt')) + stdout = StringIO() + management.call_command('makemessages', locale=LOCALE, stdout=stdout) + self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .", + force_text(stdout.getvalue())) + def test_extraction_warning(self): os.chdir(self.test_dir) shutil.copyfile('./code.sample', './code_sample.py') + self.addCleanup(self.rmfile, os.path.join(self.test_dir, 'code_sample.py')) stdout = StringIO() management.call_command('makemessages', locale=LOCALE, stdout=stdout) - os.remove('./code_sample.py') self.assertIn("code_sample.py:4", force_text(stdout.getvalue())) def test_template_message_context_extractor(self): diff --git a/tests/regressiontests/i18n/commands/not_utf8.sample b/tests/regressiontests/i18n/commands/not_utf8.sample new file mode 100644 index 0000000000..6449f52803 --- /dev/null +++ b/tests/regressiontests/i18n/commands/not_utf8.sample @@ -0,0 +1 @@ +Copyright (c) 2009 Øyvind Sean Kinsey, oyvind@kinsey.no
\ No newline at end of file |
