[pygobject] Fix IOChannel unittests for python 2.7



commit 9c6399bbf75c312b1ef4933d079712ea5b05a935
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Oct 30 12:01:44 2012 -0700

    Fix IOChannel unittests for python 2.7
    
    Use __future__ unicode_literals to minimize difference
    between python 2.7 and 3. Comparisons need to encode arguments as
    'UTF-8' for testing readline operations.
    Add backwards compatible "next" to support the python 2.7 iteration.
    Change isinstance(channel, file) to hasattr(channel, 'fileno') to
    support all python versions (and duck typing).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687047

 gi/overrides/GLib.py    |    4 +++-
 tests/test_iochannel.py |    1 +
 2 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index e1146ac..0085533 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -628,7 +628,7 @@ def io_add_watch(channel, priority, condition, callback=_unspecified, user_data=
                       PyGIDeprecationWarning)
         func_fdtransform = lambda _, cond, data: func(channel, cond, data)
         real_channel = GLib.IOChannel.unix_new(channel)
-    elif isinstance(channel, file):
+    elif hasattr(channel, 'fileno'):
         # backwards compatibility: Allow calling with Python file
         warnings.warn('Calling io_add_watch with a file object is deprecated; call it with a GLib.IOChannel object',
                       PyGIDeprecationWarning)
@@ -717,6 +717,8 @@ class IOChannel(GLib.IOChannel):
             return buf
         raise StopIteration
 
+    # Python 2.x compatibility
+    next = __next__
 
 IOChannel = override(IOChannel)
 __all__.append('IOChannel')
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
index c2db860..ec9a307 100644
--- a/tests/test_iochannel.py
+++ b/tests/test_iochannel.py
@@ -1,5 +1,6 @@
 # -*- Mode: Python -*-
 # encoding: UTF-8
+from __future__ import unicode_literals
 
 import unittest
 import tempfile



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