[pygobject] tests: Move object property reference count tests to test_properties
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests: Move object property reference count tests to test_properties
- Date: Tue, 29 Jul 2014 07:01:01 +0000 (UTC)
commit 36caa74a276972eee2b18162ac09edc83c30a3cb
Author: Simon Feltman <sfeltman src gnome org>
Date: Mon Jul 28 23:51:19 2014 -0700
tests: Move object property reference count tests to test_properties
Move and consolidate tests for object property reference counts from
tests_object_marshaling to test_properties.
https://bugzilla.gnome.org/show_bug.cgi?id=726999
tests/test_object_marshaling.py | 68 ---------------------------------------
tests/test_properties.py | 36 ++++++++++++++++++++
2 files changed, 36 insertions(+), 68 deletions(-)
---
diff --git a/tests/test_object_marshaling.py b/tests/test_object_marshaling.py
index ae0727e..c881a9a 100644
--- a/tests/test_object_marshaling.py
+++ b/tests/test_object_marshaling.py
@@ -540,74 +540,6 @@ class TestVFuncsWithHeldFloatingArg(unittest.TestCase):
self.assertTrue(held_object_ref() is None)
-class TestPropertyHoldingObject(unittest.TestCase):
- def test_props_getter_holding_object_ref_count(self):
- holder = GIMarshallingTests.PropertiesObject()
- held = GObject.Object()
-
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 1)
-
- holder.set_property('some-object', held)
- self.assertEqual(holder.__grefcount__, 1)
-
- initial_ref_count = held.__grefcount__
- holder.props.some_object
- gc.collect()
- self.assertEqual(held.__grefcount__, initial_ref_count)
-
- def test_get_property_holding_object_ref_count(self):
- holder = GIMarshallingTests.PropertiesObject()
- held = GObject.Object()
-
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 1)
-
- holder.set_property('some-object', held)
- self.assertEqual(holder.__grefcount__, 1)
-
- initial_ref_count = held.__grefcount__
- holder.get_property('some-object')
- gc.collect()
- self.assertEqual(held.__grefcount__, initial_ref_count)
-
- def test_props_setter_holding_object_ref_count(self):
- holder = GIMarshallingTests.PropertiesObject()
- held = GObject.Object()
-
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 1)
-
- # Setting property should only increase ref count by 1
- holder.props.some_object = held
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 2)
-
- # Clearing should pull it back down
- holder.props.some_object = None
- self.assertEqual(held.__grefcount__, 1)
-
- def test_set_property_holding_object_ref_count(self):
- holder = GIMarshallingTests.PropertiesObject()
- held = GObject.Object()
-
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 1)
-
- # Setting property should only increase ref count by 1
- holder.set_property('some-object', held)
- self.assertEqual(holder.__grefcount__, 1)
- self.assertEqual(held.__grefcount__, 2)
-
- # Clearing should pull it back down
- holder.set_property('some-object', None)
- self.assertEqual(held.__grefcount__, 1)
-
- def test_set_object_property_to_invalid_type(self):
- obj = GIMarshallingTests.PropertiesObject()
- self.assertRaises(TypeError, obj.set_property, 'some-object', 'not_an_object')
-
-
@unittest.skipIf(Regress is None, 'Regress is required')
class TestArgumentTypeErrors(unittest.TestCase):
def test_object_argument_type_error(self):
diff --git a/tests/test_properties.py b/tests/test_properties.py
index a2c437e..c9c75c2 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -1,5 +1,6 @@
# coding=utf-8
+import gc
import sys
import struct
import types
@@ -1185,6 +1186,41 @@ class CPropertiesTestBase(object):
self.set_prop(a, 'list', ("str1", "str2"))
self.assertEqual(self.get_prop(a, 'list'), ["str1", "str2"])
+ def test_held_object_ref_count_getter(self):
+ holder = GIMarshallingTests.PropertiesObject()
+ held = GObject.Object()
+
+ self.assertEqual(holder.__grefcount__, 1)
+ self.assertEqual(held.__grefcount__, 1)
+
+ self.set_prop(holder, 'some-object', held)
+ self.assertEqual(holder.__grefcount__, 1)
+
+ initial_ref_count = held.__grefcount__
+ self.get_prop(holder, 'some-object')
+ gc.collect()
+ self.assertEqual(held.__grefcount__, initial_ref_count)
+
+ def test_held_object_ref_count_setter(self):
+ holder = GIMarshallingTests.PropertiesObject()
+ held = GObject.Object()
+
+ self.assertEqual(holder.__grefcount__, 1)
+ self.assertEqual(held.__grefcount__, 1)
+
+ # Setting property should only increase ref count by 1
+ self.set_prop(holder, 'some-object', held)
+ self.assertEqual(holder.__grefcount__, 1)
+ self.assertEqual(held.__grefcount__, 2)
+
+ # Clearing should pull it back down
+ self.set_prop(holder, 'some-object', None)
+ self.assertEqual(held.__grefcount__, 1)
+
+ def test_set_object_property_to_invalid_type(self):
+ obj = GIMarshallingTests.PropertiesObject()
+ self.assertRaises(TypeError, self.set_prop, obj, 'some-object', 'not_an_object')
+
class TestCPropsAccessor(CPropertiesTestBase, unittest.TestCase):
# C property tests using the "props" accessor.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]