def test_getArgsBadListener(): pytest.raises(ListenerMismatchError, getArgs, 1) try: getArgs(1) except ListenerMismatchError: exc = sys.exc_info()[1] msg = 'Listener "int" (from module "__main__") inadequate: type "int" not supported' assert str(exc) == msg
def test_getArgsBadListener(): pytest.raises( ListenerMismatchError, getArgs, 1) try: getArgs(1) except ListenerMismatchError: exc = sys.exc_info()[1] msg = 'Listener "int" (from module "__main__") inadequate: type "int" not supported' assert str(exc) == msg
def test_WantTopic(): # Test the correct determination of whether want topic # auto-passed during sendMessage() calls. # first check proper breakdown of listener args: def listener(a, b=1): pass argsInfo = CallArgsInfo(listener) assert None == argsInfo.autoTopicArgName msgTopic = 'auto' class MyListener: def method(self, a, b=1, auto=Listener.AUTO_TOPIC): pass listener = MyListener() argsInfo = getArgs(listener.method) assert msgTopic == argsInfo.autoTopicArgName assert ('a','b') == argsInfo.allParams class MyFunctor: def __call__(self, a, b=1, auto=Listener.AUTO_TOPIC): pass listener = MyFunctor() argsInfo = getArgs(listener) assert msgTopic == argsInfo.autoTopicArgName assert ('a','b') == argsInfo.allParams # now some white box testing of validator that makes use of args info: def checkWantTopic(validate, listener, wantTopicAsArg=None): argsInfo = getArgs(listener) assert argsInfo.autoTopicArgName == wantTopicAsArg validate(listener) validator = ListenerValidator([], ['a']) validate = validator.validate def noWant(a=1): pass def want1(a=1, auto=Listener.AUTO_TOPIC): pass checkWantTopic(validate, noWant) checkWantTopic(validate, want1, msgTopic) validator = ListenerValidator(['a'], ['b']) validate = validator.validate def noWant2(a, b=1): pass def want2(a, auto=Listener.AUTO_TOPIC, b=1): pass checkWantTopic(validate, noWant2) checkWantTopic(validate, want2, msgTopic) # topic that has Listener.AUTO_TOPIC as an arg rather than kwarg validator = ListenerValidator([msgTopic], ['b']) validate = validator.validate def noWant3(auto, b=1): pass checkWantTopic(validate, noWant3)
def test4_WantTopic(): # Test the correct determination of whether want topic # auto-passed during sendMessage() calls. # first check proper breakdown of listener args: def listener(a, b=1): pass argsInfo = CallArgsInfo(listener, 0) assert None == argsInfo.autoTopicArgName msgTopic = 'auto' class MyListener: def method(self, a, b=1, auto=Listener.AUTO_TOPIC): pass listener = MyListener() argsInfo = getArgs(listener.method) assert msgTopic == argsInfo.autoTopicArgName assert ['a','b'] == argsInfo.allParams # now some white box testing of validator that makes use of args info: def checkWantTopic(validate, listener, wantTopicAsArg=None): argsInfo = getArgs(listener) assert argsInfo.autoTopicArgName == wantTopicAsArg validate(listener) validator = ListenerValidator([], ['a']) validate = validator.validate def noWant(a=1): pass def want1(a=1, auto=Listener.AUTO_TOPIC): pass checkWantTopic(validate, noWant) checkWantTopic(validate, want1, msgTopic) validator = ListenerValidator(['a'], ['b']) validate = validator.validate def noWant2(a, b=1): pass def want2(a, auto=Listener.AUTO_TOPIC, b=1): pass checkWantTopic(validate, noWant2) checkWantTopic(validate, want2, msgTopic) # topic that has Listener.AUTO_TOPIC as an arg rather than kwarg validator = ListenerValidator([msgTopic], ['b']) validate = validator.validate def noWant3(auto, b=1): pass checkWantTopic(validate, noWant3)
def checkWantTopic(validate, listener, wantTopicAsArg=None): argsInfo = getArgs(listener) assert argsInfo.autoTopicArgName == wantTopicAsArg validate(listener)