[Telepathy] twisted test question

Jonathon Jongsma jonathon.jongsma at collabora.co.uk
Wed Jan 28 11:30:21 PST 2009


Sorry, forgot to cc the list:

On 01/28/2009 10:31 AM, Jonathon Jongsma wrote:
> On 01/28/2009 01:22 AM, Alban Crequy wrote:
>> You can have a look here:
>> http://git.collabora.co.uk/?p=telepathy-gabble.git;a=blob;f=tests/twisted/test-caps-hash.py;h=17280f4fd35c6d18c5184deacec81f2a2236afa5;hb=master#l335
>>
>>
>> You can register a callback when the dbus-signal is fired, and set up a
>> flag in the callback.
>>
>> def caps_changed_cb(dummy):
>> # Workaround to bug 9980: do not raise an error but use a flag
>> # https://bugs.freedesktop.org/show_bug.cgi?id=9980
>> global caps_changed_flag
>> caps_changed_flag = True
>>
>> conn_caps_iface.connect_to_signal('CapabilitiesChanged',
>> caps_changed_cb)
>>
>> Then you can assert your flag is False.
>>
>> global caps_changed_flag
>> # don't receive any D-Bus signal
>> sync_dbus(bus, q, conn)
>> assert caps_changed_flag == False
>>
>> It is not as easy as q.expect_not because you need some synchronisation
>> (sync_dbus...), and you cannot assert directly in the callback because
>> of bug #9980.
>>
>> I am not sure 'ForbidEventPattern' is easy to write because you
>> would need to synchronise on possible events (D-Bus, streams).
>>
>
> Yeah, I didn't think my examples would be very simple to implement
> because of the synchronisation stuff, etc. But your solution seems like
> it should work, so I may use that. My current workaround was something
> like:
>
> try:
> q.expect(..)
> raise RuntimeError(...)
> except TimeoutError, e:
> # we *want* to timeout
> pass
>
> which is rather ugly, + it adds extra waiting time to the success case,
> which is not very nice.
>
> Thanks
> jonner



More information about the Telepathy mailing list