diff options
author | smiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875> | 2012-11-12 18:59:51 +0000 |
---|---|---|
committer | smiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875> | 2012-11-12 18:59:51 +0000 |
commit | 836982b46ab9e1e60b12009aa5abab384131c697 (patch) | |
tree | 8102e18c439ad857f56775b3c5cec30f2a189765 | |
parent | 4b5f8e08a18b21d9488d4061abeebaabcc62ad08 (diff) | |
download | mox-836982b46ab9e1e60b12009aa5abab384131c697.tar.gz |
Patch for Issue 51, contributed by matt@ihavethememo.net
git-svn-id: http://pymox.googlecode.com/svn/trunk@74 b1010a0a-674b-0410-b734-77272b80c875
-rwxr-xr-x | mox.py | 11 | ||||
-rwxr-xr-x | mox_test.py | 16 |
2 files changed, 23 insertions, 4 deletions
@@ -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() |