Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 51 by
m...@ihavethememo.net: mox.Mox.CreateMock() chokes if dir()
and getattr() do not agree
http://code.google.com/p/pymox/issues/detail?id=51
What steps will reproduce the problem?
Attempt to use mox.Mox.CreateMock() on an object where dir(obj) lists an
attribute but getattr(obj, attr_name) raises AttributeError.
What is the expected output? What do you see instead?
For example, in Python 2.7 type lists __abstractmethods__ as an attribute
while getattr(type, '__abstractmethods__') fails:
>>> mox.Mox().CreateMock(type)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mox.py", line 284, in CreateMock
new_mock = MockObject(class_to_mock, attrs=attrs)
File "mox.py", line 603, in __init__
attr = getattr(class_to_mock, method)
AttributeError: __abstractmethods__
A similar situation can arise when using slots:
>>> class ac(object): __slots__ = 'a',
...
>>> mox.Mox().CreateMock(ac())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mox.py", line 284, in CreateMock
new_mock = MockObject(class_to_mock, attrs=attrs)
File "mox.py", line 603, in __init__
attr = getattr(class_to_mock, method)
AttributeError: a
What version of the product are you using? On what operating system?
The latest version of mox from SVN, with Python 2.7.3rc2, built for 32-bit
Linux.
I have attached a patch to ignore such bogus attributes, with two test
cases.
Attachments:
mox_bogus_attr_fix.patch 2.1 KB