Module pmock
[show private | hide private]
[frames | no frames]

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
  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.

Function Details

at_least_once()

Method will be called at least once.

Convenience function for creating a AtLeastOnceInvocationMatcher instance.

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.

never()

Method will not be called.

Convenience function for getting a NotCalledInvocationMatcher 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.

Generated by Epydoc 2.0 on Sun Jul 25 19:39:43 2004 http://epydoc.sf.net