Last active
December 17, 2015 09:39
-
-
Save cnsoft/5589121 to your computer and use it in GitHub Desktop.
how to use pymox mock bigworld module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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