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

Improve MockObject description for classmethod #53

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

Improve MockObject description for classmethod #53

GoogleCodeExporter opened this issue Mar 19, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
import unittest
import mox

class Foo(object):

    @classmethod
    def some_method(cls):
        pass

class TestFoo(mox.MoxTestBase):

    def setUp(self):
        super(TestFoo, self).setUp()
        self.mox.StubOutWithMock(Foo, 'some_method')

    def test_some_method_is_called(self):
        Foo.some_method()
        self.mox.ReplayAll()

if __name__ == '__main__':
    unittest.main()

What do you see?
python test.py 
F
======================================================================
FAIL: test_some_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2120, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  instancemethod.__call__() -> None

Please provide any additional information below.
With the changes made from the patch, the output is -
python test.py 
F
======================================================================
FAIL: test_some_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2120, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  Foo.some_method.__call__() -> None

Original issue reported on code.google.com by kunalpar...@gmail.com on 18 Nov 2012 at 2:42

Attachments:

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

My earlier patch did not account for instance methods. Attached an updated 
patch.

Here's how I tested it -

import unittest
import mox

class Foo(object):

    @classmethod
    def cls_method(cls):
        pass

    def ins_method(self):
        pass

class TestFoo(mox.MoxTestBase):

    def setUp(self):
        super(TestFoo, self).setUp()
        self.mox.StubOutWithMock(Foo, 'cls_method')
        self.foo = Foo()
        self.mox.StubOutWithMock(self.foo, 'ins_method')

    def test_cls_method_is_called(self):
        Foo.cls_method()
        self.mox.ReplayAll()

    def test_ins_method_is_called(self):
        self.foo.ins_method()
        self.mox.ReplayAll()

if __name__ == '__main__':
    unittest.main()

Output before -
python test.py 
FF
======================================================================
FAIL: test_cls_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2123, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  instancemethod.__call__() -> None

======================================================================
FAIL: test_ins_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2123, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  instancemethod.__call__() -> None

Output after -
python test.py 
FF
======================================================================
FAIL: test_cls_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2123, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  Foo.cls_method.__call__() -> None

======================================================================
FAIL: test_ins_method_is_called (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/kparmar/sources/pymox/mox.py", line 2123, in new_method
    mox_obj.VerifyAll()
  File "/Users/kparmar/sources/pymox/mox.py", line 318, in VerifyAll
    mock_obj._Verify()
  File "/Users/kparmar/sources/pymox/mox.py", line 559, in _Verify
    raise ExpectedMethodCallsError(self._expected_calls_queue)
ExpectedMethodCallsError: Verify: Expected methods never called:
  0.  Foo.ins_method.__call__() -> None

Original comment by kunalpar...@gmail.com on 18 Nov 2012 at 2:54

Attachments:

@GoogleCodeExporter
Copy link
Author

Haven't seen any progress on this. Do you need more information?

Original comment by kunalpar...@gmail.com on 29 Nov 2012 at 8:49

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