diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-03-31 14:39:48 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-03-31 14:39:48 +0200 |
commit | 743f530e2a1258d3a940eae51eaf0e7fa2289dce (patch) | |
tree | 380d22a6b509c892070e1caa608502c3e2eb52d0 /tests | |
parent | 809f116a9739f77ea98b8ee11f102b44e38ee710 (diff) | |
download | pygobject-743f530e2a1258d3a940eae51eaf0e7fa2289dce.tar.gz |
tests: Skip various sys.getrefcount() checks in case sys.getrefcount is missing
PyPy doesn't support it.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_everything.py | 63 | ||||
-rw-r--r-- | tests/test_gi.py | 8 |
2 files changed, 49 insertions, 22 deletions
diff --git a/tests/test_everything.py b/tests/test_everything.py index 4b0cc720..eecd0e79 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -687,14 +687,17 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.called = True return 44 - ud_refcount = sys.getrefcount(ud) - callback_refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + ud_refcount = sys.getrefcount(ud) + callback_refcount = sys.getrefcount(callback) self.assertEqual(Everything.test_callback_async(callback, ud), None) # Callback should not have run and the ref count is increased by 1 self.assertEqual(TestCallbacks.called, False) - self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) - self.assertEqual(sys.getrefcount(ud), ud_refcount + 1) + + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) + self.assertEqual(sys.getrefcount(ud), ud_refcount + 1) # test_callback_thaw_async will run the callback previously supplied. # references should be auto decremented after this call. @@ -702,8 +705,9 @@ class TestCallbacks(unittest.TestCase): self.assertTrue(TestCallbacks.called) # Make sure refcounts are returned to normal - self.assertEqual(sys.getrefcount(callback), callback_refcount) - self.assertEqual(sys.getrefcount(ud), ud_refcount) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount) + self.assertEqual(sys.getrefcount(ud), ud_refcount) def test_callback_scope_call_multi(self): # This tests a callback that gets called multiple times from a @@ -714,12 +718,15 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.called += 1 return TestCallbacks.called - refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + refcount = sys.getrefcount(callback) result = Everything.test_multi_callback(callback) # first callback should give 1, second 2, and the function sums them up self.assertEqual(result, 3) self.assertEqual(TestCallbacks.called, 2) - self.assertEqual(sys.getrefcount(callback), refcount) + + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), refcount) def test_callback_scope_call_array(self): # This tests a callback that gets called multiple times from a @@ -732,13 +739,16 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.callargs.append((one, two)) return len(TestCallbacks.callargs) - refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + refcount = sys.getrefcount(callback) result = Everything.test_array_callback(callback) # first callback should give 1, second 2, and the function sums them up self.assertEqual(result, 3) self.assertEqual(TestCallbacks.callargs, [([-1, 0, 1, 2], ['one', 'two', 'three'])] * 2) - self.assertEqual(sys.getrefcount(callback), refcount) + + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), refcount) @unittest.skipUnless(hasattr(Everything, 'test_array_inout_callback'), 'Requires newer version of GI') @@ -751,13 +761,15 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.callargs.append(ints) return ints[1:], len(ints[1:]) - refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + refcount = sys.getrefcount(callback) result = Everything.test_array_inout_callback(callback) self.assertEqual(TestCallbacks.callargs, [[-2, -1, 0, 1, 2], [-1, 0, 1, 2]]) # first callback should give 4, second 3 self.assertEqual(result, 3) - self.assertEqual(sys.getrefcount(callback), refcount) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), refcount) def test_callback_userdata(self): TestCallbacks.called = 0 @@ -889,8 +901,9 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.called += 1 return 33 - value_refcount = sys.getrefcount(ud) - callback_refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + value_refcount = sys.getrefcount(ud) + callback_refcount = sys.getrefcount(callback) # Callback is immediately called. for i in range(100): @@ -898,14 +911,16 @@ class TestCallbacks(unittest.TestCase): self.assertEqual(res, 33) self.assertEqual(TestCallbacks.called, 100) - self.assertEqual(sys.getrefcount(callback), callback_refcount + 100) - self.assertEqual(sys.getrefcount(ud), value_refcount + 100) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount + 100) + self.assertEqual(sys.getrefcount(ud), value_refcount + 100) # thaw will call the callback again, this time resources should be freed self.assertEqual(Everything.test_callback_thaw_notifications(), 33 * 100) self.assertEqual(TestCallbacks.called, 200) - self.assertEqual(sys.getrefcount(callback), callback_refcount) - self.assertEqual(sys.getrefcount(ud), value_refcount) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount) + self.assertEqual(sys.getrefcount(ud), value_refcount) def test_callback_scope_notified_with_destroy_no_user_data(self): TestCallbacks.called = 0 @@ -915,7 +930,8 @@ class TestCallbacks(unittest.TestCase): TestCallbacks.called += 1 return 34 - callback_refcount = sys.getrefcount(callback) + if hasattr(sys, "getrefcount"): + callback_refcount = sys.getrefcount(callback) # Run with warning as exception with warnings.catch_warnings(record=True) as w: @@ -925,7 +941,8 @@ class TestCallbacks(unittest.TestCase): callback) self.assertEqual(TestCallbacks.called, 0) - self.assertEqual(sys.getrefcount(callback), callback_refcount) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount) # Run with warning as warning with warnings.catch_warnings(record=True) as w: @@ -940,13 +957,15 @@ class TestCallbacks(unittest.TestCase): self.assertEqual(res, 34) self.assertEqual(TestCallbacks.called, 1) - self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) # thaw will call the callback again, # refcount will not go down without user_data parameter self.assertEqual(Everything.test_callback_thaw_notifications(), 34) self.assertEqual(TestCallbacks.called, 2) - self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(sys.getrefcount(callback), callback_refcount + 1) def test_callback_in_methods(self): object_ = Everything.TestObj() diff --git a/tests/test_gi.py b/tests/test_gi.py index 91f4ffc7..24d94b20 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -1651,6 +1651,7 @@ class TestGValue(unittest.TestCase): gc.collect() self.assertEqual(ref(), None) + @unittest.skipUnless(hasattr(sys, "getrefcount"), "no sys.getrefcount") def test_gvalue_boxed_ref_counts(self): # Tests a boxed type wrapping a python object pointer (TYPE_PYOBJECT) # held by a GValue @@ -2542,6 +2543,7 @@ class TestPythonGObject(unittest.TestCase): object_.method_with_default_implementation(84) self.assertEqual(object_.props.int, 84) + @unittest.skipUnless(hasattr(sys, "getrefcount"), "no sys.getrefcount") def test_vfunc_return_ref_count(self): obj = self.Object(int=42) ref_count = sys.getrefcount(obj.return_for_caller_allocated_out_parameter) @@ -2555,6 +2557,12 @@ class TestPythonGObject(unittest.TestCase): self.assertEqual(sys.getrefcount(obj.return_for_caller_allocated_out_parameter), ref_count) + def test_vfunc_return_no_ref_count(self): + obj = self.Object(int=42) + ret = obj.vfunc_caller_allocated_out_parameter() + self.assertEqual(ret, obj.return_for_caller_allocated_out_parameter) + self.assertFalse(ret is obj.return_for_caller_allocated_out_parameter) + def test_subobject_parent_vfunc(self): object_ = self.SubObject(int=81) object_.method_with_default_implementation(87) |