diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:36:00 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:36:01 +0900 |
commit | 385fb5df2f7c3ec197b954e8a8ddac5297fe4043 (patch) | |
tree | d84ecee10b56acc8ec2633a277fca9ce457013f1 /tests | |
parent | c79482ebfe55da780fd2d733696f5107dc4d5cb8 (diff) | |
download | pygobject2-385fb5df2f7c3ec197b954e8a8ddac5297fe4043.tar.gz pygobject2-385fb5df2f7c3ec197b954e8a8ddac5297fe4043.tar.bz2 pygobject2-385fb5df2f7c3ec197b954e8a8ddac5297fe4043.zip |
Imported Upstream version 2.28.0
Change-Id: If251721667bb545804ab96eb17bffb715cd4e832
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/runtests.py | 2 | ||||
-rw-r--r-- | tests/test_gdbus.py | 27 | ||||
-rw-r--r-- | tests/test_overrides.py | 26 | ||||
-rw-r--r-- | tests/test_properties.py | 23 |
4 files changed, 67 insertions, 11 deletions
diff --git a/tests/runtests.py b/tests/runtests.py index a912414..2bb8637 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -7,6 +7,8 @@ import sys import unittest +# force untranslated messages, as we check for them in some tests +os.environ['LC_MESSAGES'] = 'C' # Load tests. if 'TEST_NAMES' in os.environ: diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py index ade62d1..b40492c 100644 --- a/tests/test_gdbus.py +++ b/tests/test_gdbus.py @@ -40,7 +40,8 @@ class TestGDBusClient(unittest.TestCase): self.dbus_proxy.call_sync('GetConnectionUnixProcessID', None, Gio.DBusCallFlags.NO_AUTO_START, 500, None) self.fail('call with invalid arguments should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] self.assertTrue('InvalidArgs' in str(e)) # error case: invalid argument @@ -49,7 +50,9 @@ class TestGDBusClient(unittest.TestCase): GLib.Variant('(s)', (' unknown',)), Gio.DBusCallFlags.NO_AUTO_START, 500, None) self.fail('call with invalid arguments should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + self.assertTrue('NameHasNoOwner' in str(e)) # error case: unknown method @@ -57,7 +60,9 @@ class TestGDBusClient(unittest.TestCase): self.dbus_proxy.call_sync('UnknownMethod', None, Gio.DBusCallFlags.NO_AUTO_START, 500, None) self.fail('call for unknown method should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + self.assertTrue('UnknownMethod' in str(e)) def test_native_calls_async(self): @@ -82,7 +87,9 @@ class TestGDBusClient(unittest.TestCase): try: obj.call_finish(result) self.fail('call_finish() for unknown method should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + self.assertTrue('UnknownMethod' in str(e)) finally: user_data['main_loop'].quit() @@ -120,7 +127,9 @@ class TestGDBusClient(unittest.TestCase): self.assertEqual(len(result), 4) for i in result: self.assertEqual(type(i), type('')) - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + if 'Error.ServiceUnknown' not in str(e): raise @@ -128,7 +137,9 @@ class TestGDBusClient(unittest.TestCase): try: self.dbus_proxy.GetConnectionUnixProcessID('()', timeout=0) self.fail('call with timeout=0 should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + self.assertTrue('Timeout' in str(e), str(e)) def test_python_calls_sync_errors(self): @@ -136,7 +147,9 @@ class TestGDBusClient(unittest.TestCase): try: self.dbus_proxy.GetConnectionUnixProcessID('()') self.fail('call with invalid arguments should raise an exception') - except Exception as e: + except Exception: + etype, e = sys.exc_info()[:2] + self.assertTrue('InvalidArgs' in str(e), str(e)) def test_python_calls_async(self): diff --git a/tests/test_overrides.py b/tests/test_overrides.py index e2333b1..9234d96 100644 --- a/tests/test_overrides.py +++ b/tests/test_overrides.py @@ -7,7 +7,7 @@ import sys import os sys.path.insert(0, "../") -from compathelper import _long, _unicode +from compathelper import _long, _unicode, _bytes from gi.repository import GLib from gi.repository import GObject @@ -345,6 +345,16 @@ class TestGdk(unittest.TestCase): self.assertEquals(color.green, 200) self.assertEquals(color.blue, 300) + def test_rgba(self): + self.assertEquals(Gdk.RGBA, overrides.Gdk.RGBA) + rgba = Gdk.RGBA(0.1, 0.2, 0.3, 0.4) + self.assertEquals(rgba.red, 0.1) + self.assertEquals(rgba.green, 0.2) + self.assertEquals(rgba.blue, 0.3) + self.assertEquals(rgba.alpha, 0.4) + rgba.green = 0.9 + self.assertEquals(rgba.green, 0.9) + def test_event(self): event = Gdk.Event.new(Gdk.EventType.CONFIGURE) self.assertEquals(event.type, Gdk.EventType.CONFIGURE) @@ -705,11 +715,11 @@ class TestGtk(unittest.TestCase): i % 2, bool(i % 2), i, - sys.maxint + 1, + 9223372036854775808, -9223372036854775808, 0xffffffffffffffff, 254, - 'a' + _bytes('a') )) # len gets the number of children in the root node @@ -744,7 +754,7 @@ class TestGtk(unittest.TestCase): uint_ = tree_store.get_value(treeiter, 8) self.assertEquals(uint_, i) ulong_ = tree_store.get_value(treeiter, 9) - self.assertEquals(ulong_, sys.maxint + 1) + self.assertEquals(ulong_, 9223372036854775808) int64_ = tree_store.get_value(treeiter, 10) self.assertEquals(int64_, -9223372036854775808) uint64_ = tree_store.get_value(treeiter, 11) @@ -1446,3 +1456,11 @@ class TestGio(unittest.TestCase): self.assertEqual(len(empty), 0) self.assertEqual(bool(empty), True) self.assertEqual(empty.keys(), []) + + def test_closures(self): + # make sure this doesn't crash + def fake_cb(*args): + pass + + ag = Gtk.AccelGroup() + ag.connect(Gdk.KEY_l, Gdk.ModifierType.CONTROL_MASK, 0, fake_cb) diff --git a/tests/test_properties.py b/tests/test_properties.py index 90db3ac..1499903 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -401,5 +401,28 @@ class TestProperty(unittest.TestCase): gobject.property(type=gobject.TYPE_FLOAT, minimum=-1) gobject.property(type=gobject.TYPE_DOUBLE, minimum=-1) + # Bug 644039 + def testReferenceCount(self): + # We can check directly if an object gets finalized, so we will + # observe it indirectly through the refcount of a member object. + + # We create our dummy object and store its current refcount + o = object() + rc = sys.getrefcount(o) + + # We add our object as a member to our newly created object we + # want to observe. Its refcount is increased by one. + t = PropertyObject(normal="test") + t.o = o + self.assertEquals(sys.getrefcount(o), rc + 1) + + # Now we want to ensure we do not leak any references to our + # object with properties. If no ref is leaked, then when deleting + # the local reference to this object, its reference count shoud + # drop to zero, and our dummy object should loose one reference. + del t + self.assertEquals(sys.getrefcount(o), rc) + + if __name__ == '__main__': unittest.main() |