1# -*- coding: utf-8 -*- 2from mock import Mock 3import pytest 4 5from pyee import EventEmitter 6from pyee.cls import evented, on 7 8 9@evented 10class EventedFixture: 11 def __init__(self): 12 self.call_me = Mock() 13 14 @on("event") 15 def event_handler(self, *args, **kwargs): 16 self.call_me(self, *args, **kwargs) 17 18 19_custom_event_emitter = EventEmitter() 20 21 22@evented 23class CustomEmitterFixture: 24 def __init__(self): 25 self.call_me = Mock() 26 self.event_emitter = _custom_event_emitter 27 28 @on("event") 29 def event_handler(self, *args, **kwargs): 30 self.call_me(self, *args, **kwargs) 31 32 33class InheritedFixture(EventedFixture): 34 pass 35 36 37@pytest.mark.parametrize( 38 "cls", [EventedFixture, CustomEmitterFixture, InheritedFixture] 39) 40def test_evented_decorator(cls): 41 inst = cls() 42 43 inst.event_emitter.emit("event", "emitter is emitted!") 44 45 inst.call_me.assert_called_once_with(inst, "emitter is emitted!") 46 47 _custom_event_emitter.remove_all_listeners() 48