[pygobject] tests: Fix for Python 2



commit c5343d329ebb452d97afac30e4120ebab8477556
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Nov 12 07:47:02 2012 +0100

    tests: Fix for Python 2
    
    Add quirks for Python 2's string handling, and disable the
    Everything.test_array_gint8_in() as there seems to be no way of creating a byte
    array in Python 2.

 tests/test_everything.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 327fd5b..26798f2 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -256,7 +256,9 @@ class TestEverything(unittest.TestCase):
         self.assertEqual(timeout.get_int32(), 10)
 
     def test_string(self):
-        const_str = b'const \xe2\x99\xa5 utf8'.decode('UTF-8')
+        const_str = b'const \xe2\x99\xa5 utf8'
+        if sys.version_info >= (3, 0):
+            const_str = const_str.decode('UTF-8')
         noconst_str = 'non' + const_str
 
         self.assertEqual(Everything.test_utf8_const_return(), const_str)
@@ -396,7 +398,8 @@ class TestEverything(unittest.TestCase):
         self.assertEqual(Everything.test_array_int_none_out(), [1, 2, 3, 4, 5])
         self.assertEqual(Everything.test_array_int_inout([1, 5, 42, -8]), [6, 43, -7])
 
-        self.assertEqual(Everything.test_array_gint8_in(b'\x01\x03\x05'), 9)
+        if sys.version_info >= (3, 0):
+            self.assertEqual(Everything.test_array_gint8_in(b'\x01\x03\x05'), 9)
         self.assertEqual(Everything.test_array_gint8_in([1, 3, 5, -50]), -41)
         self.assertEqual(Everything.test_array_gint16_in([256, 257, -1000, 10000]), 9513)
         self.assertEqual(Everything.test_array_gint32_in([30000, 1, -2]), 29999)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]