1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
4
# Author: Jonathan D. Simms <slyphon@twistedmatrix.com>
6
# this module is a trivial class with doctests and a __test__ attribute
7
# to test trial's doctest support with python2.4
10
class Counter(object):
11
"""a simple counter object for testing trial's doctest support
30
def __init__(self, initialValue=0, maxval=None):
31
self._count = initialValue
34
def __iadd__(self, other):
35
"""add other to my value and return self
42
if self.maxval is not None and ((self._count + other) > self.maxval):
43
raise ValueError, "sorry, counter got too big"
48
def __eq__(self, other):
49
"""equality operator, compare other to my value()
56
>>> c == 10 # fail this test on purpose
60
return self._count == other
62
def __ne__(self, other):
63
"""inequality operator
69
return not self.__eq__(other)
72
"""increment my value by 1
74
>>> from twisted.trial.test.mockdoctest import Counter
75
>>> c = Counter(10, 11)
80
Traceback (most recent call last):
81
File "<stdin>", line 1, in ?
82
File "twisted/trial/test/mockdoctest.py", line 51, in incr
84
File "twisted/trial/test/mockdoctest.py", line 39, in __iadd__
85
raise ValueError, "sorry, counter got too big"
86
ValueError: sorry, counter got too big
91
"""return this counter's value
99
def unexpectedException(self):
100
"""i will raise an unexpected exception...
101
... *CAUSE THAT'S THE KINDA GUY I AM*