5 from gi.repository import GIMarshallingTests
6 from gi.repository import Gio
7 from gi.repository import GObject
13 from gi.repository import Regress
14 from gi.repository import Gtk
19 class Test(unittest.TestCase):
21 new_func = lambda info: 'docstring test'
22 old_func = gi.docstring.get_doc_string_generator()
24 gi.docstring.set_doc_string_generator(new_func)
25 self.assertEqual(gi.docstring.get_doc_string_generator(),
27 self.assertEqual(gi.docstring.generate_doc_string(None),
30 # Set back to original generator
31 gi.docstring.set_doc_string_generator(old_func)
32 self.assertEqual(gi.docstring.get_doc_string_generator(),
35 def test_final_signature_with_full_inout(self):
36 self.assertEqual(GIMarshallingTests.Object.full_inout.__doc__,
37 'full_inout(object:GIMarshallingTests.Object) -> object:GIMarshallingTests.Object')
39 def test_overridden_doc_is_not_clobbered(self):
40 self.assertEqual(GIMarshallingTests.OverridesObject.method.__doc__,
41 'Overridden doc string.')
43 def test_allow_none_with_user_data_defaults(self):
44 g_file_copy_doc = 'copy(self, destination:Gio.File, ' \
45 'flags:Gio.FileCopyFlags, ' \
46 'cancellable:Gio.Cancellable=None, ' \
47 'progress_callback:Gio.FileProgressCallback=None, ' \
48 'progress_callback_data=None) -> bool'
50 self.assertEqual(Gio.File.copy.__doc__, g_file_copy_doc)
52 def test_array_length_arg(self):
53 self.assertEqual(GIMarshallingTests.array_in.__doc__,
54 'array_in(ints:list)')
56 def test_init_function(self):
57 # This tests implicit array length args along with skipping a
59 self.assertEqual(GIMarshallingTests.init_function.__doc__,
60 'init_function(argv:list=None) -> bool, argv:list')
62 def test_boolean_return(self):
63 self.assertEqual(GIMarshallingTests.boolean_return_true.__doc__,
64 'boolean_return_true() -> bool')
66 def test_may_return_none(self):
67 self.assertEqual(Gio.File.get_basename.__doc__,
68 'get_basename(self) -> str or None')
70 def test_class_doc_constructors(self):
71 doc = GIMarshallingTests.Object.__doc__
72 self.assertTrue('new(int_:int)' in doc)
74 def test_struct_doc_constructors(self):
75 doc = GIMarshallingTests.BoxedStruct.__doc__
76 self.assertTrue('new()' in doc)
77 self.assertTrue('BoxedStruct()' in doc)
79 @unittest.skipUnless(has_cairo, 'built without cairo support')
80 def test_private_struct_constructors(self):
81 # Structs without a size or constructor should have no constructor docs.
82 doc = Regress.TestBoxedPrivate.__doc__
83 self.assertEqual(doc, '')
85 def test_array_inout_etc(self):
86 self.assertEqual(GIMarshallingTests.array_inout_etc.__doc__,
87 'array_inout_etc(first:int, ints:list, last:int) -> ints:list, sum:int')
89 def test_array_out_etc(self):
90 self.assertEqual(GIMarshallingTests.array_out_etc.__doc__,
91 'array_out_etc(first:int, last:int) -> ints:list, sum:int')
93 @unittest.skipUnless(has_cairo, 'built without cairo support')
94 def test_shared_array_length_with_prior_out_arg(self):
95 # Test the 'iter' out argument does not effect length argument skipping.
96 self.assertEqual(Gtk.ListStore.insert_with_valuesv.__doc__,
97 'insert_with_valuesv(self, position:int, columns:list, values:list) -> iter:Gtk.TreeIter')
99 def test_sub_class_doc(self):
100 class A(GObject.Object):
108 self.assertEqual(A.__doc__, "first doc")
109 self.assertEqual(B.__doc__, "second doc")
111 def test_sub_class_no_doc(self):
112 class A(GObject.Object):
118 self.assertEqual(A.__doc__, None)
119 self.assertEqual(B.__doc__, "sub-class doc")
121 @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=734926
122 def test_sub_class_doc_setattr(self):
123 class A(GObject.Object):
129 A.__doc__ = 'custom doc'
131 self.assertEqual(A.__doc__, "custom doc")
132 self.assertEqual(B.__doc__, "custom doc")