diff options
author | smiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875> | 2010-04-20 23:47:16 +0000 |
---|---|---|
committer | smiddlek <smiddlek@b1010a0a-674b-0410-b734-77272b80c875> | 2010-04-20 23:47:16 +0000 |
commit | 680c81d422098470fae59273a56fc3f155514456 (patch) | |
tree | 67976559e88bb5033459481a13791b19ae98ab66 | |
parent | 0ab49537a5ee5cae80d7447e8a787eee734b02cc (diff) | |
download | mox-680c81d422098470fae59273a56fc3f155514456.tar.gz |
Long over due patch from alan.franzoni for better property support (Issue 11).
I'm very sorry about the delay.
git-svn-id: http://pymox.googlecode.com/svn/trunk@42 b1010a0a-674b-0410-b734-77272b80c875
-rwxr-xr-x | mox.py | 6 | ||||
-rwxr-xr-x | mox_test.py | 16 |
2 files changed, 20 insertions, 2 deletions
@@ -441,9 +441,11 @@ class MockObject(MockAnything, object): pass for method in dir(class_to_mock): - if callable(getattr(class_to_mock, method)): + attr = getattr(class_to_mock, method) + if callable(attr): self._known_methods.add(method) - else: + elif not (type(attr) is property): + # treating properties as class vars makes little sense. self._known_vars.add(method) # Set additional attributes at instantiation time; this is quicker diff --git a/mox_test.py b/mox_test.py index ea12176..c7432df 100755 --- a/mox_test.py +++ b/mox_test.py @@ -1759,6 +1759,12 @@ class MoxTestBaseMultipleInheritanceTest(mox.MoxTestBase, MyTestCase): super(MoxTestBaseMultipleInheritanceTest, self).testMethodOverride() self.assertEquals(43, self.another_critical_variable) +class MoxTestDontMockProperties(MoxTestBaseTest): + def testPropertiesArentMocked(self): + mock_class = self.mox.CreateMock(ClassWithProperties) + self.assertRaises(mox.UnknownMethodCallError, lambda: + mock_class.prop_attr) + class TestClass: """This class is used only for testing the mock framework""" @@ -1819,6 +1825,7 @@ class TestClass: def __iter__(self): pass + class ChildClass(TestClass): """This inherits from TestClass.""" def __init__(self): @@ -1837,6 +1844,15 @@ class CallableClass(object): def __call__(self, param): return param +class ClassWithProperties(object): + def setter_attr(self, value): + pass + + def getter_attr(self): + pass + + prop_attr = property(getter_attr, setter_attr) + class SubscribtableNonIterableClass(object): def __getitem__(self, index): |