def on_userquit(self, server, nick, message): if len(message) > 0: message = ', saying: %s' % message else: message = '.' info(' ** %s disconnected from the server%s' % (nick.split('!')[0], message), server=server)
def read_or_default(config, section, key, default, manipulator=lambda val: val): """ Tries to read a certain key from a certain config section. If either section or key cannot be found, the provided default value is returned. Optionally, a multiplicator can be provided to manipulate the config value before returning. If this manipulator fails, the default value is returned. """ try: return manipulator(config.get(section, key)) except: info('Key ' + key + ' not found in config section ' + section + '.') return default
def run_tests(config, silent=False): """ Discovers plugins and runs their test cases. Returns success as boolean. Logs info to test.log with the configured loglevel. Requires a properly loaded ConfigParser object as parameter. """ info('Looking up test modules...', test=True) # Get test modules test_modules = [] # Contains tuple (module, pluginname) for plugin in discover_plugins(config): try: test_modules.append((getattr(getattr( __import__('plugins.%s.%s_test' % (plugin, plugin)), plugin), plugin + '_test'), plugin)) info('Loaded tests of plugin "%s".' % plugin, test=True) except ImportError: warning('Failed to load tests of plugin "%s". Do they exist?' % plugin, test=True) info('Running tests...', test=True) # Load suites and run tests test_runner = unittest.TextTestRunner() results = [test_runner.run(case) for case in [get_suite(entry[1], config, entry[0]) for entry in test_modules]] # Summarize results through reduction total = _reduce_test_results(results) info('%d errors, %d failures, %d skipped, %d expected failures, %d \ unexpected successes. %d of %d tests were successful.' % (total[0], total[1], total[2], total[3], total[4], total[5] - total[6], total[5]), test=True) if (total[6] < 1): # All tests successful print('\033[92m[=====SUCCESS===========================================\ =============]\033[0m') sys.exit(0) # Exit with success else: print('\033[91m[=====FAILURE===========================================\ =============]\033[0m') sys.exit(1) # Indicate test failure in exit value
def on_disconnect(self, server): info('Disconnected from the server.', server=server)
def on_connect(self, server): info('Connected to the server.', server=server)
def on_notice(self, server, channel, nick, message): if channel in self._restricted_channels: return info(' * NOTICE from ' + nick.split('!')[0] + ': ' + message, server=server)
def on_userrenamed(self, server, oldnick, newnick): info(' ** %s is now known as %s.' % (oldnick.split('!')[0], newnick), server=server)
def on_modechanged(self, server, channel, nick, message): if channel in self._restricted_channels: return info(' * MODE information: ' + message, server=server)
def on_motd(self, server, message): info(' * MOTD: %s' % message, server=server)
def on_quit(self): info('Terminating plugins.')