| 1 |
from gi.repository import GLib, Gio, Regress |
| 2 |
|
| 3 |
|
| 4 |
def iteration(): |
| 5 |
ctx = GLib.main_context_default() |
| 6 |
while ctx.pending(): |
| 7 |
ctx.iteration(False) |
| 8 |
|
| 9 |
|
| 10 |
def test_async_callback(): |
| 11 |
result = [] |
| 12 |
cancel = Gio.Cancellable() |
| 13 |
|
| 14 |
def callback(obj, res): |
| 15 |
result.append(obj.function_finish(res)) |
| 16 |
|
| 17 |
obj = Regress.TestObj() |
| 18 |
obj.function_async(GLib.PRIORITY_DEFAULT, cancellable=cancel, callback=callback) |
| 19 |
obj.function_thaw_async() |
| 20 |
|
| 21 |
iteration() |
| 22 |
|
| 23 |
assert result == [True] |
| 24 |
|
| 25 |
|
| 26 |
def test_async_callback_with_extra_callbacks(): |
| 27 |
result = [] |
| 28 |
|
| 29 |
def callback(obj, res): |
| 30 |
result.append(obj.function2_finish(res)) |
| 31 |
|
| 32 |
obj = Regress.TestObj() |
| 33 |
obj.function2(GLib.PRIORITY_DEFAULT, None, None, None, callback) |
| 34 |
obj.function_thaw_async() |
| 35 |
|
| 36 |
iteration() |
| 37 |
|
| 38 |
assert result == [(True, True, None)] |
| 39 |
|
| 40 |
|
| 41 |
def test_async_callback_with_extra_callbacks_filled_in(): |
| 42 |
result = [] |
| 43 |
cancel = Gio.Cancellable() |
| 44 |
|
| 45 |
def test_cb(data): |
| 46 |
result.append(data) |
| 47 |
return 0 |
| 48 |
|
| 49 |
def callback(obj, res): |
| 50 |
result.append(obj.function2_finish(res)) |
| 51 |
|
| 52 |
obj = Regress.TestObj() |
| 53 |
obj.function2(GLib.PRIORITY_DEFAULT, cancel, test_cb, ("test_cb data",), callback) |
| 54 |
obj.function_thaw_async() |
| 55 |
|
| 56 |
iteration() |
| 57 |
|
| 58 |
assert result == ["test_cb data", (True, True, None)] |
| 59 |
|
| 60 |
|
| 61 |
def test_async_callback_with_extra_callbacks_as_kwarg(): |
| 62 |
result = [] |
| 63 |
cancel = Gio.Cancellable() |
| 64 |
|
| 65 |
def test_cb(data): |
| 66 |
result.append(data) |
| 67 |
return 0 |
| 68 |
|
| 69 |
def callback(obj, res): |
| 70 |
result.append(obj.function2_finish(res)) |
| 71 |
|
| 72 |
obj = Regress.TestObj() |
| 73 |
obj.function2( |
| 74 |
GLib.PRIORITY_DEFAULT, cancellable=cancel, test_cb=test_cb, callback=callback |
| 75 |
) |
| 76 |
obj.function_thaw_async() |
| 77 |
|
| 78 |
iteration() |
| 79 |
|
| 80 |
assert result == [None, (True, True, None)] |
| 81 |
|
| 82 |
|
| 83 |
def test_async_callback_with_extra_callbacks_as_kwarg_and_user_data(): |
| 84 |
result = [] |
| 85 |
cancel = Gio.Cancellable() |
| 86 |
|
| 87 |
def test_cb(data): |
| 88 |
result.append(data) |
| 89 |
return 0 |
| 90 |
|
| 91 |
def callback(obj, res, data): |
| 92 |
result.append(obj.function2_finish(res)) |
| 93 |
|
| 94 |
obj = Regress.TestObj() |
| 95 |
obj.function2( |
| 96 |
GLib.PRIORITY_DEFAULT, |
| 97 |
cancellable=cancel, |
| 98 |
test_cb=test_cb, |
| 99 |
callback=callback, |
| 100 |
user_data=None, |
| 101 |
) |
| 102 |
obj.function_thaw_async() |
| 103 |
|
| 104 |
iteration() |
| 105 |
|
| 106 |
assert result == [None, (True, True, None)] |