1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
4
# this module is a trivial class with doctests and a __test__ attribute
5
# to test trial's doctest support with python2.4
9
"""a simple counter object for testing trial's doctest support
28
def __init__(self, initialValue=0, maxval=None):
29
self._count = initialValue
32
def __iadd__(self, other):
33
"""add other to my value and return self
40
if self.maxval is not None and ((self._count + other) > self.maxval):
41
raise ValueError, "sorry, counter got too big"
46
def __eq__(self, other):
47
"""equality operator, compare other to my value()
54
>>> c == 10 # fail this test on purpose
58
return self._count == other
60
def __ne__(self, other):
61
"""inequality operator
67
return not self.__eq__(other)
70
"""increment my value by 1
72
>>> from twisted.trial.test.mockdoctest import Counter
73
>>> c = Counter(10, 11)
78
Traceback (most recent call last):
79
File "<stdin>", line 1, in ?
80
File "twisted/trial/test/mockdoctest.py", line 51, in incr
82
File "twisted/trial/test/mockdoctest.py", line 39, in __iadd__
83
raise ValueError, "sorry, counter got too big"
84
ValueError: sorry, counter got too big
89
"""return this counter's value
97
def unexpectedException(self):
98
"""i will raise an unexpected exception...
99
... *CAUSE THAT'S THE KINDA GUY I AM*