Describe a kind of event, and its basic operations.
| 89 | |
| 90 | |
| 91 | class Event(object): |
| 92 | """Describe a kind of event, and its basic operations.""" |
| 93 | |
| 94 | def __init__(self, name, null, aggregator, formatter = str): |
| 95 | self.name = name |
| 96 | self._null = null |
| 97 | self._aggregator = aggregator |
| 98 | self._formatter = formatter |
| 99 | |
| 100 | def __eq__(self, other): |
| 101 | return self is other |
| 102 | |
| 103 | def __hash__(self): |
| 104 | return id(self) |
| 105 | |
| 106 | def null(self): |
| 107 | return self._null |
| 108 | |
| 109 | def aggregate(self, val1, val2): |
| 110 | """Aggregate two event values.""" |
| 111 | assert val1 is not None |
| 112 | assert val2 is not None |
| 113 | return self._aggregator(val1, val2) |
| 114 | |
| 115 | def format(self, val): |
| 116 | """Format an event value.""" |
| 117 | assert val is not None |
| 118 | return self._formatter(val) |
| 119 | |
| 120 | |
| 121 | CALLS = Event("Calls", 0, add, times) |
no outgoing calls
no test coverage detected