mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[py3] Fixed compilemessages tests
This commit is contained in:
		| @@ -1,3 +1,5 @@ | |||||||
|  | from __future__ import unicode_literals | ||||||
|  |  | ||||||
| import codecs | import codecs | ||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
| @@ -7,7 +9,7 @@ from django.core.management.base import BaseCommand, CommandError | |||||||
| def has_bom(fn): | def has_bom(fn): | ||||||
|     with open(fn, 'rb') as f: |     with open(fn, 'rb') as f: | ||||||
|         sample = f.read(4) |         sample = f.read(4) | ||||||
|     return sample[:3] == '\xef\xbb\xbf' or \ |     return sample[:3] == b'\xef\xbb\xbf' or \ | ||||||
|             sample.startswith(codecs.BOM_UTF16_LE) or \ |             sample.startswith(codecs.BOM_UTF16_LE) or \ | ||||||
|             sample.startswith(codecs.BOM_UTF16_BE) |             sample.startswith(codecs.BOM_UTF16_BE) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,10 +1,10 @@ | |||||||
| import os | import os | ||||||
| from io import BytesIO |  | ||||||
|  |  | ||||||
| from django.core.management import call_command, CommandError | from django.core.management import call_command, CommandError | ||||||
| from django.test import TestCase | from django.test import TestCase | ||||||
| from django.test.utils import override_settings | from django.test.utils import override_settings | ||||||
| from django.utils import translation | from django.utils import translation | ||||||
|  | from django.utils.six import StringIO | ||||||
|  |  | ||||||
| test_dir = os.path.abspath(os.path.dirname(__file__)) | test_dir = os.path.abspath(os.path.dirname(__file__)) | ||||||
|  |  | ||||||
| @@ -26,7 +26,7 @@ class PoFileTests(MessageCompilationTests): | |||||||
|         os.chdir(test_dir) |         os.chdir(test_dir) | ||||||
|         with self.assertRaisesRegexp(CommandError, |         with self.assertRaisesRegexp(CommandError, | ||||||
|                 "file has a BOM \(Byte Order Mark\)"): |                 "file has a BOM \(Byte Order Mark\)"): | ||||||
|             call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO()) |             call_command('compilemessages', locale=self.LOCALE, stderr=StringIO()) | ||||||
|         self.assertFalse(os.path.exists(self.MO_FILE)) |         self.assertFalse(os.path.exists(self.MO_FILE)) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -42,7 +42,7 @@ class PoFileContentsTests(MessageCompilationTests): | |||||||
|  |  | ||||||
|     def test_percent_symbol_in_po_file(self): |     def test_percent_symbol_in_po_file(self): | ||||||
|         os.chdir(test_dir) |         os.chdir(test_dir) | ||||||
|         call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO()) |         call_command('compilemessages', locale=self.LOCALE, stderr=StringIO()) | ||||||
|         self.assertTrue(os.path.exists(self.MO_FILE)) |         self.assertTrue(os.path.exists(self.MO_FILE)) | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -57,7 +57,7 @@ class PercentRenderingTests(MessageCompilationTests): | |||||||
|     def test_percent_symbol_escaping(self): |     def test_percent_symbol_escaping(self): | ||||||
|         from django.template import Template, Context |         from django.template import Template, Context | ||||||
|         os.chdir(test_dir) |         os.chdir(test_dir) | ||||||
|         call_command('compilemessages', locale=self.LOCALE, stderr=BytesIO()) |         call_command('compilemessages', locale=self.LOCALE, stderr=StringIO()) | ||||||
|         with translation.override(self.LOCALE): |         with translation.override(self.LOCALE): | ||||||
|             t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}') |             t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}') | ||||||
|             rendered = t.render(Context({})) |             rendered = t.render(Context({})) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user