Module pmock
Python mock object framework, providing support for creating mock
objects for use in unit testing.
The api is modelled on the jmock mock object framework.
Usage:
import pmock
import unittest
class PowerStation(object):
def start_up(self, reactor):
try:
reactor.activate('core')
except Exception, err:
reactor.shutdown()
class PowerStationTestCase(unittest.TestCase):
def test_successful_activation(self):
mock = pmock.Mock()
mock.expects(pmock.once()).activate(pmock.eq('core'))
PowerStation().start_up(mock)
mock.verify()
def test_problematic_activation(self):
mock = pmock.Mock()
mock.expects(pmock.once()).activate(pmock.eq('core')).will(
pmock.throw_exception(RuntimeError('overheating')))
mock.expects(pmock.once()).shutdown()
PowerStation().start_up(mock)
mock.verify()
if __name__ == '__main__':
unittest.main()
Further information is available in the bundled documentation, and
from http://pmock.sourceforge.net/
Copyright (c) 2004, Graham Carlyle
This module is free software, and you may redistribute it and/or
modify it under the same terms as Python itself, so long as this
copyright message and disclaimer are retained in their original form.
IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS
IS" BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
Function Summary |
|
at_least_once ()
Method will be called at least once. |
|
eq (expected)
Argument will be equal to supplied value. |
|
functor (boolean_functor)
Supplied unary function evaluates to True when called with
argument. |
|
never ()
Method will not be called. |
|
once ()
Method will be called only once. |
|
raise_exception (exception)
Stub that raises the supplied exception. |
|
return_value (value)
Stub that returns the supplied value. |
|
same (expected)
Argument will be the same as the supplied reference. |
|
string_contains (expected)
Argument contains the supplied substring. |
eq(expected)
Argument will be equal to supplied value.
Convenience function for creating a EqConstraint instance.
-
|
functor(boolean_functor)
Supplied unary function evaluates to True when called with
argument.
Convenience function for creating a FunctorConstraint instance.
-
|
once()
Method will be called only once.
Convenience function for creating a OnceInvocationMatcher instance.
-
|
raise_exception(exception)
Stub that raises the supplied exception.
Convenience function for creating a RaiseExceptionStub instance.
-
|
return_value(value)
Stub that returns the supplied value.
Convenience function for creating a ReturnValueStub instance.
-
|
same(expected)
Argument will be the same as the supplied reference.
Convenience function for creating a SameConstraint instance.
-
|
string_contains(expected)
Argument contains the supplied substring.
Convenience function for creating a StringContainsConstraint instance.
-
|
__author__
-
- Type:
-
str
- Value:
|
__email__
-
- Type:
-
str
- Value:
'grahamcarlyle at users dot sourceforge dot net'
|
|
__version__
-
- Type:
-
str
- Value:
|
_DEFAULT_STUB
-
- Type:
-
DefaultStub
- Value:
<pmock.DefaultStub object at 0x403bd1cc>
|
|
_NOT_CALLED_MATCHER_INSTANCE
-
- Type:
-
NotCalledInvocationMatcher
- Value:
<pmock.NotCalledInvocationMatcher object at 0x403bd4ac>
|
|
_STUB_MATCHER_INSTANCE
-
- Type:
-
StubInvocationMatcher
- Value:
<pmock.StubInvocationMatcher object at 0x403bd4ec>
|
|
ANY_ARGS_MATCHER
-
- Type:
-
LeastArgumentsMatcher
- Value:
<pmock.LeastArgumentsMatcher object at 0x403a5f0c>
|
|
NO_ARGS_MATCHER
-
- Type:
-
AllArgumentsMatcher
- Value:
<pmock.AllArgumentsMatcher object at 0x403a5f2c>
|
|