diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | mocker.py | 11 | ||||
-rwxr-xr-x | test.py | 3 |
3 files changed, 16 insertions, 2 deletions
@@ -9,6 +9,10 @@ isn't called, and that may not be obvious, so a hook won't be exposed for now. +- When using an unexistent import path for Mocker.proxy(), raise an + ImportError on the base module, rather than using the actual + string as the object (#162315). + 0.8 (2007-11-11) ================ @@ -428,7 +428,10 @@ class MockerBase(object): is True), or explicitly (using the L{passthrough()} method on the event). - @param object: Real object to be proxied. + @param object: Real object to be proxied, and replaced by the mock + on replay mode. It may also be an "import path", + such as C{"time.time"}, in which case the object + will be the C{time} function from the C{time} module. @param spec: Method calls will be checked for correctness against the given object, which may be a class or an instance where attributes will be looked up. Defaults to the @@ -459,6 +462,8 @@ class MockerBase(object): object = __import__(module_path, {}, {}, [""]) except ImportError: attr_stack.insert(0, import_stack.pop()) + if not import_stack: + raise continue else: for attr in attr_stack: @@ -481,7 +486,9 @@ class MockerBase(object): namespaces, class namespaces, instance namespaces, and so on. @param object: Real object to be proxied, and replaced by the mock - on replay mode. + on replay mode. It may also be an "import path", + such as C{"time.time"}, in which case the object + will be the C{time} function from the C{time} module. @param spec: Method calls will be checked for correctness against the given object, which may be a class or an instance where attributes will be looked up. Defaults to the @@ -875,6 +875,9 @@ class MockerTest(unittest.TestCase): module = self.mocker.proxy("os.path", name="mock") self.assertEquals(module.__mocker_name__, "mock") + def test_proxy_with_unexistent_module(self): + self.assertRaises(ImportError, self.mocker.proxy, "unexistent.module") + def test_replace(self): from os import path obj = object() |