Home | Trees | Index | Help |
|
---|
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.Classes | |
---|---|
Mock |
A mock object. |
MockTestCase |
Function Summary | |
---|---|
Method will be called at least once. | |
Argument will be equal to supplied value. | |
Supplied unary function evaluates to True when called with argument. | |
Method will not be called. | |
Method will be called only once. | |
Stub that raises the supplied exception. | |
Stub that returns the supplied value. | |
Argument will be the same as the supplied reference. | |
Argument contains the supplied substring. |
Function Details |
---|
at_least_once()Method will be called at least once. Convenience function for creating aAtLeastOnceInvocationMatcher
instance.
|
eq(expected)Argument will be equal to supplied value. Convenience function for creating aEqConstraint instance.
|
functor(boolean_functor)Supplied unary function evaluates to True when called with argument. Convenience function for creating aFunctorConstraint instance.
|
never()Method will not be called. Convenience function for getting aNotCalledInvocationMatcher instance.
|
once()Method will be called only once. Convenience function for creating aOnceInvocationMatcher instance.
|
raise_exception(exception)Stub that raises the supplied exception. Convenience function for creating aRaiseExceptionStub instance.
|
return_value(value)Stub that returns the supplied value. Convenience function for creating aReturnValueStub instance.
|
same(expected)Argument will be the same as the supplied reference. Convenience function for creating aSameConstraint instance.
|
string_contains(expected)Argument contains the supplied substring. Convenience function for creating aStringContainsConstraint instance.
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.0 on Sun Jul 25 19:39:43 2004 | http://epydoc.sf.net |