Commits

ebo committed 5d7fd50

qndispatch when method now accepts multiple targets as positional arguments

  • Participants
  • Parent commits c024faa

Comments (0)

Files changed (2)

File qndispatch/qndispatch.py

         def decorator(*args, **kw):
             return dispatcher.get(args, kw)(*args, **kw)
 
-        def when(arg):
+        def when(*args):
             def when_decorate(func):
-                dispatcher.register(func, arg)
+                for arg in args:
+                    dispatcher.register(func, arg)
                 return decorator
 
             return when_decorate

File qndispatch/test_qndispatch.py

         except qndispatch.DispatchTargetException:
             pass
 
+    def test_DoubleWhen(self):
+        class TestClass(object):
+            @qndispatch.on("name")
+            def test(self, name):
+                self.fail("Illegal call to dispatch.on function")
+                pass
+
+            @test.when(str, int)
+            def test(self, name):
+                pass
+        obj = TestClass()
+        obj.test(8)
+        obj.test("str")
+        try:
+            obj.test(9.0)
+            self.fail("Dispatch with unregistered type did not fail.")
+        except qndispatch.InvalidArgException:
+            pass
 
 if __name__ == "__main__":
     #import sys;sys.argv = ['', 'Test.testName']