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

StubOutClassWithMocks does not work with abstract base classes (ABC) #47

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

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
Create a file foo.py containing the following class definitions:
import abc

class Foo(object):
  __metaclass__ = abc.ABCMeta

class Bar(Foo):
  pass

Now execute the following:
import foo
import mox
mox.Mox().StubOutClassWithMocks(foo, 'Foo')

What is the expected output?
StubOutClassWithMocks() should not produce any errors.

What do you see instead?
Raises "TypeError: Given attr is not a Class.  Use StubOutWithMock."

Reason: type(foo.Foo) is <class 'abc.ABCMeta'>, which doesn't fall into any of 
the categories in _USE_MOCK_FACTORY.

Original issue reported on code.google.com by openvcd...@gmail.com on 12 Apr 2012 at 11:53

@GoogleCodeExporter
Copy link
Author

I'm attaching a diff against trunk to add support for this.  Please apply and 
pull in to our internal version.  Thanks! :)

We need this for Python 2.7 support as things being mocked in some code such as 
gzip.GZipFile inherit from a <class 'abc.ABCMeta'> base class.

Original comment by g...@google.com on 15 Aug 2012 at 11:26

Attachments:

@GoogleCodeExporter
Copy link
Author

We really need this.

Original comment by g...@google.com on 16 Nov 2012 at 5:41

@GoogleCodeExporter
Copy link
Author

Submitted as Revision 75.

Original comment by steve.mi...@gmail.com on 16 Nov 2012 at 7:18

  • Changed state: Fixed

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