Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnexpectedMethodCallError in an other moudle call moxed time.localtime() #46

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. mox the time.localtime()
2. call time.localtime() in an other moudle

code:
0 .... 
1 t = time.gmtime(time.mktime((2012, 10, 1, 15, 26,0,0,0,0))) 
2 self.mox.StubOutWithMock?(time, 'localtime') 
3 time.localtime().AndReturn?(t) 
4 self.mox.ReplayAll()
5 print "mox localtime:", time.localtime()    # correct
6 othermoudle.func() # call time.localtime() in func()  # error
7 ...

What is the expected output? What do you see instead?
on the line 5,I got a correct mox time: 
(Pdb) time.localtime() 
time.struct_time(tm_year=2012, tm_mon=10, tm_mday=1, tm_hour=7, tm_min=26, 
tm_sec=0, tm_wday=0, tm_yday=275, tm_isdst=0)

and then call time.localtime in an other moudle, I got an error: 
(Pdb) time.time() 
1333178201.334844 
(Pdb) time.localtime() 
UnexpectedMethodCallError: Unexpected method call Stub for <built-in function 
localtime>.call() -> None 
(Pdb)


What version of the product are you using? On what operating system?
mox-0.5.3-py2.7.egg
python 2.7
Ubuntu 11.10 desktop

Please provide any additional information below.
my error msg is:
Unit test of worker.

mox localtime: time.struct_time(tm_year=2012, tm_mon=10, tm_mday=1, tm_hour=7, 
tm_min=26, tm_sec=0, tm_wday=0, tm_yday=275, tm_isdst=0)

F
======================================================================
FAIL: testIsTimeToWorkFirst (__main__.WorkerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_worker.py", line 64, in testIsTimeToWorkFirst
    ret = w.is_timeto_work()
  File "/home/pyw/work/demux/worker/worker.py", line 119, in is_timeto_work
    self.update_time()
  File "/home/pyw/work/demux/worker/worker.py", line 92, in update_time
    localtime = time.localtime()
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 1002, in __call__
    expected_method = self._VerifyMethodCall()
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 1049, in _VerifyMethodCall
    expected = self._PopNextMethod()
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 1035, in _PopNextMethod
    raise UnexpectedMethodCallError(self, None)
UnexpectedMethodCallError: Unexpected method call Stub for <built-in function 
localtime>.__call__() -> None

Original issue reported on code.google.com by pengyu...@gmail.com on 31 Mar 2012 at 7:47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant