Commit 24a0aa54 authored by Michal Čihař's avatar Michal Čihař

Fix some file format tests for Python 3

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent a54691b2
...@@ -873,7 +873,7 @@ class PoFormat(FileFormat): ...@@ -873,7 +873,7 @@ class PoFormat(FileFormat):
@classmethod @classmethod
def create_new_file(cls, filename, code, base): def create_new_file(cls, filename, code, base):
"""Handles creation of new translation file.""" """Handles creation of new translation file."""
with open(base, 'r') as handle: with open(base, 'rb') as handle:
data = handle.read() data = handle.read()
# Assume input is UTF-8 if not specified # Assume input is UTF-8 if not specified
if b'Content-Type: text/plain; charset=CHARSET' in data: if b'Content-Type: text/plain; charset=CHARSET' in data:
......
...@@ -22,6 +22,7 @@ File format specific behavior. ...@@ -22,6 +22,7 @@ File format specific behavior.
''' '''
from __future__ import unicode_literals from __future__ import unicode_literals
import io
import tempfile import tempfile
from unittest import TestCase, SkipTest from unittest import TestCase, SkipTest
...@@ -116,7 +117,10 @@ class AutoFormatTest(SimpleTestCase): ...@@ -116,7 +117,10 @@ class AutoFormatTest(SimpleTestCase):
testdata = handle.read() testdata = handle.read()
# Create test file # Create test file
testfile = tempfile.NamedTemporaryFile(suffix='.{0}'.format(self.EXT)) testfile = tempfile.NamedTemporaryFile(
suffix='.{0}'.format(self.EXT),
mode='w+'
)
try: try:
# Write test data to file # Write test data to file
testfile.write(testdata) testfile.write(testdata)
...@@ -157,7 +161,10 @@ class AutoFormatTest(SimpleTestCase): ...@@ -157,7 +161,10 @@ class AutoFormatTest(SimpleTestCase):
def test_add(self): def test_add(self):
if self.FORMAT.supports_new_language(): if self.FORMAT.supports_new_language():
self.assertTrue(self.FORMAT.is_valid_base_for_new(self.BASE)) self.assertTrue(self.FORMAT.is_valid_base_for_new(self.BASE))
out = tempfile.NamedTemporaryFile(suffix='.{0}'.format(self.EXT)) out = tempfile.NamedTemporaryFile(
suffix='.{0}'.format(self.EXT),
mode='w+'
)
self.FORMAT.add_language(out.name, 'cs', self.BASE) self.FORMAT.add_language(out.name, 'cs', self.BASE)
data = out.read() data = out.read()
self.assertTrue(self.MATCH in data) self.assertTrue(self.MATCH in data)
...@@ -314,9 +321,9 @@ class OutputTest(TestCase): ...@@ -314,9 +321,9 @@ class OutputTest(TestCase):
out.write(json_input.encode('utf-8')) out.write(json_input.encode('utf-8'))
out.flush() out.flush()
JSONFormat(out.name).save() JSONFormat(out.name).save()
with open(out.name) as handle: with io.open(out.name) as handle:
self.assertEqual( self.assertEqual(
handle.read().decode('UTF-8'), handle.read(),
json_expected_output json_expected_output
) )
out.close() out.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment