Commits

Anonymous committed 376fac0

Arbitrary number of names support

Comments (0)

Files changed (2)

     return [name]
 
 
-def p(name, *args, **kw):
+def p(*args, **kw):
     """
     Acts like :func:``mock.patch``, but passes side-effects (patched mocks)
     into special dict-like ``se`` parameter.
     """
     def rv_decorator(fn):
-        patcher = patch(name, *args, **kw)
-        # add names to patcher
-        patcher.names = get_names(name)
         new_patchers = []
+        for name in args:
+            patcher = patch(name, **kw)
+            # add names to patcher
+            patcher.names = get_names(name)
+            new_patchers.append(patcher)
+
         if hasattr(fn, 'patchers'):
             new_patchers += fn.patchers
             del fn.patchers
-        new_patchers.append(patcher)
 
         @wraps(fn)
         def rv_fun(*args, **kw):
     - `**defaults`: default kw-args
     """
     @wraps(patcher)
-    def rv(name, *args, **kw):
+    def rv(*args, **kw):
         def_copy = defaults.copy()
         def_copy.update(kw)
-        return patcher(prefix + '.' + name, *args, **def_copy)
+        full_names = map(lambda name: prefix + '.' + name, args)
+        return patcher(*full_names, **def_copy)
     return rv
 
 
 
 
 class TestPatch(TestCase):
-    @p(__name__ + '.side_effect_one')
-    @p(__name__ + '.side_effect_two')
+    @p(__name__ + '.side_effect_one', __name__ + '.side_effect_two')
     def test_should_mock_to_kw(self, se):
         self.assertIsInstance(se.side_effect_one, MagicMock)
         self.assertIsInstance(se.side_effect_two, MagicMock)
     #     # self.assertIsInstance(m, M)
 
 
-@ppatch('side_effect_one')
-@ppatch('side_effect_two')
+@ppatch('side_effect_one', 'side_effect_two')
 class TestPatchClass(TestCase):
     def test_should_get_se(self, se):
         self.assertIsInstance(se.side_effect_one, MagicMock)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.