tests: deal with events containing dict in kwargs
If kwargs contains dict as one of values, it isn't hashable and can't be used as value in frozenset/tuple. Convert such values into frozenset(dict.items()). Only one (more) level is supported, but it should be enough. Solution from http://stackoverflow.com/a/13264725
This commit is contained in:
parent
beaa0e9348
commit
f1c8f3220d
@ -143,12 +143,22 @@ class TestEmitter(qubes.events.Emitter):
|
||||
|
||||
def fire_event(self, event, **kwargs):
|
||||
effects = super(TestEmitter, self).fire_event(event, **kwargs)
|
||||
self.fired_events[(event, tuple(kwargs.items()))] += 1
|
||||
ev_kwargs = frozenset(
|
||||
(key,
|
||||
frozenset(value.items()) if isinstance(value, dict) else value)
|
||||
for key, value in kwargs.items()
|
||||
)
|
||||
self.fired_events[(event, ev_kwargs)] += 1
|
||||
return effects
|
||||
|
||||
def fire_event_pre(self, event, **kwargs):
|
||||
effects = super(TestEmitter, self).fire_event_pre(event, **kwargs)
|
||||
self.fired_events[(event, tuple(kwargs.items()))] += 1
|
||||
ev_kwargs = frozenset(
|
||||
(key,
|
||||
frozenset(value.items()) if isinstance(value, dict) else value)
|
||||
for key, value in kwargs.items()
|
||||
)
|
||||
self.fired_events[(event, ev_kwargs)] += 1
|
||||
return effects
|
||||
|
||||
def expectedFailureIfTemplate(templates):
|
||||
|
Loading…
Reference in New Issue
Block a user