diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-04-22 21:30:53 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-04-22 21:47:34 +0200 |
commit | 535a1c3d795de575cc81dd212f2301bc9714b57f (patch) | |
tree | 5c3198dec579829a11ecba3ffc3509c6442d9cee /tests | |
parent | a2c8c533a791375a8ba337e6200672bd04914c08 (diff) | |
download | pygobject-535a1c3d795de575cc81dd212f2301bc9714b57f.tar.gz |
pypy: skip various refcounting related tests and add some gc.collect where it helps
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_everything.py | 9 | ||||
-rw-r--r-- | tests/test_object_marshaling.py | 46 |
2 files changed, 43 insertions, 12 deletions
diff --git a/tests/test_everything.py b/tests/test_everything.py index 76543f7a..bccc94b1 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -12,6 +12,7 @@ import sys import os import re import platform +import gc import pytest @@ -1353,6 +1354,8 @@ class TestBoxed(unittest.TestCase): # - another owned by @obj self.assertEqual(obj.refcount, 2) del wrapper + gc.collect() + gc.collect() self.assertEqual(obj.refcount, 1) def test_boxed_c_wrapper_copy(self): @@ -1367,10 +1370,16 @@ class TestBoxed(unittest.TestCase): # - another owned by @obj self.assertEqual(obj.refcount, 3) del wrapper + gc.collect() + gc.collect() self.assertEqual(obj.refcount, 2) del wrapper_copy + gc.collect() + gc.collect() self.assertEqual(obj.refcount, 1) del obj + gc.collect() + gc.collect() def test_array_fixed_boxed_none_out(self): arr = Everything.test_array_fixed_boxed_none_out() diff --git a/tests/test_object_marshaling.py b/tests/test_object_marshaling.py index e50cbb61..3d8ebb84 100644 --- a/tests/test_object_marshaling.py +++ b/tests/test_object_marshaling.py @@ -128,11 +128,13 @@ class TestVFuncsWithObjectArg(unittest.TestCase): with warnings.catch_warnings(record=True) as warn: warnings.simplefilter('always') ref_count, is_floating = vfuncs.get_ref_info_for_vfunc_out_object_transfer_none() - self.assertTrue(issubclass(warn[0].category, RuntimeWarning)) + if hasattr(sys, "getrefcount"): + self.assertTrue(issubclass(warn[0].category, RuntimeWarning)) # The ref count of the GObject returned to the caller (get_ref_info_for_vfunc_return_object_transfer_none) # should be a single floating ref - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -144,9 +146,11 @@ class TestVFuncsWithObjectArg(unittest.TestCase): with warnings.catch_warnings(record=True) as warn: warnings.simplefilter('always') ref_count, is_floating = vfuncs.get_ref_info_for_vfunc_out_object_transfer_none() - self.assertTrue(issubclass(warn[0].category, RuntimeWarning)) + if hasattr(sys, "getrefcount"): + self.assertTrue(issubclass(warn[0].category, RuntimeWarning)) - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -158,7 +162,8 @@ class TestVFuncsWithObjectArg(unittest.TestCase): # The vfunc caller receives full ownership of a single ref which should not # be floating. - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -169,7 +174,8 @@ class TestVFuncsWithObjectArg(unittest.TestCase): vfuncs = self.VFuncs() ref_count, is_floating = vfuncs.get_ref_info_for_vfunc_out_object_transfer_full() - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -183,9 +189,12 @@ class TestVFuncsWithObjectArg(unittest.TestCase): self.assertEqual(vfuncs.in_object_grefcount, 2) # initial + python wrapper self.assertFalse(vfuncs.in_object_is_floating) - self.assertEqual(ref_count, 1) # ensure python wrapper released + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) # ensure python wrapper released self.assertFalse(is_floating) + gc.collect() + gc.collect() self.assertTrue(vfuncs.object_ref() is None) def test_vfunc_in_object_transfer_full(self): @@ -199,9 +208,12 @@ class TestVFuncsWithObjectArg(unittest.TestCase): self.assertFalse(vfuncs.in_object_is_floating) # ensure python wrapper took ownership and released, after vfunc was complete - self.assertEqual(ref_count, 0) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 0) self.assertFalse(is_floating) + gc.collect() + gc.collect() self.assertTrue(vfuncs.object_ref() is None) @@ -213,6 +225,7 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): Object = GObject.InitiallyUnowned ObjectRef = weakref.ref + @unittest.skipUnless(hasattr(sys, "getrefcount"), "refcount specific") def test_vfunc_return_object_transfer_none_with_floating(self): # Python is expected to return a single floating reference without warning. vfuncs = self.VFuncs() @@ -226,6 +239,7 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): gc.collect() self.assertTrue(vfuncs.object_ref() is None) + @unittest.skipUnless(hasattr(sys, "getrefcount"), "refcount specific") def test_vfunc_out_object_transfer_none_with_floating(self): # Same as above except uses out arg instead of return vfuncs = self.VFuncs() @@ -242,7 +256,8 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): ref_count, is_floating = vfuncs.get_ref_info_for_vfunc_return_object_transfer_full() # The vfunc caller receives full ownership of a single ref. - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -253,7 +268,8 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): vfuncs = self.VFuncs() ref_count, is_floating = vfuncs.get_ref_info_for_vfunc_out_object_transfer_full() - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertFalse(is_floating) gc.collect() @@ -270,9 +286,12 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): self.assertTrue(vfuncs.in_object_is_floating) # vfunc caller should only have a single floating ref after the vfunc finishes - self.assertEqual(ref_count, 1) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 1) self.assertTrue(is_floating) + gc.collect() + gc.collect() self.assertTrue(vfuncs.object_ref() is None) def test_vfunc_in_object_transfer_full_with_floating(self): @@ -286,9 +305,12 @@ class TestVFuncsWithFloatingArg(unittest.TestCase): self.assertFalse(vfuncs.in_object_is_floating) # ensure python wrapper took ownership and released - self.assertEqual(ref_count, 0) + if hasattr(sys, "getrefcount"): + self.assertEqual(ref_count, 0) self.assertFalse(is_floating) + gc.collect() + gc.collect() self.assertTrue(vfuncs.object_ref() is None) |