From 4adacddee307c4f90d8cb49ca69f83176967a4e7 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gajda Date: Mon, 23 Apr 2012 15:59:47 +0200 Subject: Converted all classes to the new style (inheriting from object) - this is the only option in py3k. --- mox.py | 15 ++++++++++++--- mox_test.py | 4 ++-- stubout.py | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mox.py b/mox.py index cbf73aa..595a133 100755 --- a/mox.py +++ b/mox.py @@ -417,7 +417,7 @@ def Reset(*args): mock._Reset() -class MockAnything: +class MockAnything(object): """A mock that can be used to mock anything. This is helpful for mocking classes that do not provide a public interface. @@ -457,7 +457,16 @@ class MockAnything: return self.__class__.__dir__.__get__(self, self.__class__) return self._CreateMockMethod(method_name) - + + def __str__(self): + return self._CreateMockMethod('__str__')() + + def __call__(self, *args, **kwargs): + return self._CreateMockMethod('__call__')(*args, **kwargs) + + def __getitem__(self, i): + return self._CreateMockMethod('__getitem__')(i) + def _CreateMockMethod(self, method_name, method_to_mock=None): """Create a new mock method call and return it. @@ -529,7 +538,7 @@ class MockAnything: self._replay_mode = False -class MockObject(MockAnything, object): +class MockObject(MockAnything): """A mock object that simulates the public/protected interface of a class.""" def __init__(self, class_to_mock, attrs=None): diff --git a/mox_test.py b/mox_test.py index bed58b9..6439060 100755 --- a/mox_test.py +++ b/mox_test.py @@ -1327,7 +1327,7 @@ class MoxTest(unittest.TestCase): def testCallOnNonCallableObject(self): """Test that you cannot call a non-callable object.""" - mock_obj = self.mox.CreateMock(TestClass) + mock_obj = self.mox.CreateMock("string is not callable") self.assertRaises(TypeError, mock_obj) def testCallableObjectWithBadCall(self): @@ -2229,7 +2229,7 @@ class MoxTestDontMockProperties(MoxTestBaseTest): mock_class.prop_attr) -class TestClass: +class TestClass(object): """This class is used only for testing the mock framework""" SOME_CLASS_VAR = "test_value" diff --git a/stubout.py b/stubout.py index 7175b52..d03c955 100644 --- a/stubout.py +++ b/stubout.py @@ -18,7 +18,7 @@ import inspect -class StubOutForTesting: +class StubOutForTesting(object): """Sample Usage: You want os.path.exists() to always return true during testing. -- cgit v1.2.1