kgashok / pymox

Automatically exported from code.google.com/p/pymox
Apache License 2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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 commented 8 years ago
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 commented 8 years ago
We really need this.

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

GoogleCodeExporter commented 8 years ago
Submitted as Revision 75.

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