File: test_component_setup.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (89 lines) | stat: -rw-r--r-- 1,414 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from circuits import Component, Manager
from circuits.core.handlers import handler


"""Component Setup Tests

Tests that event handlers of a Component are
automatically registered as event handlers.
"""


class App(Component):
    def test(self, event, *args, **kwargs):
        pass


class A(Component):
    pass


class B(Component):
    informed = False

    @handler('prepare_unregister', channel='*')
    def _on_prepare_unregister(self, event, c):
        if event.in_subtree(self):
            self.informed = True


class Base(Component):
    channel = 'base'


class C(Base):
    channel = 'c'


def test_basic():
    m = Manager()

    app = App()
    app.register(m)

    assert app.test in app._handlers.get('test', set())

    app.unregister()
    while len(m):
        m.flush()

    assert not m._handlers


def test_complex():
    m = Manager()

    a = A()
    b = B()

    a.register(m)
    b.register(a)

    assert a in m
    assert a.root == m
    assert a.parent == m
    assert b in a
    assert b.root == m
    assert b.parent == a

    a.unregister()
    while len(m):
        m.flush()

    assert b.informed
    assert a not in m
    assert a.root == a
    assert a.parent == a
    assert b in a
    assert b.root == a
    assert b.parent == a


def test_subclassing_with_custom_channel():
    base = Base()

    assert base.channel == 'base'

    c = C()

    assert c.channel == 'c'