yamf

Yet another mock framework for Python
Download

yamf Ranking & Summary

Advertisement

  • Rating:
  • License:
  • LGPL
  • Publisher Name:
  • Mika Lackman
  • Publisher web site:
  • http://code.google.com/u/Mika.Lackman/

yamf Tags


yamf Description

Yet another mock framework for Python yamf is a mock framework for Python, which has taken influence from jMock.InstallingDownload latest version from Downloads and extract the file. Run sudo setup.py installBest way to see the usage is to see the test code test_yamf.pyBasic usageTo set basic expectation that doSomething must be called:m = yamf.Mock()m.doSomething.mustBeCalledMethod can be mocked also:mockMethod = yamf.MockMethod()mockMethod.mustBeCalledTo verify that the doSomething was called use:m.verify()The verify will raise assertion if the expectations are not met.To verify that method is not called use:m.doSomethingElse.mustNotBeCalledCall countsTo check that method is called certain times:m.doSomething.mustBeCalled.oncem.doSomething.mustBeCalled.times(2)m.doSomething.mustBeCalled.atLeastTimes(2)ArgumentsTo check arguments of the method:m.doSomething.mustBeCalled.withArgs(5,2)To check that method is called at least two times with specific argsm.doSomething.mustBeCalled.withArgs(5).mustBeCalled.withArgs(6)To check that method is called two times with same argsm.doSomething.mustBeCalled.withArgs(5).times(2)Return valueTo make a method to return value:m.doSomething.returns(1)This will also workm.doSomething.mustBeCalled.once.returns(5)ExecutingTo execute something when mock method is called:def method(a,b): #Do something. Note that the method return value is not given to callerm.doSomething.execute(method) # execute takes callableHistoryTo find out certain call's arguments:#Somewhere mock gets called likem.doSomething(1,k=2) m.doSomething(5,k=6)# calls will be calls = m.doSomething.historyArray of mocksTo handle situation where there are array of mocks:mocks = MockArray(4)mocks.method.mustBeCalled.times(2) for mock in mocks: mock.method() for mock in mocks: mock.method() mocks.verify()ModulesTo verify that certain module method is calledm = MockModule('os')m.getcwd.mustBeCalled# testing...m.verify()To make the module method to return valuem = MockModule('os')m.getcwd.returns('abc123') Requirements: · Python


yamf Related Software