Issue 51 in pymox: mox.Mox.CreateMock() chokes if dir() and getattr() do not agree

5 views
Skip to first unread message

codesite...@google.com

unread,
Nov 8, 2012, 8:20:11 PM11/8/12
to mox-d...@googlegroups.com
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

codesite...@google.com

unread,
Nov 12, 2012, 2:00:45 PM11/12/12
to mox-d...@googlegroups.com
Updates:
Status: Fixed

Comment #1 on issue 51 by stev...@google.com: mox.Mox.CreateMock() chokes
if dir() and getattr() do not agree
http://code.google.com/p/pymox/issues/detail?id=51

Fixed in http://code.google.com/p/pymox/source/detail?r=74

Reply all
Reply to author
Forward
0 new messages