summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:01 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:48:04 +0900
commitd80fc1d31f28c6bcf9ea34b253e8765321616c3c (patch)
tree53afc44a25c72df0a698294b6be95695dfa643ba /tests
parent52620756e3ccf2925e140a254d340d3ba29f3ad5 (diff)
downloadpygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.tar.gz
pygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.tar.bz2
pygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.zip
Imported Upstream version 3.7.1
Change-Id: I4c5c3aae69e883da127f15b41c102f953e8cc74c Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/Makefile.in7
-rw-r--r--tests/test_everything.py4
-rw-r--r--tests/test_gdbus.py11
-rw-r--r--tests/test_gi.py9
-rw-r--r--tests/test_iochannel.py259
-rw-r--r--tests/test_mainloop.py19
-rw-r--r--tests/test_properties.py65
-rw-r--r--tests/test_source.py13
9 files changed, 85 insertions, 303 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5cd2b95..7a619bf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,7 +87,6 @@ EXTRA_DIST = \
test_glib.py \
test_gobject.py \
test_interface.py \
- test_iochannel.py \
test_mainloop.py \
test_option.py \
test_properties.py \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index e5033c5..9993ec7 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -59,10 +59,8 @@ subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \
- $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \
- $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
- $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/m4/python.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/python.m4 \
+ $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -329,7 +327,6 @@ EXTRA_DIST = \
test_glib.py \
test_gobject.py \
test_interface.py \
- test_iochannel.py \
test_mainloop.py \
test_option.py \
test_properties.py \
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 600edbf..4c4535f 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -287,7 +287,7 @@ class TestNullableArgs(unittest.TestCase):
@unittest.skipUnless(has_cairo, 'built without cairo support')
class TestCallbacks(unittest.TestCase):
called = False
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
def test_callback(self):
TestCallbacks.called = False
@@ -398,7 +398,7 @@ class TestCallbacks(unittest.TestCase):
def test_async_ready_callback(self):
TestCallbacks.called = False
- TestCallbacks.main_loop = GObject.MainLoop()
+ TestCallbacks.main_loop = GLib.MainLoop()
def callback(obj, result, user_data):
TestCallbacks.main_loop.quit()
diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py
index b129419..bb5f2d9 100644
--- a/tests/test_gdbus.py
+++ b/tests/test_gdbus.py
@@ -3,7 +3,6 @@
import unittest
-from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
@@ -68,7 +67,7 @@ class TestGDBusClient(unittest.TestCase):
finally:
user_data['main_loop'].quit()
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
data = {'main_loop': main_loop}
self.dbus_proxy.call('ListNames', None,
Gio.DBusCallFlags.NO_AUTO_START, 500, None,
@@ -90,7 +89,7 @@ class TestGDBusClient(unittest.TestCase):
finally:
user_data['main_loop'].quit()
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
data = {'main_loop': main_loop}
self.dbus_proxy.call('UnknownMethod', None,
Gio.DBusCallFlags.NO_AUTO_START, 500, None,
@@ -162,7 +161,7 @@ class TestGDBusClient(unittest.TestCase):
user_data['result'] = result
user_data['main_loop'].quit()
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
data = {'main_loop': main_loop}
self.dbus_proxy.ListNames('()', result_handler=call_done, user_data=data)
main_loop.run()
@@ -178,7 +177,7 @@ class TestGDBusClient(unittest.TestCase):
user_data['result'] = result
user_data['main_loop'].quit()
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
data = {'main_loop': main_loop}
self.dbus_proxy.ListNames('(s)', 'invalid_argument',
result_handler=call_done, user_data=data)
@@ -197,7 +196,7 @@ class TestGDBusClient(unittest.TestCase):
user_data['error'] = error
user_data['main_loop'].quit()
- main_loop = GObject.MainLoop()
+ main_loop = GLib.MainLoop()
data = {'main_loop': main_loop}
self.dbus_proxy.ListNames('(s)', 'invalid_argument',
result_handler=call_done,
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 315867a..51cb6f9 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -64,15 +64,6 @@ class TestConstant(unittest.TestCase):
def test_constant_number(self):
self.assertEqual(CONSTANT_NUMBER, GIMarshallingTests.CONSTANT_NUMBER)
- def test_min_max_int(self):
- self.assertEqual(GLib.MAXINT32, 2 ** 31 - 1)
- self.assertEqual(GLib.MININT32, -2 ** 31)
- self.assertEqual(GLib.MAXUINT32, 2 ** 32 - 1)
-
- self.assertEqual(GLib.MAXINT64, 2 ** 63 - 1)
- self.assertEqual(GLib.MININT64, -2 ** 63)
- self.assertEqual(GLib.MAXUINT64, 2 ** 64 - 1)
-
class TestBoolean(unittest.TestCase):
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
deleted file mode 100644
index 8c035e9..0000000
--- a/tests/test_iochannel.py
+++ /dev/null
@@ -1,259 +0,0 @@
-# -*- Mode: Python -*-
-# encoding: UTF-8
-
-import unittest
-import tempfile
-import os.path
-import fcntl
-import shutil
-
-from gi.repository import GLib
-
-
-class IOChannel(unittest.TestCase):
- def setUp(self):
- self.workdir = tempfile.mkdtemp()
-
- self.testutf8 = os.path.join(self.workdir, 'testutf8.txt')
- with open(self.testutf8, 'wb') as f:
- f.write('''hello ♥ world
-second line
-
-À demain!'''.encode('UTF-8'))
-
- self.testlatin1 = os.path.join(self.workdir, 'testlatin1.txt')
- with open(self.testlatin1, 'wb') as f:
- f.write(b'''hell\xf8 world
-second line
-
-\xc0 demain!''')
-
- self.testout = os.path.join(self.workdir, 'testout.txt')
-
- def tearDown(self):
- shutil.rmtree(self.workdir)
-
- def test_file_readline_utf8(self):
- 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(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(ch.get_buffer_condition(), 0)
- self.assertEqual(ch.readline(), '')
- ch.close()
-
- def test_file_readline_latin1(self):
- 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(ch.readline(), 'second line\n')
- self.assertEqual(ch.readline(), '\n')
- self.assertEqual(ch.readline(), 'À demain!')
- ch.close()
-
- def test_file_iter(self):
- items = []
- ch = GLib.IOChannel(filename=self.testutf8)
- for item in ch:
- items.append(item)
- self.assertEqual(len(items), 4)
- self.assertEqual(items[0], 'hello ♥ world\n')
- ch.close()
-
- def test_file_readlines(self):
- ch = GLib.IOChannel(filename=self.testutf8)
- lines = ch.readlines()
- # Note, this really ought to be 4, but the static bindings add an extra
- # empty one
- self.assertGreaterEqual(len(lines), 4)
- self.assertLessEqual(len(lines), 5)
- self.assertEqual(lines[0], 'hello ♥ world\n')
- self.assertEqual(lines[3], 'À demain!')
- if len(lines) == 4:
- self.assertEqual(lines[4], '')
-
- def test_file_read(self):
- ch = GLib.IOChannel(filename=self.testutf8)
- with open(self.testutf8, 'rb') as f:
- self.assertEqual(ch.read(), f.read())
-
- ch = GLib.IOChannel(filename=self.testutf8)
- with open(self.testutf8, 'rb') as f:
- self.assertEqual(ch.read(10), f.read(10))
-
- ch = GLib.IOChannel(filename=self.testutf8)
- with open(self.testutf8, 'rb') as f:
- self.assertEqual(ch.read(max_count=15), f.read(15))
-
- def test_seek(self):
- ch = GLib.IOChannel(filename=self.testutf8)
- ch.seek(2)
- self.assertEqual(ch.read(3), b'llo')
-
- ch.seek(2, 0) # SEEK_SET
- self.assertEqual(ch.read(3), b'llo')
-
- ch.seek(1, 1) # SEEK_CUR, skip the space
- self.assertEqual(ch.read(3), b'\xe2\x99\xa5')
-
- ch.seek(2, 2) # SEEK_END
- # FIXME: does not work currently
- #self.assertEqual(ch.read(2), b'n!')
-
- # invalid whence value
- self.assertRaises(ValueError, ch.seek, 0, 3)
-
- def test_file_write(self):
- ch = GLib.IOChannel(filename=self.testout, mode='w')
- ch.set_encoding('latin1')
- ch.write('hellø world\n')
- ch.close()
- ch = GLib.IOChannel(filename=self.testout, mode='a')
- ch.set_encoding('latin1')
- ch.write('À demain!')
- ch.close()
-
- with open(self.testout, 'rb') as f:
- self.assertEqual(f.read().decode('latin1'), 'hellø world\nÀ demain!')
-
- def test_file_writelines(self):
- ch = GLib.IOChannel(filename=self.testout, mode='w')
- ch.writelines(['foo', 'bar\n', 'baz\n', 'end'])
- ch.close()
-
- with open(self.testout, 'r') as f:
- self.assertEqual(f.read(), 'foobar\nbaz\nend')
-
- def test_buffering(self):
- writer = GLib.IOChannel(filename=self.testout, mode='w')
- writer.set_encoding(None)
- self.assertTrue(writer.get_buffered())
- self.assertGreater(writer.get_buffer_size(), 10)
-
- reader = GLib.IOChannel(filename=self.testout, mode='r')
-
- # does not get written immediately on buffering
- writer.write('abc')
- self.assertEqual(reader.read(), b'')
- writer.flush()
- self.assertEqual(reader.read(), b'abc')
-
- # does get written immediately without buffering
- writer.set_buffered(False)
- writer.write('def')
- self.assertEqual(reader.read(), b'def')
-
- # writes after buffer overflow
- writer.set_buffer_size(10)
- writer.write('0123456789012')
- self.assertTrue(reader.read().startswith(b'012'))
- writer.flush()
- reader.read() # ignore bits written after flushing
-
- # closing flushes
- writer.set_buffered(True)
- writer.write('ghi')
- writer.close()
- self.assertEqual(reader.read(), b'ghi')
- reader.close()
-
- def test_fd_read(self):
- (r, w) = os.pipe()
-
- ch = GLib.IOChannel(filedes=r)
- ch.set_encoding(None)
- ch.set_flags(ch.get_flags() | GLib.IOFlags.NONBLOCK)
- self.assertNotEqual(ch.get_flags() | GLib.IOFlags.NONBLOCK, 0)
- self.assertEqual(ch.read(), b'')
- os.write(w, b'\x01\x02')
- self.assertEqual(ch.read(), b'\x01\x02')
-
- # now test blocking case, after closing the write end
- ch.set_flags(ch.get_flags() & ~GLib.IOFlags.NONBLOCK)
- os.write(w, b'\x03\x04')
- os.close(w)
- self.assertEqual(ch.read(), b'\x03\x04')
-
- ch.close()
-
- def test_fd_write(self):
- (r, w) = os.pipe()
- fcntl.fcntl(r, fcntl.F_SETFL, fcntl.fcntl(r, fcntl.F_GETFL) | os.O_NONBLOCK)
-
- ch = GLib.IOChannel(filedes=w, mode='w')
- ch.set_encoding(None)
- ch.set_buffered(False)
- ch.write(b'\x01\x02')
- self.assertEqual(os.read(r, 10), b'\x01\x02')
-
- # now test blocking case, after closing the write end
- fcntl.fcntl(r, fcntl.F_SETFL, fcntl.fcntl(r, fcntl.F_GETFL) & ~os.O_NONBLOCK)
- ch.write(b'\x03\x04')
- ch.close()
- self.assertEqual(os.read(r, 10), b'\x03\x04')
- os.close(r)
-
- def test_add_watch_no_data(self):
- (r, w) = os.pipe()
-
- ch = GLib.IOChannel(filedes=r)
- ch.set_encoding(None)
- ch.set_flags(ch.get_flags() | GLib.IOFlags.NONBLOCK)
-
- cb_reads = []
-
- def cb(channel, condition):
- self.assertEqual(channel, ch)
- self.assertEqual(condition, GLib.IOCondition.IN)
- cb_reads.append(channel.read())
- return True
-
- ch.add_watch(GLib.IOCondition.IN, cb)
-
- ml = GLib.MainLoop()
-
- GLib.timeout_add(10, lambda: os.write(w, b'a') and False)
- GLib.timeout_add(100, lambda: os.write(w, b'b') and False)
- GLib.timeout_add(200, ml.quit)
- ml.run()
-
- self.assertEqual(cb_reads, [b'a', b'b'])
-
- def test_add_watch_data_priority(self):
- (r, w) = os.pipe()
-
- ch = GLib.IOChannel(filedes=r)
- ch.set_encoding(None)
- ch.set_flags(ch.get_flags() | GLib.IOFlags.NONBLOCK)
-
- cb_reads = []
-
- def cb(channel, condition, data):
- self.assertEqual(channel, ch)
- self.assertEqual(condition, GLib.IOCondition.IN)
- self.assertEqual(data, 'hello')
- cb_reads.append(channel.read())
- return True
-
- ml = GLib.MainLoop()
- ch.add_watch(GLib.IOCondition.IN, cb, 'hello', GLib.PRIORITY_HIGH)
-
- GLib.timeout_add(10, lambda: os.write(w, b'a') and False)
- GLib.timeout_add(100, lambda: os.write(w, b'b') and False)
- GLib.timeout_add(200, ml.quit)
- ml.run()
-
- self.assertEqual(cb_reads, [b'a', b'b'])
-
- def test_backwards_compat_flags(self):
- self.assertEqual(GLib.IOCondition.IN, GLib.IO_IN)
- self.assertEqual(GLib.IOFlags.NONBLOCK, GLib.IO_FLAG_NONBLOCK)
- self.assertEqual(GLib.IOFlags.IS_SEEKABLE, GLib.IO_FLAG_IS_SEEKABLE)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 4c7794a..408a123 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -41,23 +41,24 @@ class TestMainLoop(unittest.TestCase):
os.close(pipe_w)
def excepthook(type, value, traceback):
- assert type is Exception
- assert value.args[0] == "deadbabe"
+ self.assertTrue(type is Exception)
+ self.assertEqual(value.args[0], "deadbabe")
sys.excepthook = excepthook
-
- got_exception = False
try:
- loop.run()
- except:
- got_exception = True
+ got_exception = False
+ try:
+ loop.run()
+ except:
+ got_exception = True
+ finally:
+ sys.excepthook = sys.__excepthook__
#
# The exception should be handled (by printing it)
# immediately on return from child_died() rather
# than here. See bug #303573
#
- sys.excepthook = sys.__excepthook__
- assert not got_exception
+ self.assertFalse(got_exception)
def test_concurrency(self):
def on_usr1(signum, frame):
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 405375d..490b1ae 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -21,6 +21,7 @@ from gi.repository.GObject import \
from gi.repository import Gio
from gi.repository import GLib
from gi.repository import GIMarshallingTests
+from gi._gobject import propertyhelper
if sys.version_info < (3, 0):
TEST_UTF8 = "\xe2\x99\xa5"
@@ -722,5 +723,69 @@ class TestProperty(unittest.TestCase):
self.assertRaises(TypeError, tester._type_from_python, types.CodeType)
+
+class TestInstallProperties(unittest.TestCase):
+ # These tests only test how signalhelper.install_signals works
+ # with the __gsignals__ dict and therefore does not need to use
+ # GObject as a base class because that would automatically call
+ # install_signals within the meta-class.
+ class Base(object):
+ __gproperties__ = {'test': (0, '', '', 0, 0, 0, 0)}
+
+ class Sub1(Base):
+ pass
+
+ class Sub2(Base):
+ @GObject.Property(type=int)
+ def sub2test(self):
+ return 123
+
+ class ClassWithPropertyAndGetterVFunc(object):
+ @GObject.Property(type=int)
+ def sub2test(self):
+ return 123
+
+ def do_get_property(self, name):
+ return 321
+
+ class ClassWithPropertyRedefined(object):
+ __gproperties__ = {'test': (0, '', '', 0, 0, 0, 0)}
+ test = GObject.Property(type=int)
+
+ def setUp(self):
+ self.assertEqual(len(self.Base.__gproperties__), 1)
+ propertyhelper.install_properties(self.Base)
+ self.assertEqual(len(self.Base.__gproperties__), 1)
+
+ def test_subclass_without_properties_is_not_modified(self):
+ self.assertFalse('__gproperties__' in self.Sub1.__dict__)
+ propertyhelper.install_properties(self.Sub1)
+ self.assertFalse('__gproperties__' in self.Sub1.__dict__)
+
+ def test_subclass_with_decorator_gets_gproperties_dict(self):
+ # Sub2 has Property instances but will not have a __gproperties__
+ # until install_properties is called
+ self.assertFalse('__gproperties__' in self.Sub2.__dict__)
+ self.assertFalse('do_get_property' in self.Sub2.__dict__)
+ self.assertFalse('do_set_property' in self.Sub2.__dict__)
+
+ propertyhelper.install_properties(self.Sub2)
+ self.assertTrue('__gproperties__' in self.Sub2.__dict__)
+ self.assertEqual(len(self.Base.__gproperties__), 1)
+ self.assertEqual(len(self.Sub2.__gproperties__), 1)
+ self.assertTrue('sub2test' in self.Sub2.__gproperties__)
+
+ # get/set vfuncs should have been added
+ self.assertTrue('do_get_property' in self.Sub2.__dict__)
+ self.assertTrue('do_set_property' in self.Sub2.__dict__)
+
+ def test_object_with_property_and_do_get_property_vfunc_raises(self):
+ self.assertRaises(TypeError, propertyhelper.install_properties,
+ self.ClassWithPropertyAndGetterVFunc)
+
+ def test_same_name_property_definitions_raises(self):
+ self.assertRaises(ValueError, propertyhelper.install_properties,
+ self.ClassWithPropertyRedefined)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/test_source.py b/tests/test_source.py
index 6e497e1..fe674cd 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -2,7 +2,7 @@
import unittest
-from gi.repository import GLib, GObject
+from gi.repository import GLib
class Idle(GLib.Idle):
@@ -113,17 +113,6 @@ class TestSource(unittest.TestCase):
s = f()
self.assertTrue(s.is_destroyed())
- def testRemove(self):
- s = GLib.idle_add(dir)
- self.assertEqual(GLib.source_remove(s), True)
- # s is now removed, should fail now
- self.assertEqual(GLib.source_remove(s), False)
-
- # accepts large source IDs (they are unsigned)
- self.assertEqual(GLib.source_remove(GObject.G_MAXINT32), False)
- self.assertEqual(GLib.source_remove(GObject.G_MAXINT32 + 1), False)
- self.assertEqual(GLib.source_remove(GObject.G_MAXUINT32), False)
-
class TestTimeout(unittest.TestCase):
def test504337(self):