File: test_cls.py

package info (click to toggle)
pyee 13.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 296 kB
  • sloc: python: 1,113; makefile: 4; sh: 1
file content (48 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
from unittest.mock import Mock

import pytest

from pyee import EventEmitter
from pyee.cls import evented, on


@evented
class EventedFixture:
    def __init__(self):
        self.call_me = Mock()

    @on("event")
    def event_handler(self, *args, **kwargs):
        self.call_me(self, *args, **kwargs)


_custom_event_emitter = EventEmitter()


@evented
class CustomEmitterFixture:
    def __init__(self):
        self.call_me = Mock()
        self.event_emitter = _custom_event_emitter

    @on("event")
    def event_handler(self, *args, **kwargs):
        self.call_me(self, *args, **kwargs)


class InheritedFixture(EventedFixture):
    pass


@pytest.mark.parametrize(
    "cls", [EventedFixture, CustomEmitterFixture, InheritedFixture]
)
def test_evented_decorator(cls):
    inst = cls()

    inst.event_emitter.emit("event", "emitter is emitted!")

    inst.call_me.assert_called_once_with(inst, "emitter is emitted!")

    _custom_event_emitter.remove_all_listeners()