class documentation

class Counter: (source)

View In Hierarchy

a simple counter object for testing trial's doctest support

>>> c = Counter()
>>> c.value()
0
>>> c += 3
>>> c.value()
3
>>> c.incr()
>>> c.value() == 4
True
>>> c == 4
True
>>> c != 9
True
Method __eq__ equality operator, compare other to my value()
Method __iadd__ add other to my value and return self
Method __init__ Undocumented
Method __ne__ inequality operator
Method incr increment my value by 1
Method unexpectedException i will raise an unexpected exception... ... *CAUSE THAT'S THE KINDA GUY I AM*
Method value return this counter's value
Instance Variable maxval Undocumented
Instance Variable _count Undocumented
def __eq__(self, other): (source)

equality operator, compare other to my value()

>>> c = Counter()
>>> c == 0
True
>>> c += 10
>>> c.incr()
>>> c == 10   # fail this test on purpose
True
Parameters
other:objectUndocumented
Returns
boolUndocumented
def __iadd__(self, other): (source)

add other to my value and return self

>>> c = Counter(100)
>>> c += 333
>>> c == 433
True
def __init__(self, initialValue=0, maxval=None): (source)

Undocumented

def __ne__(self, other): (source)

inequality operator

>>> c = Counter()
>>> c != 10
True
Parameters
other:objectUndocumented
Returns
boolUndocumented
def incr(self): (source)

increment my value by 1

>>> from twisted.trial.test.mockdoctest import Counter
>>> c = Counter(10, 11)
>>> c.incr()
>>> c.value() == 11
True
>>> c.incr()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "twisted/trial/test/mockdoctest.py", line 51, in incr
    self.__iadd__(1)
  File "twisted/trial/test/mockdoctest.py", line 39, in __iadd__
    raise ValueError, "sorry, counter got too big"
ValueError: sorry, counter got too big
def unexpectedException(self): (source)

i will raise an unexpected exception... ... *CAUSE THAT'S THE KINDA GUY I AM*

>>> 1/0
def value(self): (source)

return this counter's value

>>> c = Counter(555)
>>> c.value() == 555
True

Undocumented

Undocumented