Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / twisted / trial / test / | server ip : 172.67.156.115 your ip : 172.69.58.251 H O M E |
Filename | /usr/lib/python2.7/dist-packages/twisted/trial/test/mockdoctest.py |
Size | 2.61 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 24-Aug-2013 02:26 |
Last accessed | 07-Jul-2025 10:03 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
# this module is a trivial class with doctests to test trial's doctest
# support.
from __future__ import division, absolute_import
class Counter(object):
"""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
"""
_count = 0
def __init__(self, initialValue=0, maxval=None):
self._count = initialValue
self.maxval = maxval
def __iadd__(self, other):
"""add other to my value and return self
>>> c = Counter(100)
>>> c += 333
>>> c == 433
True
"""
if self.maxval is not None and ((self._count + other) > self.maxval):
raise ValueError, "sorry, counter got too big"
else:
self._count += other
return self
def __eq__(self, other):
"""equality operator, compare other to my value()
>>> c = Counter()
>>> c == 0
True
>>> c += 10
>>> c.incr()
>>> c == 10 # fail this test on purpose
True
"""
return self._count == other
def __ne__(self, other):
"""inequality operator
>>> c = Counter()
>>> c != 10
True
"""
return not self.__eq__(other)
def incr(self):
"""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
"""
self.__iadd__(1)
def value(self):
"""return this counter's value
>>> c = Counter(555)
>>> c.value() == 555
True
"""
return self._count
def unexpectedException(self):
"""i will raise an unexpected exception...
... *CAUSE THAT'S THE KINDA GUY I AM*
>>> 1/0
"""
# See LICENSE for details.
# this module is a trivial class with doctests to test trial's doctest
# support.
from __future__ import division, absolute_import
class Counter(object):
"""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
"""
_count = 0
def __init__(self, initialValue=0, maxval=None):
self._count = initialValue
self.maxval = maxval
def __iadd__(self, other):
"""add other to my value and return self
>>> c = Counter(100)
>>> c += 333
>>> c == 433
True
"""
if self.maxval is not None and ((self._count + other) > self.maxval):
raise ValueError, "sorry, counter got too big"
else:
self._count += other
return self
def __eq__(self, other):
"""equality operator, compare other to my value()
>>> c = Counter()
>>> c == 0
True
>>> c += 10
>>> c.incr()
>>> c == 10 # fail this test on purpose
True
"""
return self._count == other
def __ne__(self, other):
"""inequality operator
>>> c = Counter()
>>> c != 10
True
"""
return not self.__eq__(other)
def incr(self):
"""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
"""
self.__iadd__(1)
def value(self):
"""return this counter's value
>>> c = Counter(555)
>>> c.value() == 555
True
"""
return self._count
def unexpectedException(self):
"""i will raise an unexpected exception...
... *CAUSE THAT'S THE KINDA GUY I AM*
>>> 1/0
"""