[pygobject] tests: Fix unicode vs. str issues in Python 2
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests: Fix unicode vs. str issues in Python 2
- Date: Mon, 19 Nov 2012 13:35:15 +0000 (UTC)
commit 567aae6e7c56bb89f53fcfccb1b0bc732f85b847
Author: Martin Pitt <martinpitt gnome org>
Date: Mon Nov 19 14:34:13 2012 +0100
tests: Fix unicode vs. str issues in Python 2
Some of the tests assumed a system default encoding of UTF-8, which is not true
in Python 2 unless pygtkcompat is imported. Commit e617f76 uncovered this.
tests/test_gi.py | 8 ++++----
tests/test_iochannel.py | 16 +++++++++-------
2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 270a883..4837204 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -19,7 +19,7 @@ from gi.repository import GObject, GLib, Gio
from gi.repository import GIMarshallingTests
-from compathelper import _bytes
+from compathelper import _bytes, _unicode
if sys.version_info < (3, 0):
CONSTANT_UTF8 = "const \xe2\x99\xa5 utf8"
@@ -696,7 +696,7 @@ class TestFilename(unittest.TestCase):
shutil.rmtree(self.workdir)
def test_filename_in(self):
- fname = os.path.join(self.workdir, 'testÃÃ.txt')
+ fname = os.path.join(self.workdir, _unicode('testÃÃ.txt'))
self.assertRaises(GLib.GError, GLib.file_get_contents, fname)
with open(fname.encode('UTF-8'), 'wb') as f:
@@ -711,8 +711,8 @@ class TestFilename(unittest.TestCase):
dirname = GLib.Dir.make_tmp('testÃÃ.XXXXXX')
self.assertTrue('/testÃÃ.' in dirname, dirname)
- self.assertTrue(os.path.isdir(dirname.encode('UTF-8')))
- os.rmdir(dirname.encode('UTF-8'))
+ self.assertTrue(os.path.isdir(dirname))
+ os.rmdir(dirname)
def test_filename_type_error(self):
self.assertRaises(TypeError, GLib.file_get_contents, 23)
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
index f0fe273..0cc1b4b 100644
--- a/tests/test_iochannel.py
+++ b/tests/test_iochannel.py
@@ -12,6 +12,8 @@ import warnings
from gi.repository import GLib
from gi import PyGIDeprecationWarning
+from compathelper import _unicode
+
class IOChannel(unittest.TestCase):
def setUp(self):
@@ -40,11 +42,11 @@ second line
ch = GLib.IOChannel(filename=self.testutf8)
self.assertEqual(ch.get_encoding(), 'UTF-8')
self.assertTrue(ch.get_close_on_unref())
- self.assertEqual(ch.readline(), 'hello â world\n')
+ self.assertEqual(_unicode(ch.readline()), 'hello â world\n')
self.assertEqual(ch.get_buffer_condition(), GLib.IOCondition.IN)
self.assertEqual(ch.readline(), 'second line\n')
self.assertEqual(ch.readline(), '\n')
- self.assertEqual(ch.readline(), 'Ã demain!')
+ self.assertEqual(_unicode(ch.readline()), 'Ã demain!')
self.assertEqual(ch.get_buffer_condition(), 0)
self.assertEqual(ch.readline(), '')
ch.close()
@@ -53,10 +55,10 @@ second line
ch = GLib.IOChannel(filename=self.testlatin1, mode='r')
ch.set_encoding('latin1')
self.assertEqual(ch.get_encoding(), 'latin1')
- self.assertEqual(ch.readline(), 'hellà world\n')
+ self.assertEqual(_unicode(ch.readline()), 'hellà world\n')
self.assertEqual(ch.readline(), 'second line\n')
self.assertEqual(ch.readline(), '\n')
- self.assertEqual(ch.readline(), 'Ã demain!')
+ self.assertEqual(_unicode(ch.readline()), 'Ã demain!')
ch.close()
def test_file_iter(self):
@@ -65,7 +67,7 @@ second line
for item in ch:
items.append(item)
self.assertEqual(len(items), 4)
- self.assertEqual(items[0], 'hello â world\n')
+ self.assertEqual(_unicode(items[0]), 'hello â world\n')
ch.close()
def test_file_readlines(self):
@@ -75,8 +77,8 @@ second line
# empty one
self.assertGreaterEqual(len(lines), 4)
self.assertLessEqual(len(lines), 5)
- self.assertEqual(lines[0], 'hello â world\n')
- self.assertEqual(lines[3], 'Ã demain!')
+ self.assertEqual(_unicode(lines[0]), 'hello â world\n')
+ self.assertEqual(_unicode(lines[3]), 'Ã demain!')
if len(lines) == 4:
self.assertEqual(lines[4], '')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]