def run(): """Create the asyncio loop and start the server.""" args = parse_cmd_args(sys.argv[1:]) configure_logs(args) logger = logging.getLogger('blackhole') if args.test: config_test(args) try: config = Config(args.config_file).load().test() except ConfigException as err: logger.fatal(err) raise SystemExit(os.EX_USAGE) if args.background and not config.pidfile: logger.fatal('Cannot run in the background without a pidfile.') raise SystemExit(os.EX_USAGE) loop = asyncio.get_event_loop() loop.add_signal_handler(signal.SIGINT, loop.stop) start_servers() setgid() setuid() if args.background: try: Daemon(config.pidfile).daemonize() except DaemonException as err: stop_servers() logger.fatal(err) raise SystemExit(os.EX_USAGE) try: loop.run_forever() except KeyboardInterrupt: pass stop_servers() raise SystemExit(os.EX_OK)
def test_quiet(): args = Args((("debug", False), ("test", False), ("quiet", True))) logger = logging.getLogger("blackhole") configure_logs(args) assert logger.handlers[0].level is logging.ERROR
def test__test(): args = Args((('debug', False), ('test', True))) logger = logging.getLogger('blackhole') configure_logs(args) assert logger.handlers[0].level is logging.INFO