Skip to content

Instantly share code, notes, and snippets.

@cnsoft
Last active December 17, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnsoft/5589121 to your computer and use it in GitHub Desktop.
Save cnsoft/5589121 to your computer and use it in GitHub Desktop.
how to use pymox mock bigworld module
import mox
import stubout
#test function tearup
m = mox.Mox()
BigWorld = m.CreateMockAnything()
m.StubOutWithMock(BigWorld,"entities")
m.StubOutWithMock(BigWorld,"singleton")
#Great,prepare clientside input data for function be called.
BigWorld.entities.get(100).AndReturn(None)
#stub we can stub property to BigWorld.bots ?
stub = stubout.StubOutForTesting()
stub.Set(BigWorld, 'entities2', {}) ## good . we can access it with property entities2
BigWorld.singleton.evtImpEvent(1,None,20).AndReturn("i trigger event")
#tearup
m.ReplayAll()
### call ####
print BigWorld.singleton.evtImpEvent(1,None,20) # GlobalTechConfig.EVT_CHARGE_POINT_UPDATE, None, self.chargePoint )
e = BigWorld.entities.get(100)
BigWorld.entities2[100] = m
print BigWorld.entities2.get(100)
#teardown
m.VerifyAll()
#
print e
assert e == None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment