|
1 | 1 | import math |
2 | 2 | import time |
| 3 | +import warnings |
| 4 | + |
| 5 | +def test_dispatcher_construction(): |
| 6 | + from pydispatch import Dispatcher, Property |
| 7 | + |
| 8 | + class A(Dispatcher): |
| 9 | + foo = Property() |
| 10 | + bar = Property() |
| 11 | + baz = Property() |
| 12 | + _events_ = [ |
| 13 | + 'on_stuff', 'on_more_stuff', |
| 14 | + ] |
| 15 | + class B(A): |
| 16 | + a = Property() |
| 17 | + b = Property() |
| 18 | + c = Property() |
| 19 | + _events_ = [ |
| 20 | + 'on_even_more_stuff', 'on_one_more_thing' |
| 21 | + ] |
| 22 | + |
| 23 | + with warnings.catch_warnings(record=True) as w_list: |
| 24 | + warnings.simplefilter("always") |
| 25 | + a = A() |
| 26 | + b = B() |
| 27 | + for w in w_list: |
| 28 | + # Check for PEP-0479 (StopIteration) issues |
| 29 | + assert not issubclass(w.category, DeprecationWarning) |
| 30 | + assert not issubclass(w.category, PendingDeprecationWarning) |
| 31 | + assert len(w_list) == 0 |
| 32 | + |
| 33 | + a_prop_names = {'foo', 'bar', 'baz'} |
| 34 | + a_event_names = {'on_stuff', 'on_more_stuff'} |
| 35 | + assert a_prop_names == set(a._Dispatcher__property_events.keys()) |
| 36 | + assert a_event_names == set(a._Dispatcher__events.keys()) |
| 37 | + |
| 38 | + b_prop_names = {'a', 'b', 'c'} |
| 39 | + b_prop_names |= a_prop_names |
| 40 | + b_event_names = {'on_even_more_stuff', 'on_one_more_thing'} |
| 41 | + b_event_names |= a_event_names |
| 42 | + |
| 43 | + assert b_prop_names == set(b._Dispatcher__property_events.keys()) |
| 44 | + assert b_event_names == set(b._Dispatcher__events.keys()) |
3 | 45 |
|
4 | 46 | def test_subclass_new_timing(): |
5 | 47 | from pydispatch import Dispatcher, Property |
|
0 commit comments