| 1 |
import collections.abc |
| 2 |
import inspect |
| 3 |
import typing |
| 4 |
import unittest |
| 5 |
|
| 6 |
from gi.repository import GIMarshallingTests, GLib, Gio, GObject |
| 7 |
|
| 8 |
|
| 9 |
class Test(unittest.TestCase): |
| 10 |
def test_signature_attr(self): |
| 11 |
func = GIMarshallingTests.Object.full_inout |
| 12 |
self.assertTrue(hasattr(func, "__signature__")) |
| 13 |
sig1 = func.__signature__ |
| 14 |
sig2 = inspect.signature(func) |
| 15 |
self.assertIsInstance(sig1, inspect.Signature) |
| 16 |
self.assertEqual(sig1, sig2) |
| 17 |
|
| 18 |
def assertSignatureEqual(self, first, second, msg=None): |
| 19 |
first_sig = inspect.signature(first) |
| 20 |
second_sig = inspect.signature(second) |
| 21 |
self.assertEqual(first_sig, second_sig, msg=msg) |
| 22 |
|
| 23 |
def test_allow_none_with_user_data_defaults(self): |
| 24 |
def expected( |
| 25 |
self, |
| 26 |
destination: Gio.File, |
| 27 |
flags: Gio.FileCopyFlags, |
| 28 |
cancellable: Gio.Cancellable | None = None, |
| 29 |
progress_callback: collections.abc.Callable[[int, int, typing.Any], None] |
| 30 |
| None = None, |
| 31 |
progress_callback_data: typing.Any = None, |
| 32 |
) -> bool: |
| 33 |
return True |
| 34 |
|
| 35 |
self.assertSignatureEqual(Gio.File.copy, expected) |
| 36 |
|
| 37 |
def test_init_function(self): |
| 38 |
def expected( |
| 39 |
argv: list[str] | None = None, |
| 40 |
) -> tuple[bool, list[str] | None]: |
| 41 |
return (True, []) |
| 42 |
|
| 43 |
self.assertSignatureEqual(GIMarshallingTests.init_function, expected) |
| 44 |
|
| 45 |
def test_in_arg(self): |
| 46 |
def expected(ints: list[int]) -> None: |
| 47 |
pass |
| 48 |
|
| 49 |
self.assertSignatureEqual(GIMarshallingTests.array_in, expected) |
| 50 |
|
| 51 |
def test_inout_arg(self): |
| 52 |
def expected(ints: list[int]) -> list[int]: |
| 53 |
return [] |
| 54 |
|
| 55 |
self.assertSignatureEqual(GIMarshallingTests.array_inout, expected) |
| 56 |
|
| 57 |
def test_out_arg(self): |
| 58 |
def expected() -> list[int]: |
| 59 |
return [] |
| 60 |
|
| 61 |
self.assertSignatureEqual(GIMarshallingTests.array_out, expected) |
| 62 |
|
| 63 |
def test_arg_boolean(self): |
| 64 |
def expected(v: bool) -> None: |
| 65 |
pass |
| 66 |
|
| 67 |
self.assertSignatureEqual(GIMarshallingTests.boolean_in_true, expected) |
| 68 |
|
| 69 |
def test_arg_int8(self): |
| 70 |
def expected(v: int) -> None: |
| 71 |
pass |
| 72 |
|
| 73 |
self.assertSignatureEqual(GIMarshallingTests.int8_in_max, expected) |
| 74 |
|
| 75 |
def test_arg_uint8(self): |
| 76 |
def expected(v: int) -> None: |
| 77 |
pass |
| 78 |
|
| 79 |
self.assertSignatureEqual(GIMarshallingTests.uint8_in, expected) |
| 80 |
|
| 81 |
def test_arg_int16(self): |
| 82 |
def expected(v: int) -> None: |
| 83 |
pass |
| 84 |
|
| 85 |
self.assertSignatureEqual(GIMarshallingTests.int16_in_max, expected) |
| 86 |
|
| 87 |
def test_arg_uint16(self): |
| 88 |
def expected(v: int) -> None: |
| 89 |
pass |
| 90 |
|
| 91 |
self.assertSignatureEqual(GIMarshallingTests.uint16_in, expected) |
| 92 |
|
| 93 |
def test_arg_int32(self): |
| 94 |
def expected(v: int) -> None: |
| 95 |
pass |
| 96 |
|
| 97 |
self.assertSignatureEqual(GIMarshallingTests.int32_in_max, expected) |
| 98 |
|
| 99 |
def test_arg_uint32(self): |
| 100 |
def expected(v: int) -> None: |
| 101 |
pass |
| 102 |
|
| 103 |
self.assertSignatureEqual(GIMarshallingTests.uint32_in, expected) |
| 104 |
|
| 105 |
def test_arg_int64(self): |
| 106 |
def expected(v: int) -> None: |
| 107 |
pass |
| 108 |
|
| 109 |
self.assertSignatureEqual(GIMarshallingTests.int64_in_max, expected) |
| 110 |
|
| 111 |
def test_arg_uint64(self): |
| 112 |
def expected(v: int) -> None: |
| 113 |
pass |
| 114 |
|
| 115 |
self.assertSignatureEqual(GIMarshallingTests.uint64_in, expected) |
| 116 |
|
| 117 |
def test_arg_float(self): |
| 118 |
def expected(v: float) -> None: |
| 119 |
pass |
| 120 |
|
| 121 |
self.assertSignatureEqual(GIMarshallingTests.float_in, expected) |
| 122 |
|
| 123 |
def test_arg_double(self): |
| 124 |
def expected(v: float) -> None: |
| 125 |
pass |
| 126 |
|
| 127 |
self.assertSignatureEqual(GIMarshallingTests.double_in, expected) |
| 128 |
|
| 129 |
def test_arg_gtype(self): |
| 130 |
def expected(gtype: GObject.GType) -> None: |
| 131 |
pass |
| 132 |
|
| 133 |
self.assertSignatureEqual(GIMarshallingTests.gtype_in, expected) |
| 134 |
|
| 135 |
def test_arg_utf8(self): |
| 136 |
def expected(utf8: str) -> None: |
| 137 |
pass |
| 138 |
|
| 139 |
self.assertSignatureEqual(GIMarshallingTests.utf8_none_in, expected) |
| 140 |
|
| 141 |
def test_arg_filename(self): |
| 142 |
def expected(path: str) -> bool: |
| 143 |
return True |
| 144 |
|
| 145 |
self.assertSignatureEqual(GIMarshallingTests.filename_exists, expected) |
| 146 |
|
| 147 |
def test_arg_enum(self): |
| 148 |
def expected(v: GIMarshallingTests.Enum) -> None: |
| 149 |
pass |
| 150 |
|
| 151 |
self.assertSignatureEqual(GIMarshallingTests.enum_in, expected) |
| 152 |
|
| 153 |
def test_arg_genum(self): |
| 154 |
def expected(v: GIMarshallingTests.GEnum) -> None: |
| 155 |
pass |
| 156 |
|
| 157 |
self.assertSignatureEqual(GIMarshallingTests.genum_in, expected) |
| 158 |
|
| 159 |
def test_arg_flags(self): |
| 160 |
def expected(v: GIMarshallingTests.NoTypeFlags) -> None: |
| 161 |
pass |
| 162 |
|
| 163 |
self.assertSignatureEqual(GIMarshallingTests.no_type_flags_in, expected) |
| 164 |
|
| 165 |
def test_arg_gflags(self): |
| 166 |
def expected(v: GIMarshallingTests.Flags) -> None: |
| 167 |
pass |
| 168 |
|
| 169 |
self.assertSignatureEqual(GIMarshallingTests.flags_in, expected) |
| 170 |
|
| 171 |
def test_arg_array(self): |
| 172 |
def expected(ints: list[int]) -> None: |
| 173 |
pass |
| 174 |
|
| 175 |
self.assertSignatureEqual(GIMarshallingTests.array_fixed_int_in, expected) |
| 176 |
self.assertSignatureEqual(GIMarshallingTests.array_in, expected) |
| 177 |
|
| 178 |
def test_arg_garray(self): |
| 179 |
def expected(array_: list[int]) -> None: |
| 180 |
pass |
| 181 |
|
| 182 |
self.assertSignatureEqual(GIMarshallingTests.garray_int_none_in, expected) |
| 183 |
|
| 184 |
def test_arg_ptrarray(self): |
| 185 |
def expected(parray_: list[str]) -> None: |
| 186 |
pass |
| 187 |
|
| 188 |
self.assertSignatureEqual(GIMarshallingTests.gptrarray_utf8_none_in, expected) |
| 189 |
|
| 190 |
def test_arg_glist(self): |
| 191 |
def expected(list: list[int]) -> None: |
| 192 |
pass |
| 193 |
|
| 194 |
self.assertSignatureEqual(GIMarshallingTests.glist_int_none_in, expected) |
| 195 |
|
| 196 |
def test_arg_gslist(self): |
| 197 |
def expected(list: list[int]) -> None: |
| 198 |
pass |
| 199 |
|
| 200 |
self.assertSignatureEqual(GIMarshallingTests.gslist_int_none_in, expected) |
| 201 |
|
| 202 |
def test_arg_ghashtable(self): |
| 203 |
def expected(hash_table: dict[int, int]) -> None: |
| 204 |
pass |
| 205 |
|
| 206 |
self.assertSignatureEqual(GIMarshallingTests.ghashtable_int_none_in, expected) |
| 207 |
|
| 208 |
def test_arg_gvalue(self): |
| 209 |
def expected(value: GObject.Value) -> None: |
| 210 |
pass |
| 211 |
|
| 212 |
self.assertSignatureEqual(GIMarshallingTests.gvalue_in, expected) |
| 213 |
|
| 214 |
def test_arg_struct(self): |
| 215 |
def expected(structs: list[GIMarshallingTests.SimpleStruct]) -> None: |
| 216 |
pass |
| 217 |
|
| 218 |
self.assertSignatureEqual(GIMarshallingTests.array_simple_struct_in, expected) |
| 219 |
|
| 220 |
def test_arg_boxed(self): |
| 221 |
def expected(structs: list[GIMarshallingTests.BoxedStruct]) -> None: |
| 222 |
pass |
| 223 |
|
| 224 |
self.assertSignatureEqual(GIMarshallingTests.array_struct_in, expected) |
| 225 |
|
| 226 |
def test_return(self): |
| 227 |
def expected() -> int: |
| 228 |
return 0 |
| 229 |
|
| 230 |
self.assertSignatureEqual(GIMarshallingTests.int_return_max, expected) |
| 231 |
|
| 232 |
def test_return_multiple(self): |
| 233 |
def expected() -> tuple[int, int]: |
| 234 |
return (0, 0) |
| 235 |
|
| 236 |
self.assertSignatureEqual(GIMarshallingTests.int_out_out, expected) |
| 237 |
self.assertSignatureEqual(GIMarshallingTests.int_return_out, expected) |
| 238 |
|
| 239 |
def test_object_full_inout(self): |
| 240 |
class A: |
| 241 |
@staticmethod |
| 242 |
def expected( |
| 243 |
object: GIMarshallingTests.Object, |
| 244 |
) -> GIMarshallingTests.Object: |
| 245 |
pass |
| 246 |
|
| 247 |
self.assertSignatureEqual(GIMarshallingTests.Object.full_inout, A.expected) |
| 248 |
self.assertSignatureEqual(GIMarshallingTests.Object().full_inout, A().expected) |
| 249 |
|
| 250 |
def test_object_constructor(self): |
| 251 |
class A: |
| 252 |
@classmethod |
| 253 |
def expected(cls, int_: int) -> GIMarshallingTests.Object: |
| 254 |
pass |
| 255 |
|
| 256 |
self.assertSignatureEqual(GIMarshallingTests.Object.new, A.expected) |
| 257 |
self.assertSignatureEqual(GIMarshallingTests.Object().new, A().expected) |
| 258 |
|
| 259 |
def test_object_method(self): |
| 260 |
class A: |
| 261 |
def expected(self, ints: list[int]) -> None: |
| 262 |
pass |
| 263 |
|
| 264 |
self.assertSignatureEqual(GIMarshallingTests.Object.method_array_in, A.expected) |
| 265 |
self.assertSignatureEqual( |
| 266 |
GIMarshallingTests.Object().method_array_in, A().expected |
| 267 |
) |
| 268 |
|
| 269 |
def test_object_static_method(self): |
| 270 |
class A: |
| 271 |
@staticmethod |
| 272 |
def expected() -> None: |
| 273 |
pass |
| 274 |
|
| 275 |
self.assertSignatureEqual(GIMarshallingTests.Object.static_method, A.expected) |
| 276 |
self.assertSignatureEqual( |
| 277 |
GIMarshallingTests.Object().static_method, A().expected |
| 278 |
) |
| 279 |
|
| 280 |
def test_object_virtual_method(self): |
| 281 |
class A: |
| 282 |
@classmethod |
| 283 |
def expected(cls, self, object: GObject.GObject) -> None: |
| 284 |
pass |
| 285 |
|
| 286 |
self.assertSignatureEqual( |
| 287 |
GIMarshallingTests.Object.do_vfunc_in_object_transfer_none, A.expected |
| 288 |
) |
| 289 |
self.assertSignatureEqual( |
| 290 |
GIMarshallingTests.Object().do_vfunc_in_object_transfer_none, A().expected |
| 291 |
) |
| 292 |
|
| 293 |
def test_arg_conflict(self): |
| 294 |
class A: |
| 295 |
@classmethod |
| 296 |
def expected( |
| 297 |
type_, |
| 298 |
self, |
| 299 |
offset: int, |
| 300 |
type: GLib.SeekType, |
| 301 |
cancellable: Gio.Cancellable | None = None, |
| 302 |
) -> bool: |
| 303 |
return True |
| 304 |
|
| 305 |
self.assertSignatureEqual(Gio.FileIOStream.do_seek, A.expected) |