diff options
-rw-r--r-- | tests/test_everything.py | 69 | ||||
-rw-r--r-- | tests/test_properties.py | 59 |
2 files changed, 60 insertions, 68 deletions
diff --git a/tests/test_everything.py b/tests/test_everything.py index 094d8adf..e753dcce 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -997,51 +997,7 @@ class TestClosures(unittest.TestCase): @unittest.skipUnless(has_cairo, 'built without cairo support') -class TestProperties(unittest.TestCase): - - def test_basic(self): - object_ = Everything.TestObj() - - self.assertEqual(object_.props.int, 0) - object_.props.int = 42 - self.assertTrue(isinstance(object_.props.int, int)) - self.assertEqual(object_.props.int, 42) - - self.assertEqual(object_.props.float, 0.0) - object_.props.float = 42.42 - self.assertTrue(isinstance(object_.props.float, float)) - self.assertAlmostEqual(object_.props.float, 42.42, places=5) - - self.assertEqual(object_.props.double, 0.0) - object_.props.double = 42.42 - self.assertTrue(isinstance(object_.props.double, float)) - self.assertAlmostEqual(object_.props.double, 42.42, places=5) - - self.assertEqual(object_.props.string, None) - object_.props.string = 'mec' - self.assertTrue(isinstance(object_.props.string, str)) - self.assertEqual(object_.props.string, 'mec') - - self.assertEqual(object_.props.gtype, GObject.TYPE_INVALID) - object_.props.gtype = int - self.assertEqual(object_.props.gtype, GObject.TYPE_INT) - - def test_hash_table(self): - object_ = Everything.TestObj() - self.assertEqual(object_.props.hash_table, None) - - object_.props.hash_table = {'mec': 56} - self.assertTrue(isinstance(object_.props.hash_table, dict)) - self.assertEqual(list(object_.props.hash_table.items())[0], ('mec', 56)) - - def test_list(self): - object_ = Everything.TestObj() - self.assertEqual(object_.props.list, []) - - object_.props.list = ['1', '2', '3'] - self.assertTrue(isinstance(object_.props.list, list)) - self.assertEqual(object_.props.list, ['1', '2', '3']) - +class TestBoxed(unittest.TestCase): def test_boxed(self): object_ = Everything.TestObj() self.assertEqual(object_.props.boxed, None) @@ -1081,29 +1037,6 @@ class TestProperties(unittest.TestCase): self.assertEqual(boxed, copy) self.assertNotEqual(id(boxed), id(copy)) - def test_gtype(self): - object_ = Everything.TestObj() - self.assertEqual(object_.props.gtype, GObject.TYPE_INVALID) - object_.props.gtype = int - self.assertEqual(object_.props.gtype, GObject.TYPE_INT) - - object_ = Everything.TestObj(gtype=int) - self.assertEqual(object_.props.gtype, GObject.TYPE_INT) - object_.props.gtype = str - self.assertEqual(object_.props.gtype, GObject.TYPE_STRING) - - def test_parent_class(self): - class A(Everything.TestObj): - prop1 = GObject.Property(type=int) - - a = A() - a.props.int = 20 - self.assertEqual(a.props.int, 20) - - # test parent property which needs introspection - a.props.list = ("str1", "str2") - self.assertEqual(a.props.list, ["str1", "str2"]) - @unittest.skipUnless(has_cairo, 'built without cairo support') class TestTortureProfile(unittest.TestCase): diff --git a/tests/test_properties.py b/tests/test_properties.py index d044dfe1..a2c437eb 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -1109,6 +1109,15 @@ class CPropertiesTestBase(object): self.assertRaises(TypeError, self.set_prop, self.obj, 'some-boxed-glist', 'foo') self.assertRaises(TypeError, self.set_prop, self.obj, 'some-boxed-glist', ['a']) + @unittest.skipUnless(has_regress, 'built without cairo support') + def test_annotated_glist(self): + obj = Regress.TestObj() + self.assertEqual(self.get_prop(obj, 'list'), []) + + self.set_prop(obj, 'list', ['1', '2', '3']) + self.assertTrue(isinstance(self.get_prop(obj, 'list'), list)) + self.assertEqual(self.get_prop(obj, 'list'), ['1', '2', '3']) + @unittest.expectedFailure def test_boxed_glist_ctor(self): l = [GObject.G_MININT, 42, GObject.G_MAXINT] @@ -1141,6 +1150,41 @@ class CPropertiesTestBase(object): self.assertEqual(42, self.get_prop(obj, 'some-int')) self.assertEqual(54, self.get_prop(obj, 'some-uchar')) + @unittest.skipUnless(has_regress, 'built without cairo support') + def test_gtype(self): + obj = Regress.TestObj() + self.assertEqual(self.get_prop(obj, 'gtype'), GObject.TYPE_INVALID) + self.set_prop(obj, 'gtype', int) + self.assertEqual(self.get_prop(obj, 'gtype'), GObject.TYPE_INT) + + obj = Regress.TestObj(gtype=int) + self.assertEqual(self.get_prop(obj, 'gtype'), GObject.TYPE_INT) + self.set_prop(obj, 'gtype', str) + self.assertEqual(self.get_prop(obj, 'gtype'), GObject.TYPE_STRING) + + @unittest.skipUnless(has_regress, 'built without cairo support') + def test_hash_table(self): + obj = Regress.TestObj() + self.assertEqual(self.get_prop(obj, 'hash-table'), None) + + self.set_prop(obj, 'hash-table', {'mec': 56}) + self.assertTrue(isinstance(self.get_prop(obj, 'hash-table'), dict)) + self.assertEqual(list(self.get_prop(obj, 'hash-table').items())[0], + ('mec', 56)) + + @unittest.skipUnless(has_regress, 'built without cairo support') + def test_parent_class(self): + class A(Regress.TestObj): + prop1 = GObject.Property(type=int) + + a = A() + self.set_prop(a, 'int', 20) + self.assertEqual(self.get_prop(a, 'int'), 20) + + # test parent property which needs introspection + self.set_prop(a, 'list', ("str1", "str2")) + self.assertEqual(self.get_prop(a, 'list'), ["str1", "str2"]) + class TestCPropsAccessor(CPropertiesTestBase, unittest.TestCase): # C property tests using the "props" accessor. @@ -1189,6 +1233,11 @@ class TestCGetPropertyMethod(CPropertiesTestBase, unittest.TestCase): CPropertiesTestBase.test_boxed_glist(self) @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=733893 + def test_annotated_glist(self): + # get_property() returns None + CPropertiesTestBase.test_annotated_glist(self) + + @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=733893 def test_char(self): # get_property() returns a single element string which cannot represent # tested values for G_TYPE_CHAR @@ -1206,6 +1255,16 @@ class TestCGetPropertyMethod(CPropertiesTestBase, unittest.TestCase): # tested values for G_TYPE_UCHAR CPropertiesTestBase.test_setting_several_properties(self) + @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=733893 + def test_parent_class(self): + # get_property() returns gpointer instead of a list + CPropertiesTestBase.test_annotated_glist(self) + + @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=733893 + def test_hash_table(self): + # get_property() returns gpointer instead of a dict + CPropertiesTestBase.test_hash_table(self) + if __name__ == '__main__': unittest.main() |