From 836982b46ab9e1e60b12009aa5abab384131c697 Mon Sep 17 00:00:00 2001 From: smiddlek Date: Mon, 12 Nov 2012 18:59:51 +0000 Subject: Patch for Issue 51, contributed by matt@ihavethememo.net git-svn-id: http://pymox.googlecode.com/svn/trunk@74 b1010a0a-674b-0410-b734-77272b80c875 --- mox.py | 11 +++++++++-- mox_test.py | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mox.py b/mox.py index 482acd0..f250187 100755 --- a/mox.py +++ b/mox.py @@ -600,7 +600,10 @@ class MockObject(MockAnything, object): pass for method in dir(class_to_mock): - attr = getattr(class_to_mock, method) + try: + attr = getattr(class_to_mock, method) + except AttributeError: + continue if callable(attr): self._known_methods.add(method) elif not (type(attr) is property): @@ -2062,7 +2065,11 @@ class MoxMetaTestBase(type): for base in bases: for attr_name in dir(base): if attr_name not in d: - d[attr_name] = getattr(base, attr_name) + try: + attr_value = getattr(base, attr_name) + except AttributeValue: + continue + d[attr_name] = attr_value for func_name, func in d.items(): if func_name.startswith('test') and callable(func): diff --git a/mox_test.py b/mox_test.py index d489f0b..89efd48 100755 --- a/mox_test.py +++ b/mox_test.py @@ -1253,7 +1253,18 @@ class MoxTest(unittest.TestCase): def testCreateObject(self): """Mox should create a mock object.""" - mock_obj = self.mox.CreateMock(TestClass) + self.mox.CreateMock(TestClass) + + def testCreateMockOfType(self): + self.mox.CreateMock(type) + + def testCreateMockWithBogusAttr(self): + + class BogusAttrClass(object): + __slots__ = 'no_such_attr', + + foo = BogusAttrClass() + self.mox.CreateMock(foo) def testVerifyObjectWithCompleteReplay(self): """Mox should replay and verify all objects it created.""" @@ -1664,7 +1675,8 @@ class MoxTest(unittest.TestCase): self.assertEquals('foo', actual) def testStubOutMethod_Unbound_Subclass_Comparator(self): - self.mox.StubOutWithMock(mox_test_helper.TestClassFromAnotherModule, 'Value') + self.mox.StubOutWithMock(mox_test_helper.TestClassFromAnotherModule, + 'Value') mox_test_helper.TestClassFromAnotherModule.Value( mox.IsA(mox_test_helper.ChildClassFromAnotherModule)).AndReturn('foo') self.mox.ReplayAll() -- cgit v1.2.1