From 24d9d80b6d657011bd4ad7fb6ac6afd308df97bc Mon Sep 17 00:00:00 2001 From: gholt Date: Sat, 23 Jun 2012 02:30:30 +0000 Subject: [PATCH] Made compliant with PEP8 1.3.1 --- brim/http.py | 3 +- brim/httpform.py | 6 +- brim/server.py | 251 +++++----- brim/service.py | 6 +- brim/stats.py | 12 +- brim/test/unit/test_conf.py | 42 +- brim/test/unit/test_daemon_sample.py | 15 +- brim/test/unit/test_http.py | 24 +- brim/test/unit/test_log.py | 40 +- brim/test/unit/test_server.py | 697 ++++++++++++++++----------- brim/test/unit/test_service.py | 44 +- brim/test/unit/test_stats.py | 64 +-- brim/test/unit/test_tcp_echo.py | 4 +- brim/test/unit/test_udp_echo.py | 3 +- brim/test/unit/test_wsgi_echo.py | 23 +- 15 files changed, 714 insertions(+), 520 deletions(-) diff --git a/brim/http.py b/brim/http.py index 4268b8f..5ce3286 100644 --- a/brim/http.py +++ b/brim/http.py @@ -106,7 +106,8 @@ class HTTPException(Exception): """ def __init__(self, body=None, headers=None, code=500): - Exception.__init__(self, + Exception.__init__( + self, '%s %s %s' % (code, CODE2NAME.get(code, 'Status'), body or '-')) self.code = code self.body = body or '' diff --git a/brim/httpform.py b/brim/httpform.py index fccd1bb..cbd5ac8 100644 --- a/brim/httpform.py +++ b/brim/httpform.py @@ -269,13 +269,13 @@ def iter_form(env, read_chunk_size=4096): 'sig value', '------WebKitFormBoundaryNcxTqxSlX7t4TDkR', 'Content-Disposition: form-data; name="file1"; ' - 'filename="testfile1.txt"', + 'filename="testfile1.txt"', 'Content-Type: text/plain', '', 'Test File\nOne\n', '------WebKitFormBoundaryNcxTqxSlX7t4TDkR', 'Content-Disposition: form-data; name="file2"; ' - 'filename="testfile2.txt"', + 'filename="testfile2.txt"', 'Content-Type: text/plain', '', 'Test\nFile\nTwo\n', @@ -289,7 +289,7 @@ def iter_form(env, read_chunk_size=4096): ])) env = { 'CONTENT_TYPE': 'multipart/form-data; ' - 'boundary=----WebKitFormBoundaryNcxTqxSlX7t4TDkR', + 'boundary=----WebKitFormBoundaryNcxTqxSlX7t4TDkR', 'wsgi.input': wsgi_input } for message in iter_form(env): diff --git a/brim/server.py b/brim/server.py index 21d141b..0c95fd2 100644 --- a/brim/server.py +++ b/brim/server.py @@ -336,9 +336,11 @@ def _parse_conf(self, conf): :param conf: The brim.conf.Conf instance for the overall server configuration. """ - self.log_name = conf.get(self.name, 'log_name', + self.log_name = conf.get( + self.name, 'log_name', conf.get('brim', 'log_name', 'brim') + self.name) - self.log_level = conf.get(self.name, 'log_level', + self.log_level = conf.get( + self.name, 'log_level', conf.get('brim', 'log_level', 'INFO')).upper() try: import logging @@ -346,7 +348,8 @@ def _parse_conf(self, conf): except AttributeError: raise Exception( 'Invalid [%s] log_level %r.' % (self.name, self.log_level)) - self.log_facility = conf.get(self.name, 'log_facility', + self.log_facility = conf.get( + self.name, 'log_facility', conf.get('brim', 'log_facility', 'LOCAL0')).upper() if not self.log_facility.startswith('LOG_'): self.log_facility = 'LOG_' + self.log_facility @@ -356,7 +359,8 @@ def _parse_conf(self, conf): except AttributeError: raise Exception('Invalid [%s] log_facility %r.' % (self.name, self.log_facility)) - self.json_dumps = conf.get(self.name, 'json_dumps', + self.json_dumps = conf.get( + self.name, 'json_dumps', conf.get('brim', 'json_dumps', 'json.dumps')) try: mod, fnc = self.json_dumps.rsplit('.', 1) @@ -369,7 +373,8 @@ def _parse_conf(self, conf): raise Exception( 'Could not load function %r for [%s] json_dumps.' % (self.json_dumps, self.name)) - self.json_loads = conf.get(self.name, 'json_loads', + self.json_loads = conf.get( + self.name, 'json_loads', conf.get('brim', 'json_loads', 'json.loads')) try: mod, fnc = self.json_loads.rsplit('.', 1) @@ -418,28 +423,30 @@ def __init__(self, server, name): def _parse_conf(self, conf): Subserver._parse_conf(self, conf) self.ip = conf.get(self.name, 'ip', conf.get('brim', 'ip', '*')) - self.port = conf.get_int(self.name, 'port', - conf.get_int('brim', 'port', 80)) + self.port = \ + conf.get_int(self.name, 'port', conf.get_int('brim', 'port', 80)) if self.server.no_daemon: self.worker_count = 0 self.worker_names = ['0'] else: - self.worker_count = conf.get_int(self.name, 'workers', - conf.get_int('brim', 'workers', 1)) + self.worker_count = conf.get_int( + self.name, 'workers', conf.get_int('brim', 'workers', 1)) self.worker_names = \ [str(i) for i in xrange(self.worker_count or 1)] - self.certfile = conf.get(self.name, 'certfile', - conf.get('brim', 'certfile')) - self.keyfile = conf.get(self.name, 'keyfile', - conf.get('brim', 'keyfile')) - self.client_timeout = conf.get_int(self.name, 'client_timeout', + self.certfile = \ + conf.get(self.name, 'certfile', conf.get('brim', 'certfile')) + self.keyfile = \ + conf.get(self.name, 'keyfile', conf.get('brim', 'keyfile')) + self.client_timeout = conf.get_int( + self.name, 'client_timeout', conf.get_int('brim', 'client_timeout', 60)) - self.concurrent_per_worker = \ - conf.get_int(self.name, 'concurrent_per_worker', - conf.get_int('brim', 'concurrent_per_worker', 1024)) - self.backlog = conf.get_int(self.name, 'backlog', - conf.get_int('brim', 'backlog', 4096)) - self.listen_retry = conf.get_int(self.name, 'listen_retry', + self.concurrent_per_worker = conf.get_int( + self.name, 'concurrent_per_worker', + conf.get_int('brim', 'concurrent_per_worker', 1024)) + self.backlog = conf.get_int( + self.name, 'backlog', conf.get_int('brim', 'backlog', 4096)) + self.listen_retry = conf.get_int( + self.name, 'listen_retry', conf.get_int('brim', 'listen_retry', 30)) eventlet_hub = conf.get(self.name, 'eventlet_hub', conf.get('brim', 'eventlet_hub')) @@ -456,8 +463,9 @@ def _parse_conf(self, conf): self.eventlet_hub = __import__(eventlet_hub) except ImportError: try: - self.eventlet_hub = getattr(__import__('eventlet.hubs', - fromlist=[eventlet_hub]), eventlet_hub) + self.eventlet_hub = getattr( + __import__('eventlet.hubs', fromlist=[eventlet_hub]), + eventlet_hub) except (AttributeError, ImportError): pass if eventlet_hub and self.eventlet_hub is None: @@ -478,25 +486,28 @@ class WSGISubserver(IPSubserver): def __init__(self, server, name): IPSubserver.__init__(self, server, name) - self.stats_conf.update({'request_count': 'sum', - 'status_2xx_count': 'sum', 'status_3xx_count': 'sum', - 'status_4xx_count': 'sum', 'status_5xx_count': 'sum'}) + self.stats_conf.update({ + 'request_count': 'sum', 'status_2xx_count': 'sum', + 'status_3xx_count': 'sum', 'status_4xx_count': 'sum', + 'status_5xx_count': 'sum'}) def _parse_conf(self, conf): IPSubserver._parse_conf(self, conf) - self.log_headers = conf.get_bool(self.name, 'log_headers', + self.log_headers = conf.get_bool( + self.name, 'log_headers', conf.get_bool('brim', 'log_headers', False)) - self.count_status_codes = conf.get(self.name, 'count_status_codes', + self.count_status_codes = conf.get( + self.name, 'count_status_codes', conf.get('brim', 'count_status_codes', '404 408 499 501')) try: - self.count_status_codes = [int(c) for c in - self.count_status_codes.split()] + self.count_status_codes = \ + [int(c) for c in self.count_status_codes.split()] except ValueError: raise Exception('Invalid [%s] count_status_codes %r.' % (self.name, self.count_status_codes)) - self.wsgi_input_iter_chunk_size = \ - conf.get_int(self.name, 'wsgi_input_iter_chunk_size', - conf.get_int('brim', 'wsgi_input_iter_chunk_size', 4096)) + self.wsgi_input_iter_chunk_size = conf.get_int( + self.name, 'wsgi_input_iter_chunk_size', + conf.get_int('brim', 'wsgi_input_iter_chunk_size', 4096)) self.apps = [] app_names = conf.get(self.name, 'apps', '').strip().split() @@ -518,10 +529,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(app_class.__init__).args) if args != 4: - raise Exception('Would not be able to instantiate %r for ' - 'app [%s]. Incorrect number of args, %s, should be 4 ' - '(self, name, conf, next_app).' % - (call, app_name, args)) + raise Exception( + 'Would not be able to instantiate %r for app [%s]. ' + 'Incorrect number of args, %s, should be 4 (self, ' + 'name, conf, next_app).' % (call, app_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably not a class.' @@ -531,10 +542,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(app_class.__call__).args) if args != 3: - raise Exception('Would not be able to use %r for app ' - '[%s]. Incorrect number of __call__ args, %s, should ' - 'be 3 (self, env, start_response).' % - (call, app_name, args)) + raise Exception( + 'Would not be able to use %r for app [%s]. Incorrect ' + 'number of __call__ args, %s, should be 3 (self, env, ' + 'start_response).' % (call, app_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably no __call__ method.' @@ -545,10 +556,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(app_class.parse_conf).args) if args != 3: - raise Exception('Cannot use %r for app [%s]. ' - 'Incorrect number of parse_conf args, %s, should ' - 'be 3 (cls, name, conf).' % - (call, app_name, args)) + raise Exception( + 'Cannot use %r for app [%s]. Incorrect number of ' + 'parse_conf args, %s, should be 3 (cls, name, ' + 'conf).' % (call, app_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'parse_conf probably not a method.' @@ -561,10 +572,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(app_class.stats_conf).args) if args != 3: - raise Exception('Cannot use %r for app [%s]. ' - 'Incorrect number of stats_conf args, %s, should ' - 'be 3 (cls, name, conf).' % - (call, app_name, args)) + raise Exception( + 'Cannot use %r for app [%s]. Incorrect number of ' + 'stats_conf args, %s, should be 3 (cls, name, ' + 'conf).' % (call, app_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'stats_conf probably not a method.' @@ -577,9 +588,10 @@ def _parse_conf(self, conf): def _privileged_start(self): try: - self.sock = get_listening_tcp_socket(self.ip, self.port, - backlog=self.backlog, retry=self.listen_retry, - certfile=self.certfile, keyfile=self.keyfile, style='eventlet') + self.sock = get_listening_tcp_socket( + self.ip, self.port, backlog=self.backlog, + retry=self.listen_retry, certfile=self.certfile, + keyfile=self.keyfile, style='eventlet') except socket_error, err: raise Exception( 'Could not bind to %s:%s: %s' % (self.ip, self.port, err)) @@ -884,9 +896,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.__init__).args) if args != 3: - raise Exception('Would not be able to instantiate %r for ' - '[%s]. Incorrect number of args, %s, should be 3 (self, ' - 'name, parsed_conf).' % (call, self.name, args)) + raise Exception( + 'Would not be able to instantiate %r for [%s]. Incorrect ' + 'number of args, %s, should be 3 (self, name, ' + 'parsed_conf).' % (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably not a class.' @@ -896,10 +909,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.__call__).args) if args != 6: - raise Exception('Would not be able to use %r for [%s]. ' - 'Incorrect number of __call__ args, %s, should be 6 ' - '(self, subserver, stats, sock, ip, port).' % - (call, self.name, args)) + raise Exception( + 'Would not be able to use %r for [%s]. Incorrect number ' + 'of __call__ args, %s, should be 6 (self, subserver, ' + 'stats, sock, ip, port).' % (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably no __call__ method.' @@ -909,9 +922,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.parse_conf).args) if args != 3: - raise Exception('Cannot use %r for [%s]. Incorrect number ' - 'of parse_conf args, %s, should be 3 (cls, name, ' - 'conf).' % (call, self.name, args)) + raise Exception( + 'Cannot use %r for [%s]. Incorrect number of ' + 'parse_conf args, %s, should be 3 (cls, name, conf).' % + (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'parse_conf probably not a method.' @@ -924,9 +938,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.stats_conf).args) if args != 3: - raise Exception('Cannot use %r for [%s]. Incorrect number ' - 'of stats_conf args, %s, should be 3 (cls, name, ' - 'conf).' % (call, self.name, args)) + raise Exception( + 'Cannot use %r for [%s]. Incorrect number of ' + 'stats_conf args, %s, should be 3 (cls, name, conf).' % + (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'stats_conf probably not a method.' @@ -938,9 +953,10 @@ def _parse_conf(self, conf): def _privileged_start(self): try: - self.sock = get_listening_tcp_socket(self.ip, self.port, - backlog=self.backlog, retry=self.listen_retry, - certfile=self.certfile, keyfile=self.keyfile, style='eventlet') + self.sock = get_listening_tcp_socket( + self.ip, self.port, backlog=self.backlog, + retry=self.listen_retry, certfile=self.certfile, + keyfile=self.keyfile, style='eventlet') except socket_error, err: raise Exception( 'Could not bind to %s:%s: %s' % (self.ip, self.port, err)) @@ -1036,7 +1052,8 @@ def _parse_conf(self, conf): IPSubserver._parse_conf(self, conf) self.worker_count = 1 self.worker_names = ['0'] - self.max_datagram_size = conf.get_int(self.name, 'max_datagram_size', + self.max_datagram_size = conf.get_int( + self.name, 'max_datagram_size', conf.get_int('brim', 'max_datagram_size', 65536)) call = conf.get(self.name, 'call') if not call: @@ -1055,9 +1072,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.__init__).args) if args != 3: - raise Exception('Would not be able to instantiate %r for ' - '[%s]. Incorrect number of args, %s, should be 3 (self, ' - 'name, parsed_conf).' % (call, self.name, args)) + raise Exception( + 'Would not be able to instantiate %r for [%s]. Incorrect ' + 'number of args, %s, should be 3 (self, name, ' + 'parsed_conf).' % (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably not a class.' @@ -1067,9 +1085,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.__call__).args) if args != 7: - raise Exception('Would not be able to use %r for [%s]. ' - 'Incorrect number of __call__ args, %s, should be 7 ' - '(self, subserver, stats, sock, datagram, ip, port).' % + raise Exception( + 'Would not be able to use %r for [%s]. Incorrect number ' + 'of __call__ args, %s, should be 7 (self, subserver, ' + 'stats, sock, datagram, ip, port).' % (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': @@ -1080,14 +1099,15 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.parse_conf).args) if args != 3: - raise Exception('Cannot use %r for [%s]. Incorrect number ' - 'of parse_conf args, %s, should be 3 (cls, name, ' - 'conf).' % (call, self.name, args)) + raise Exception( + 'Cannot use %r for [%s]. Incorrect number of ' + 'parse_conf args, %s, should be 3 (cls, name, conf).' % + (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'parse_conf probably not a method.' - raise Exception('Cannot use %r for [%s]. %s' % - (call, self.name, err)) + raise Exception( + 'Cannot use %r for [%s]. %s' % (call, self.name, err)) self.handler_conf = self.handler.parse_conf(self.name, conf) else: self.handler_conf = conf @@ -1095,9 +1115,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(self.handler.stats_conf).args) if args != 3: - raise Exception('Cannot use %r for [%s]. Incorrect number ' - 'of stats_conf args, %s, should be 3 (cls, name, ' - 'conf).' % (call, self.name, args)) + raise Exception( + 'Cannot use %r for [%s]. Incorrect number of ' + 'stats_conf args, %s, should be 3 (cls, name, conf).' % + (call, self.name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'stats_conf probably not a method.' @@ -1109,8 +1130,8 @@ def _parse_conf(self, conf): def _privileged_start(self): try: - self.sock = get_listening_udp_socket(self.ip, self.port, - retry=self.listen_retry, style='eventlet') + self.sock = get_listening_udp_socket( + self.ip, self.port, retry=self.listen_retry, style='eventlet') except socket_error, err: raise Exception( 'Could not bind to %s:%s: %s' % (self.ip, self.port, err)) @@ -1209,9 +1230,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(daemon_class.__init__).args) if args != 3: - raise Exception('Would not be able to instantiate %r for ' - 'daemon [%s]. Incorrect number of args, %s, should be ' - '3 (self, name, conf).' % (call, daemon_name, args)) + raise Exception( + 'Would not be able to instantiate %r for daemon [%s]. ' + 'Incorrect number of args, %s, should be 3 (self, ' + 'name, conf).' % (call, daemon_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'Probably not a class.' @@ -1221,9 +1243,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(daemon_class.__call__).args) if args != 3: - raise Exception('Would not be able to use %r for daemon ' - '[%s]. Incorrect number of __call__ args, %s, should ' - 'be 3 (self, subserver, stats).' % + raise Exception( + 'Would not be able to use %r for daemon [%s]. ' + 'Incorrect number of __call__ args, %s, should be 3 ' + '(self, subserver, stats).' % (call, daemon_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': @@ -1235,10 +1258,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(daemon_class.parse_conf).args) if args != 3: - raise Exception('Cannot use %r for daemon [%s]. ' - 'Incorrect number of parse_conf args, %s, should ' - 'be 3 (cls, name, conf).' % - (call, daemon_name, args)) + raise Exception( + 'Cannot use %r for daemon [%s]. Incorrect number ' + 'of parse_conf args, %s, should be 3 (cls, name, ' + 'conf).' % (call, daemon_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'parse_conf probably not a method.' @@ -1251,10 +1274,10 @@ def _parse_conf(self, conf): try: args = len(getargspec(daemon_class.stats_conf).args) if args != 3: - raise Exception('Cannot use %r for daemon [%s]. ' - 'Incorrect number of stats_conf args, %s, should ' - 'be 3 (cls, name, conf).' % - (call, daemon_name, args)) + raise Exception( + 'Cannot use %r for daemon [%s]. Incorrect number ' + 'of stats_conf args, %s, should be 3 (cls, name, ' + 'conf).' % (call, daemon_name, args)) except TypeError, err: if str(err) == 'arg is not a Python function': err = 'stats_conf probably not a method.' @@ -1391,7 +1414,8 @@ def _parse_args(self): brim.conf.Conf instance if the server should be started. """ - parser = OptionParser(add_help_option=False, usage=""" + parser = OptionParser( + add_help_option=False, usage=""" Usage: %%prog [options] [command] Brim.Net Core Server %s @@ -1417,32 +1441,35 @@ def _parse_args(self): core apps will be started and no daemons. This can be useful for debugging. """.strip() % brim.version) - parser.add_option('-?', '-h', '--help', dest='help', - action='store_true', default=False, - help='Outputs this help information.') - parser.add_option('-c', '--conf', action='append', dest='conf_files', - metavar='PATH', + parser.add_option( + '-?', '-h', '--help', dest='help', action='store_true', + default=False, help='Outputs this help information.') + parser.add_option( + '-c', '--conf', action='append', dest='conf_files', metavar='PATH', help='By default, /etc/brimd.conf and ~/.brimd.conf are read for ' 'configuration. You may override this by specifying a ' 'specific conf file with -c. This option may be specified ' 'more than once and the conf files will each be read in ' 'order.') - parser.add_option('-p', '--pid-file', dest='pid_file', - default='/var/run/brimd.pid', metavar='PATH', + parser.add_option( + '-p', '--pid-file', dest='pid_file', default='/var/run/brimd.pid', + metavar='PATH', help='The path to the file to store the PID of the running main ' 'brimd process.') - parser.add_option('-o', '--output', dest='output', - action='store_true', default=False, + parser.add_option( + '-o', '--output', dest='output', action='store_true', + default=False, help='When running as a daemon brimd will normally close ' 'standard input, output, and error; this option will leave ' 'them open, which can be useful for debugging. Also, if ' 'brimd exits immediately with an error, the full stack trace ' 'will be output.') - parser.add_option('-v', '--version', dest='version', + parser.add_option( + '-v', '--version', dest='version', action='store_true', + default=False, help='Displays the version of brimd.') + parser.add_option( + '-x', '--error-stack-trace', dest='error_stack_trace', action='store_true', default=False, - help='Displays the version of brimd.') - parser.add_option('-x', '--error-stack-trace', - dest='error_stack_trace', action='store_true', default=False, help='Displays a full stack trace on a start up error.') def _parser_error(msg): diff --git a/brim/service.py b/brim/service.py index dd857f0..b457c62 100644 --- a/brim/service.py +++ b/brim/service.py @@ -397,9 +397,9 @@ def hup_signal(*args): worker_func(worker_id) except Exception, err: if logger: - logger.exception('wid:%03d ppid:%d pid:%d Worker ' - 'exited due to exception: %s' % - (worker_id, ppid, getpid(), err)) + logger.exception( + 'wid:%03d ppid:%d pid:%d Worker exited due to ' + 'exception: %s' % (worker_id, ppid, getpid(), err)) # Reraised in case of useful installed sys.excepthook. raise if logger: diff --git a/brim/stats.py b/brim/stats.py index 11ac249..b0c8e66 100644 --- a/brim/stats.py +++ b/brim/stats.py @@ -68,16 +68,20 @@ def __call__(self, env, start_response): else: for name, typ in stats.stats_conf.iteritems(): if typ == 'sum': - body[subserver.name][name] = sum(stats.get(i, name) + body[subserver.name][name] = sum( + stats.get(i, name) for i in xrange(stats.bucket_count)) elif typ == 'min': - body[subserver.name][name] = min(stats.get(i, name) + body[subserver.name][name] = min( + stats.get(i, name) for i in xrange(stats.bucket_count)) elif typ == 'max': - body[subserver.name][name] = max(stats.get(i, name) + body[subserver.name][name] = max( + stats.get(i, name) for i in xrange(stats.bucket_count)) for i in xrange(stats.bucket_count): - body[subserver.name].setdefault(stats.bucket_names[i], + body[subserver.name].setdefault( + stats.bucket_names[i], {})[name] = stats.get(i, name) body['start_time'] = server.start_time body = env['brim.json_dumps'](body) + '\n' diff --git a/brim/test/unit/test_conf.py b/brim/test/unit/test_conf.py index 3f469fb..0c41b4d 100644 --- a/brim/test/unit/test_conf.py +++ b/brim/test/unit/test_conf.py @@ -31,8 +31,8 @@ def test_false_values(self): [v.lower() for v in conf.FALSE_VALUES]) def test_true_false_values_distinct(self): - self.assertEquals(set(), - set(conf.TRUE_VALUES).intersection(set(conf.FALSE_VALUES))) + self.assertEquals( + set(), set(conf.TRUE_VALUES).intersection(set(conf.FALSE_VALUES))) def test_direct_store(self): d = {'s1': {'o1': '1.1', 'o2': '1.2'}, @@ -44,23 +44,23 @@ def test_files(self): self.assertEquals(f, conf.Conf({}, f).files) def test_get(self): - self.assertEquals('1.1', - conf.Conf({'s1': {'o1': '1.1'}}).get('s1', 'o1')) + self.assertEquals( + '1.1', conf.Conf({'s1': {'o1': '1.1'}}).get('s1', 'o1')) def test_get_default(self): self.assertEquals('d', conf.Conf({}).get('s1', 'o1', 'd')) def test_get_default_orig_is_none(self): - self.assertEquals('d', - conf.Conf({'s1': {'o1': None}}).get('s1', 'o1', 'd')) + self.assertEquals( + 'd', conf.Conf({'s1': {'o1': None}}).get('s1', 'o1', 'd')) def test_get_default_orig_is_empty(self): - self.assertEquals('d', - conf.Conf({'s1': {'o1': ''}}).get('s1', 'o1', 'd')) + self.assertEquals( + 'd', conf.Conf({'s1': {'o1': ''}}).get('s1', 'o1', 'd')) def test_get_default_orig_is_something(self): - self.assertEquals('s', - conf.Conf({'s1': {'o1': 's'}}).get('s1', 'o1', 'd')) + self.assertEquals( + 's', conf.Conf({'s1': {'o1': 's'}}).get('s1', 'o1', 'd')) def test_get_bool(self): self.assertTrue( @@ -88,10 +88,10 @@ def _exit(v): "be converted to boolean."]) def test_get_int(self): - self.assertEquals(1, - conf.Conf({'s1': {'o1': '1'}}).get_int('s1', 'o1', -2)) - self.assertEquals(-2, - conf.Conf({'s1': {'o1': '-2'}}).get_int('s1', 'o1', 1)) + self.assertEquals( + 1, conf.Conf({'s1': {'o1': '1'}}).get_int('s1', 'o1', -2)) + self.assertEquals( + -2, conf.Conf({'s1': {'o1': '-2'}}).get_int('s1', 'o1', 1)) def test_get_int_default(self): self.assertEquals(1, conf.Conf({}).get_int('s1', 'o1', 1)) @@ -108,14 +108,15 @@ def _exit(v): conf.Conf({'s1': {'o1': 'z'}}).get_int('s1', 'o1', 1) finally: conf.exit = orig_exit - self.assertEquals(calls, + self.assertEquals( + calls, ["Configuration value [s1] o1 of 'z' cannot be converted to int."]) def test_get_float(self): - self.assertEquals(1.1, - conf.Conf({'s1': {'o1': '1.1'}}).get_float('s1', 'o1', -2.3)) - self.assertEquals(-2.3, - conf.Conf({'s1': {'o1': '-2.3'}}).get_float('s1', 'o1', 1.1)) + self.assertEquals( + 1.1, conf.Conf({'s1': {'o1': '1.1'}}).get_float('s1', 'o1', -2.3)) + self.assertEquals( + -2.3, conf.Conf({'s1': {'o1': '-2.3'}}).get_float('s1', 'o1', 1.1)) def test_get_float_default(self): self.assertEquals(1.1, conf.Conf({}).get_float('s1', 'o1', 1.1)) @@ -239,7 +240,8 @@ def read(self, files): conf.SafeConfigParser = _SafeConfigParser c = conf.read_conf(['test1.conf', 'test2.conf'], exit_on_read_exception=False) - self.assertEquals(c.store, + self.assertEquals( + c.store, {'section1': {'default1': '1', 'option1': '1.1', 'option2': '1.2'}, 'section2': {'default1': '1', 'option1': '2.1', diff --git a/brim/test/unit/test_daemon_sample.py b/brim/test/unit/test_daemon_sample.py index 5e3ba58..b938ed3 100644 --- a/brim/test/unit/test_daemon_sample.py +++ b/brim/test/unit/test_daemon_sample.py @@ -85,7 +85,8 @@ def _time(): daemon_sample.time = orig_time self.assertEquals(str(exc), 'testexit') self.assertEquals(sleep_calls, [(60,)] * 3) - self.assertEquals(fake_server.logger.info_calls, + self.assertEquals( + fake_server.logger.info_calls, ['test sample daemon log line 1', 'test sample daemon log line 2', 'test sample daemon log line 3']) @@ -95,16 +96,16 @@ def _time(): def test_parse_conf(self): c = daemon_sample.DaemonSample.parse_conf('test', Conf({})) self.assertEquals(c, {'interval': 60}) - c = daemon_sample.DaemonSample.parse_conf('test', - Conf({'test': {'interval': 123}})) + c = daemon_sample.DaemonSample.parse_conf( + 'test', Conf({'test': {'interval': 123}})) self.assertEquals(c, {'interval': 123}) - c = daemon_sample.DaemonSample.parse_conf('test', - Conf({'test2': {'interval': 123}})) + c = daemon_sample.DaemonSample.parse_conf( + 'test', Conf({'test2': {'interval': 123}})) self.assertEquals(c, {'interval': 60}) def test_stats_conf(self): - self.assertEquals(daemon_sample.DaemonSample.stats_conf('test', - {'interval': 60}), ['iterations', 'last_run']) + self.assertEquals(daemon_sample.DaemonSample.stats_conf( + 'test', {'interval': 60}), ['iterations', 'last_run']) if __name__ == '__main__': diff --git a/brim/test/unit/test_http.py b/brim/test/unit/test_http.py index 6edfcde..cb9e7e4 100644 --- a/brim/test/unit/test_http.py +++ b/brim/test/unit/test_http.py @@ -62,8 +62,10 @@ def _start_response(*args): env = {'REQUEST_METHOD': 'GET'} body = http.HTTPException()(env, _start_response) - self.assertEquals(start_response_calls, [('500 Internal Server Error', - [('Content-Length', '0'), ('Content-Type', 'text/plain')])]) + self.assertEquals( + start_response_calls, + [('500 Internal Server Error', + [('Content-Length', '0'), ('Content-Type', 'text/plain')])]) self.assertEquals(''.join(body), '') def test_call_200(self): @@ -75,7 +77,8 @@ def _start_response(*args): env = {'REQUEST_METHOD': 'GET'} body = http.HTTPException(body='testvalue', code=200)(env, _start_response) - self.assertEquals(start_response_calls, + self.assertEquals( + start_response_calls, [('200 OK', [('Content-Length', '9'), ('Content-Type', 'text/plain')])]) self.assertEquals(''.join(body), 'testvalue') @@ -89,7 +92,8 @@ def _start_response(*args): env = {'REQUEST_METHOD': 'GET'} body = http.HTTPException(body='', code=200)(env, _start_response) - self.assertEquals(start_response_calls, + self.assertEquals( + start_response_calls, [('204 No Content', [('Content-Length', '0'), ('Content-Type', 'text/plain')])]) self.assertEquals(''.join(body), '') @@ -103,7 +107,8 @@ def _start_response(*args): env = {'REQUEST_METHOD': 'GET'} body = http.HTTPException(body='', headers={'content-length': 'abc'}, code=200)(env, _start_response) - self.assertEquals(start_response_calls, + self.assertEquals( + start_response_calls, [('200 OK', [('Content-Length', 'abc'), ('Content-Type', 'text/plain')])]) self.assertEquals(''.join(body), '') @@ -117,7 +122,8 @@ def _start_response(*args): env = {'REQUEST_METHOD': 'HEAD'} body = http.HTTPException(body='testvalue', code=200)(env, _start_response) - self.assertEquals(start_response_calls, + self.assertEquals( + start_response_calls, [('200 OK', [('Content-Length', '9'), ('Content-Type', 'text/plain')])]) self.assertEquals(''.join(body), '') @@ -127,7 +133,7 @@ class TestQueryParser(TestCase): def setUp(self): self.q = http.QueryParser( - 'empty1&empty2=&tp1=val1&tp2=val2a&tp2=val2b') + 'empty1&empty2=&tp1=val1&tp2=val2a&tp2=val2b') def test_init_empty_works(self): q = http.QueryParser() @@ -214,8 +220,8 @@ class TestGetHeaderInt(TestCase): def test_get_header_int(self): self.assertEquals(http.get_header_int({}, 'test-header', 123), 123) - self.assertEquals(http.get_header_int({'HTTP_TEST_HEADER': '123'}, - 'test-header'), 123) + self.assertEquals(http.get_header_int( + {'HTTP_TEST_HEADER': '123'}, 'test-header'), 123) self.assertRaises(http.HTTPBadRequest, http.get_header_int, {}, 'test-header') self.assertRaises(http.HTTPBadRequest, http.get_header_int, diff --git a/brim/test/unit/test_log.py b/brim/test/unit/test_log.py index 52d144e..9604bd1 100644 --- a/brim/test/unit/test_log.py +++ b/brim/test/unit/test_log.py @@ -42,8 +42,8 @@ class TestLogAdapter(TestCase): def test_process(self): a = log._LogAdapter(None, 'testserver') a.txn = 'abc' - self.assertEquals(a.process('test', {}), - ('test', {'extra': {'txn': 'abc', 'server': 'testserver'}})) + self.assertEquals(a.process('test', {}), ( + 'test', {'extra': {'txn': 'abc', 'server': 'testserver'}})) def test_effective_level(self): a = log._LogAdapter(FakeLogger(), 'testserver') @@ -53,28 +53,30 @@ def test_exception(self): logger = FakeLogger() a = log._LogAdapter(logger, 'testserver') a.exception('testexc') - self.assertEquals(logger.error_calls, - [(("testexc None ['None']",), - {'extra': {'txn': None, 'server': 'testserver'}})]) + self.assertEquals(logger.error_calls, [( + ("testexc None ['None']",), + {'extra': {'txn': None, 'server': 'testserver'}})]) try: raise Exception('blah') except Exception: a.exception('testexc2') self.assertEquals(len(logger.error_calls), 2) - self.assertEquals(logger.error_calls[-1][1], - {'extra': {'txn': None, 'server': 'testserver'}}) - self.assertTrue(logger.error_calls[-1][0][0].startswith('testexc2 ' - 'Exception: blah [\'Traceback (most recent call last):\', \' ' - 'File ')) - self.assertTrue(logger.error_calls[-1][0][0].endswith(', in ' - 'test_exception\', " raise Exception(\'blah\')", \'Exception: ' - 'blah\']')) + self.assertEquals( + logger.error_calls[-1][1], + {'extra': {'txn': None, 'server': 'testserver'}}) + self.assertTrue(logger.error_calls[-1][0][0].startswith( + 'testexc2 Exception: blah [\'Traceback (most recent call ' + 'last):\', \' File ')) + self.assertTrue(logger.error_calls[-1][0][0].endswith( + ', in test_exception\', " raise Exception(\'blah\')", ' + '\'Exception: blah\']')) def test_notice(self): logger = FakeLogger() a = log._LogAdapter(logger, 'testserver') a.notice('testnotice') - self.assertEquals(logger.log_calls, [(log.NOTICE, 'testnotice', (), + self.assertEquals(logger.log_calls, [( + log.NOTICE, 'testnotice', (), {'extra': {'txn': None, 'server': 'testserver'}})]) @@ -107,10 +109,12 @@ def test_sysloggable_excinfo(self): raise Exception('test') except: sei = log.sysloggable_excinfo() - self.assertTrue(sei.startswith('Exception: test [\'Traceback ' - '(most recent call last):\', \' File ')) - self.assertTrue(sei.endswith(', in test_sysloggable_excinfo\', ' - '" raise Exception(\'test\')", \'Exception: test\']')) + self.assertTrue(sei.startswith( + 'Exception: test [\'Traceback (most recent call last):\', \' ' + 'File ')) + self.assertTrue(sei.endswith( + ', in test_sysloggable_excinfo\', " raise ' + 'Exception(\'test\')", \'Exception: test\']')) try: raise KeyboardInterrupt() except KeyboardInterrupt: diff --git a/brim/test/unit/test_server.py b/brim/test/unit/test_server.py index 966a740..066df52 100644 --- a/brim/test/unit/test_server.py +++ b/brim/test/unit/test_server.py @@ -294,7 +294,8 @@ def test_kill_expect_exit_timeout(self): server._send_pid_sig('some.pid', 0, expect_exit=True) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), '12345 did not exit after %s seconds.' % server.PID_WAIT_TIME) self.assertEquals(self.time_calls, [()] * (server.PID_WAIT_TIME + 1)) self.assertEquals(self.sleep_calls, @@ -539,7 +540,8 @@ def test_parse_conf_json_dumps(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load function 'pickle.blah' for [test] json_dumps.") ss = self._class(FakeServer(), 'test') @@ -566,7 +568,8 @@ def test_parse_conf_json_dumps(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load function 'pickle.blah' for [test] json_dumps.") def test_parse_conf_json_loads(self): @@ -594,7 +597,8 @@ def test_parse_conf_json_loads(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load function 'pickle.blah' for [test] json_loads.") ss = self._class(FakeServer(), 'test') @@ -621,7 +625,8 @@ def test_parse_conf_json_loads(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load function 'pickle.blah' for [test] json_loads.") def test_privileged_start(self): @@ -764,8 +769,10 @@ def test_parse_conf_client_timeout(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "client_timeout of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] client_timeout of 'abc' cannot be " + "converted to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -781,8 +788,10 @@ def test_parse_conf_client_timeout(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "client_timeout of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] client_timeout of 'abc' cannot be " + "converted to int.") def test_parse_conf_concurrent_per_worker(self): ss = self._class(FakeServer(), 'test') @@ -799,8 +808,10 @@ def test_parse_conf_concurrent_per_worker(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "concurrent_per_worker of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] concurrent_per_worker of 'abc' cannot " + "be converted to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -816,8 +827,10 @@ def test_parse_conf_concurrent_per_worker(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "concurrent_per_worker of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] concurrent_per_worker of 'abc' cannot " + "be converted to int.") def test_parse_conf_backlog(self): ss = self._class(FakeServer(), 'test') @@ -869,8 +882,10 @@ def test_parse_conf_listen_retry(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "listen_retry of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] listen_retry of 'abc' cannot be " + "converted to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -886,8 +901,10 @@ def test_parse_conf_listen_retry(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "listen_retry of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] listen_retry of 'abc' cannot be " + "converted to int.") def test_parse_conf_eventlet_hub(self): ss = self._class(FakeServer(), 'test') @@ -916,8 +933,8 @@ def test_parse_conf_eventlet_hub(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), - "Could not load [test] eventlet_hub 'invalid'.") + self.assertEquals( + str(exc), "Could not load [test] eventlet_hub 'invalid'.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -927,8 +944,8 @@ def test_parse_conf_eventlet_hub(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), - "Could not load [test] eventlet_hub 'invalid.module'.") + self.assertEquals( + str(exc), "Could not load [test] eventlet_hub 'invalid.module'.") def test_parse_conf_workers(self): ss = self._class(FakeServer(), 'test') @@ -963,8 +980,10 @@ def test_parse_conf_workers(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] workers of " - "'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] workers of 'abc' cannot be converted " + "to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -998,8 +1017,10 @@ def test_parse_conf_workers(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] workers of " - "'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] workers of 'abc' cannot be converted " + "to int.") class AppWithInvalidInit(object): @@ -1181,8 +1202,10 @@ def test_parse_conf_log_headers(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "log_headers of 'abc' cannot be converted to boolean.") + self.assertEquals( + str(exc), + "Configuration value [brim] log_headers of 'abc' cannot be " + "converted to boolean.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -1198,8 +1221,10 @@ def test_parse_conf_log_headers(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "log_headers of 'abc' cannot be converted to boolean.") + self.assertEquals( + str(exc), + "Configuration value [test] log_headers of 'abc' cannot be " + "converted to boolean.") def test_parse_conf_count_status_codes(self): ss = self._class(FakeServer(), 'test') @@ -1257,8 +1282,10 @@ def test_parse_conf_wsgi_input_iter_chunk_size(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "wsgi_input_iter_chunk_size of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] wsgi_input_iter_chunk_size of 'abc' " + "cannot be converted to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -1274,8 +1301,10 @@ def test_parse_conf_wsgi_input_iter_chunk_size(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "wsgi_input_iter_chunk_size of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] wsgi_input_iter_chunk_size of 'abc' " + "cannot be converted to int.") def test_configure_wsgi_apps(self): ss = self._class(FakeServer(), 'test') @@ -1316,8 +1345,9 @@ def test_configure_wsgi_apps_conf_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Invalid call value " - "'brim_wsgi_echo_WSGIEcho' for app [one].") + self.assertEquals( + str(exc), + "Invalid call value 'brim_wsgi_echo_WSGIEcho' for app [one].") def test_configure_wsgi_apps_no_load(self): ss = self._class(FakeServer(), 'test') @@ -1329,8 +1359,9 @@ def test_configure_wsgi_apps_no_load(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Could not load class " - "'brim.wsgi_echo.sgi_cho' for app [one].") + self.assertEquals( + str(exc), + "Could not load class 'brim.wsgi_echo.sgi_cho' for app [one].") def test_configure_wsgi_apps_not_a_class(self): ss = self._class(FakeServer(), 'test') @@ -1342,9 +1373,10 @@ def test_configure_wsgi_apps_not_a_class(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " - "'brim.server._send_pid_sig' for app [one]. Probably not a " - "class.") + self.assertEquals( + str(exc), + "Would not be able to instantiate 'brim.server._send_pid_sig' for " + "app [one]. Probably not a class.") def test_configure_wsgi_apps_invalid_init(self): ss = self._class(FakeServer(), 'test') @@ -1357,7 +1389,9 @@ def test_configure_wsgi_apps_invalid_init(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " + self.assertEquals( + str(exc), + "Would not be able to instantiate " "'brim.test.unit.test_server.AppWithInvalidInit' for app " "[one]. Incorrect number of args, 1, should be 4 (self, name, " "conf, next_app).") @@ -1373,7 +1407,9 @@ def test_configure_wsgi_apps_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.AppWithInvalidCall' for app " "[one]. Incorrect number of __call__ args, 1, should be 3 (self, " "env, start_response).") @@ -1389,7 +1425,9 @@ def test_configure_wsgi_apps_no_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.AppWithNoCall' for app " "[one]. Probably no __call__ method.") @@ -1404,9 +1442,10 @@ def test_configure_wsgi_apps_invalid_parse_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.AppWithInvalidParseConf1' for " - "app [one]. Incorrect number of parse_conf args, 1, should be " + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.AppWithInvalidParseConf1' " + "for app [one]. Incorrect number of parse_conf args, 1, should be " "3 (cls, name, conf).") def test_configure_wsgi_apps_invalid_parse_conf2(self): @@ -1420,9 +1459,10 @@ def test_configure_wsgi_apps_invalid_parse_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.AppWithInvalidParseConf2' for " - "app [one]. parse_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.AppWithInvalidParseConf2' " + "for app [one]. parse_conf probably not a method.") def test_configure_wsgi_apps_no_parse_conf(self): ss = self._class(FakeServer(), 'test') @@ -1454,10 +1494,11 @@ def test_configure_wsgi_apps_invalid_stats_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.AppWithInvalidStatsConf1' for " - "app [one]. Incorrect number of stats_conf args, 1, should be 3 " - "(cls, name, conf).") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.AppWithInvalidStatsConf1' " + "for app [one]. Incorrect number of stats_conf args, 1, should be " + "3 (cls, name, conf).") def test_configure_wsgi_apps_invalid_stats_conf2(self): ss = self._class(FakeServer(), 'test') @@ -1470,9 +1511,10 @@ def test_configure_wsgi_apps_invalid_stats_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.AppWithInvalidStatsConf2' for " - "app [one]. stats_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.AppWithInvalidStatsConf2' " + "for app [one]. stats_conf probably not a method.") def test_configure_wsgi_apps_no_stats_conf(self): ss = self._class(FakeServer(), 'test') @@ -1511,8 +1553,8 @@ def test_privileged_start(self): ss._privileged_start() except Exception, err: exc = err - self.assertEquals(str(exc), - 'Could not bind to *:80: [Errno 13] Permission denied') + self.assertEquals( + str(exc), 'Could not bind to *:80: [Errno 13] Permission denied') ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -1595,13 +1637,15 @@ def _shutdown_safe(*args): if output: self.assertEquals(capture_exceptions_stdout_stderr_calls, []) else: - self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), + self.assertEquals(capture_exceptions_stdout_stderr_calls, [( + (), {'exceptions': ss._capture_exception, 'stdout_func': ss._capture_stdout, 'stderr_func': ss._capture_stderr})]) self.assertEquals(time_calls, [()]) - self.assertEquals(get_logger_calls, [(ss.name, ss.log_name, - ss.log_level, ss.log_facility, ss.server.no_daemon)]) + self.assertEquals(get_logger_calls, [( + ss.name, ss.log_name, ss.log_level, ss.log_facility, + ss.server.no_daemon)]) self.assertEquals(sustain_workers_calls, [((1, ss._wsgi_worker), {'logger': fake_logger})]) self.assertEquals(shutdown_safe_calls, [(ss.sock,)]) @@ -1610,7 +1654,8 @@ def _shutdown_safe(*args): self.assertEquals(ss.logger, fake_logger) for code in ss.count_status_codes: key = 'status_%d_count' % code - self.assertEquals(ss.stats_conf.get(key), 'sum', + self.assertEquals( + ss.stats_conf.get(key), 'sum', 'key %r value %r != %r' % (key, ss.stats_conf.get(key), 'sum')) self.assertEquals(fake_wsgi.HttpProtocol.default_request_version, 'HTTP/1.0') @@ -1843,12 +1888,14 @@ def _app_with_body_exception(env, start_response): self.assertEquals(env.get('brim.json_loads'), ss.json_loads) if raises: if raises == 'start': - self.assertEquals(env.get('brim._start_response'), + self.assertEquals( + env.get('brim._start_response'), ('500 Internal Server Error', [('Content-Length', '0')], None)) self.assertEquals(content, '') else: - self.assertEquals(env.get('brim._start_response'), + self.assertEquals( + env.get('brim._start_response'), ('200 OK', [('Content-Length', '10')], None)) self.assertEquals(content, 'partial') self.assertEquals(ss.logger.debug_calls, []) @@ -1867,7 +1914,8 @@ def _app_with_body_exception(env, start_response): self.assertEquals(str(ss.logger.exception_calls[0][1][1]), 'body exception') elif with_app: - self.assertEquals(env.get('brim._start_response'), + self.assertEquals( + env.get('brim._start_response'), ('200 OK', [('Content-Length', '10')], None)) self.assertEquals(content, 'test value') self.assertEquals(ss.logger.debug_calls, []) @@ -1876,7 +1924,8 @@ def _app_with_body_exception(env, start_response): self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) else: - self.assertEquals(env.get('brim._start_response'), + self.assertEquals( + env.get('brim._start_response'), ('404 Not Found', [('Content-Length', '0')], None)) self.assertEquals(content, '') self.assertEquals(ss.logger.debug_calls, []) @@ -1896,15 +1945,16 @@ def test_wsgi_entry_raises_body_exception(self): self.test_wsgi_entry(raises='body') def _log_request_build(self, start=1330037777.77): - return {'REQUEST_METHOD': 'GET', - 'PATH_INFO': '/path', - 'SERVER_PROTOCOL': 'HTTP/1.1', - 'brim.start': start, - 'brim.txn': 'abcdef', - 'brim._start_response': - ('200 OK', [('Content-Length', '10')], None), - 'brim._bytes_in': 0, - 'brim._bytes_out': 10} + return { + 'REQUEST_METHOD': 'GET', + 'PATH_INFO': '/path', + 'SERVER_PROTOCOL': 'HTTP/1.1', + 'brim.start': start, + 'brim.txn': 'abcdef', + 'brim._start_response': ( + '200 OK', [('Content-Length', '10')], None), + 'brim._bytes_in': 0, + 'brim._bytes_out': 10} def _log_request_execute(self, env, end=1330037779.89, log_headers=False): ss = self._class(FakeServer(output=True), 'test') @@ -1950,8 +2000,9 @@ def test_log_request_no_start_response(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 499 - - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 499 - - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -1968,8 +2019,9 @@ def test_log_request_minimal(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -1988,8 +2040,9 @@ def test_log_request_3xx(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 301 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 301 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2008,8 +2061,9 @@ def test_log_request_4xx(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 404 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 404 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2028,8 +2082,9 @@ def test_log_request_5xx(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 1) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 503 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 503 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2071,8 +2126,9 @@ def test_log_request_path_quoted_requoted(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path%20/test HTTP/1.1 200 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path%20/test HTTP/1.1 200 10 - - - ' + 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2090,9 +2146,9 @@ def test_log_request_query(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path?param1=value1%20value2¶m2 HTTP/1.1 200 10 - - - ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path?param1=value1%20value2¶m2 ' + 'HTTP/1.1 200 10 - - - abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2110,8 +2166,8 @@ def test_log_request_cluster_client(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.4 - - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.4 - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -2130,8 +2186,8 @@ def test_log_request_forwarded_for(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.4 - - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.4 - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -2151,8 +2207,8 @@ def test_log_request_cluster_client_forwarded_for(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.4 - - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.4 - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -2171,9 +2227,9 @@ def test_log_request_remote_addr(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.4 1.2.3.4 - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.4 1.2.3.4 - - 20120223T225619Z GET /path HTTP/1.1 200 10 - ' + '- - abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2192,9 +2248,9 @@ def test_log_request_remote_addr_cluster_client(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.5 1.2.3.4 - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.5 1.2.3.4 - - 20120223T225619Z GET /path HTTP/1.1 200 10 - ' + '- - abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2213,9 +2269,9 @@ def test_log_request_remote_addr_forwarded_for(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.5 1.2.3.4 - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.5 1.2.3.4 - - 20120223T225619Z GET /path HTTP/1.1 200 10 - ' + '- - abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2235,9 +2291,9 @@ def test_log_request_remote_addr_cluster_client_forwarded_for(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('1.2.3.5 1.2.3.4 - - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '1.2.3.5 1.2.3.4 - - 20120223T225619Z GET /path HTTP/1.1 200 10 - ' + '- - abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2256,8 +2312,9 @@ def test_log_request_headers(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - - - abcdef 2.12000 headers: ' + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - abcdef ' + '2.12000 headers: ' 'X-Test:test%20value%0AContent-Type:text/plain',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -2276,8 +2333,9 @@ def test_log_request_client_disconnect(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 499 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 499 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2296,8 +2354,9 @@ def test_log_request_goofy_code(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 - 10 - - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 - 10 - - - abcdef ' + '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2315,9 +2374,9 @@ def test_log_auth_token(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - authtoken - ' - '20120223T225619Z GET /path HTTP/1.1 200 10 - - - abcdef ' - '2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - authtoken - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - ' + 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2335,8 +2394,9 @@ def test_log_bytes_in(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 123 - - abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 123 - - ' + 'abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2354,8 +2414,8 @@ def test_log_request_referer(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - ' + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - ' 'http://some.host/path%2520/test?maybe=query+value - abcdef ' '2.12000',)]) self.assertEquals(ss.logger.error_calls, []) @@ -2375,9 +2435,9 @@ def test_log_request_user_agent(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - - Some%20User%20Agent%20(v1.0) ' - 'abcdef 2.12000',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - ' + 'Some%20User%20Agent%20(v1.0) abcdef 2.12000',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2395,8 +2455,9 @@ def test_log_request_additional_info(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - - - abcdef 2.12000 test: one two',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - abcdef ' + '2.12000 test: one two',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2415,9 +2476,9 @@ def test_log_request_additional_info_and_headers(self): self.assertEquals(ss.bucket_stats.get(0, 'status_5xx_count'), 0) self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) - self.assertEquals(ss.logger.notice_calls, [('- - - - 20120223T225619Z ' - 'GET /path HTTP/1.1 200 10 - - - abcdef 2.12000 test: one two ' - 'headers: Content-Type:text/plain',)]) + self.assertEquals(ss.logger.notice_calls, [( + '- - - - 20120223T225619Z GET /path HTTP/1.1 200 10 - - - abcdef ' + '2.12000 test: one two headers: Content-Type:text/plain',)]) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) self.assertEquals(ss.logger.txn, None) @@ -2445,10 +2506,11 @@ def test_capture_exception(self): self.assertEquals(len(ss.logger.error_calls), 1) self.assertEquals(len(ss.logger.error_calls[0]), 1) e = ss.logger.error_calls[0][0] - self.assertTrue(e.startswith("UNCAUGHT EXCEPTION: wid:123 Exception: " - "test ['Traceback (most recent call last):', ' File ")) - self.assertTrue(e.endswith('\', " raise Exception(\'test\')", ' - '\'Exception: test\']')) + self.assertTrue(e.startswith( + "UNCAUGHT EXCEPTION: wid:123 Exception: test ['Traceback (most " + "recent call last):', ' File ")) + self.assertTrue(e.endswith( + '\', " raise Exception(\'test\')", \'Exception: test\']')) self.assertEquals(ss.logger.exception_calls, []) def test_capture_stdout(self): @@ -2457,8 +2519,9 @@ def test_capture_stdout(self): ss.worker_id = 123 ss._capture_stdout('one\ntwo three\nfour\n') self.assertEquals(ss.logger.debug_calls, []) - self.assertEquals(ss.logger.info_calls, [('STDOUT: wid:123 one',), - ('STDOUT: wid:123 two three',), ('STDOUT: wid:123 four',)]) + self.assertEquals(ss.logger.info_calls, [ + ('STDOUT: wid:123 one',), ('STDOUT: wid:123 two three',), + ('STDOUT: wid:123 four',)]) self.assertEquals(ss.logger.notice_calls, []) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -2471,8 +2534,9 @@ def test_capture_stderr(self): self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) self.assertEquals(ss.logger.notice_calls, []) - self.assertEquals(ss.logger.error_calls, [('STDERR: wid:123 one',), - ('STDERR: wid:123 two three',), ('STDERR: wid:123 four',)]) + self.assertEquals(ss.logger.error_calls, [ + ('STDERR: wid:123 one',), ('STDERR: wid:123 two three',), + ('STDERR: wid:123 four',)]) self.assertEquals(ss.logger.exception_calls, []) @@ -2654,8 +2718,8 @@ def test_configure_handler_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), - "Invalid call value 'brim_tcp_echo_TCPEcho' for [test].") + self.assertEquals( + str(exc), "Invalid call value 'brim_tcp_echo_TCPEcho' for [test].") def test_configure_handler_no_load(self): ss = self._class(FakeServer(), 'test') @@ -2666,7 +2730,8 @@ def test_configure_handler_no_load(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load class 'brim.tcp_echo.cp_echo' for [test].") def test_configure_handler_not_a_class(self): @@ -2678,8 +2743,10 @@ def test_configure_handler_not_a_class(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " - "'brim.server._send_pid_sig' for [test]. Probably not a class.") + self.assertEquals( + str(exc), + "Would not be able to instantiate 'brim.server._send_pid_sig' for " + "[test]. Probably not a class.") def test_configure_handler_invalid_init(self): ss = self._class(FakeServer(), 'test') @@ -2690,7 +2757,9 @@ def test_configure_handler_invalid_init(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " + self.assertEquals( + str(exc), + "Would not be able to instantiate " "'brim.test.unit.test_server.TCPWithInvalidInit' for [test]. " "Incorrect number of args, 1, should be 3 (self, name, " "parsed_conf).") @@ -2704,7 +2773,9 @@ def test_configure_handler_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.TCPWithInvalidCall' for [test]. " "Incorrect number of __call__ args, 1, should be 6 (self, " "subserver, stats, sock, ip, port).") @@ -2718,7 +2789,9 @@ def test_configure_handler_no_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.TCPWithNoCall' for [test]. Probably " "no __call__ method.") @@ -2732,9 +2805,10 @@ def test_configure_handler_invalid_parse_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.TCPWithInvalidParseConf1' for " - "[test]. Incorrect number of parse_conf args, 1, should be 3 " + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.TCPWithInvalidParseConf1' " + "for [test]. Incorrect number of parse_conf args, 1, should be 3 " "(cls, name, conf).") def test_configure_handler_invalid_parse_conf2(self): @@ -2747,9 +2821,10 @@ def test_configure_handler_invalid_parse_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.TCPWithInvalidParseConf2' for " - "[test]. parse_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.TCPWithInvalidParseConf2' " + "for [test]. parse_conf probably not a method.") def test_configure_handler_no_parse_conf(self): ss = self._class(FakeServer(), 'test') @@ -2776,9 +2851,10 @@ def test_configure_handler_invalid_stats_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.TCPWithInvalidStatsConf1' for " - "[test]. Incorrect number of stats_conf args, 1, should be 3 " + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.TCPWithInvalidStatsConf1' " + "for [test]. Incorrect number of stats_conf args, 1, should be 3 " "(cls, name, conf).") def test_configure_handler_invalid_stats_conf2(self): @@ -2791,9 +2867,10 @@ def test_configure_handler_invalid_stats_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.TCPWithInvalidStatsConf2' for " - "[test]. stats_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.TCPWithInvalidStatsConf2' " + "for [test]. stats_conf probably not a method.") def test_configure_handler_no_stats_conf(self): ss = self._class(FakeServer(), 'test') @@ -2820,8 +2897,8 @@ def test_privileged_start(self): ss._privileged_start() except Exception, err: exc = err - self.assertEquals(str(exc), - 'Could not bind to *:80: [Errno 13] Permission denied') + self.assertEquals( + str(exc), 'Could not bind to *:80: [Errno 13] Permission denied') ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -2899,13 +2976,15 @@ def _shutdown_safe(*args): if output: self.assertEquals(capture_exceptions_stdout_stderr_calls, []) else: - self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), + self.assertEquals(capture_exceptions_stdout_stderr_calls, [( + (), {'exceptions': ss._capture_exception, 'stdout_func': ss._capture_stdout, 'stderr_func': ss._capture_stderr})]) self.assertEquals(time_calls, [()]) - self.assertEquals(get_logger_calls, [(ss.name, ss.log_name, - ss.log_level, ss.log_facility, ss.server.no_daemon)]) + self.assertEquals(get_logger_calls, [( + ss.name, ss.log_name, ss.log_level, ss.log_facility, + ss.server.no_daemon)]) self.assertEquals(sustain_workers_calls, [((1, ss._tcp_worker), {'logger': fake_logger})]) self.assertEquals(shutdown_safe_calls, [(ss.sock,)]) @@ -3004,8 +3083,8 @@ def _time(): else: self.assertEquals(use_hub_calls, [(None,)]) self.assertEquals(ss.handler.__class__.__name__, 'TCPEcho') - self.assertEquals(GreenPool_calls, - [((), {'size': ss.concurrent_per_worker})]) + self.assertEquals( + GreenPool_calls, [((), {'size': ss.concurrent_per_worker})]) self.assertEquals(len(spawn_n_calls), 1) self.assertEquals(len(spawn_n_calls[0]), 6) self.assertEquals(spawn_n_calls[0][0].__class__.__name__, 'TCPEcho') @@ -3065,10 +3144,11 @@ def test_capture_exception(self): self.assertEquals(len(ss.logger.error_calls), 1) self.assertEquals(len(ss.logger.error_calls[0]), 1) e = ss.logger.error_calls[0][0] - self.assertTrue(e.startswith("UNCAUGHT EXCEPTION: tid:123 Exception: " - "test ['Traceback (most recent call last):', ' File ")) - self.assertTrue(e.endswith('\', " raise Exception(\'test\')", ' - '\'Exception: test\']')) + self.assertTrue(e.startswith( + "UNCAUGHT EXCEPTION: tid:123 Exception: test ['Traceback (most " + "recent call last):', ' File ")) + self.assertTrue(e.endswith( + '\', " raise Exception(\'test\')", \'Exception: test\']')) self.assertEquals(ss.logger.exception_calls, []) def test_capture_stdout(self): @@ -3077,8 +3157,9 @@ def test_capture_stdout(self): ss.worker_id = 123 ss._capture_stdout('one\ntwo three\nfour\n') self.assertEquals(ss.logger.debug_calls, []) - self.assertEquals(ss.logger.info_calls, [('STDOUT: tid:123 one',), - ('STDOUT: tid:123 two three',), ('STDOUT: tid:123 four',)]) + self.assertEquals(ss.logger.info_calls, [ + ('STDOUT: tid:123 one',), ('STDOUT: tid:123 two three',), + ('STDOUT: tid:123 four',)]) self.assertEquals(ss.logger.notice_calls, []) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -3091,8 +3172,9 @@ def test_capture_stderr(self): self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) self.assertEquals(ss.logger.notice_calls, []) - self.assertEquals(ss.logger.error_calls, [('STDERR: tid:123 one',), - ('STDERR: tid:123 two three',), ('STDERR: tid:123 four',)]) + self.assertEquals(ss.logger.error_calls, [ + ('STDERR: tid:123 one',), ('STDERR: tid:123 two three',), + ('STDERR: tid:123 four',)]) self.assertEquals(ss.logger.exception_calls, []) @@ -3241,8 +3323,10 @@ def test_parse_conf_max_datagram_size(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [brim] " - "max_datagram_size of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [brim] max_datagram_size of 'abc' cannot be " + "converted to int.") ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -3258,8 +3342,10 @@ def test_parse_conf_max_datagram_size(self): ss._parse_conf(Conf(confd)) except SystemExit, err: exc = err - self.assertEquals(str(exc), "Configuration value [test] " - "max_datagram_size of 'abc' cannot be converted to int.") + self.assertEquals( + str(exc), + "Configuration value [test] max_datagram_size of 'abc' cannot be " + "converted to int.") def test_parse_conf_no_call(self): ss = self._class(FakeServer(), 'test') @@ -3311,8 +3397,8 @@ def test_configure_handler_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), - "Invalid call value 'brim_udp_echo_UDPEcho' for [test].") + self.assertEquals( + str(exc), "Invalid call value 'brim_udp_echo_UDPEcho' for [test].") def test_configure_handler_no_load(self): ss = self._class(FakeServer(), 'test') @@ -3323,7 +3409,8 @@ def test_configure_handler_no_load(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), "Could not load class 'brim.udp_echo.cp_echo' for [test].") def test_configure_handler_not_a_class(self): @@ -3335,8 +3422,10 @@ def test_configure_handler_not_a_class(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " - "'brim.server._send_pid_sig' for [test]. Probably not a class.") + self.assertEquals( + str(exc), + "Would not be able to instantiate 'brim.server._send_pid_sig' for " + "[test]. Probably not a class.") def test_configure_handler_invalid_init(self): ss = self._class(FakeServer(), 'test') @@ -3347,7 +3436,9 @@ def test_configure_handler_invalid_init(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " + self.assertEquals( + str(exc), + "Would not be able to instantiate " "'brim.test.unit.test_server.UDPWithInvalidInit' for [test]. " "Incorrect number of args, 1, should be 3 (self, name, " "parsed_conf).") @@ -3361,7 +3452,9 @@ def test_configure_handler_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.UDPWithInvalidCall' for [test]. " "Incorrect number of __call__ args, 1, should be 7 (self, " "subserver, stats, sock, datagram, ip, port).") @@ -3375,7 +3468,9 @@ def test_configure_handler_no_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.UDPWithNoCall' for [test]. Probably " "no __call__ method.") @@ -3389,9 +3484,10 @@ def test_configure_handler_invalid_parse_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.UDPWithInvalidParseConf1' for " - "[test]. Incorrect number of parse_conf args, 1, should be 3 " + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.UDPWithInvalidParseConf1' " + "for [test]. Incorrect number of parse_conf args, 1, should be 3 " "(cls, name, conf).") def test_configure_handler_invalid_parse_conf2(self): @@ -3404,9 +3500,10 @@ def test_configure_handler_invalid_parse_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.UDPWithInvalidParseConf2' for " - "[test]. parse_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.UDPWithInvalidParseConf2' " + "for [test]. parse_conf probably not a method.") def test_configure_handler_no_parse_conf(self): ss = self._class(FakeServer(), 'test') @@ -3433,9 +3530,10 @@ def test_configure_handler_invalid_stats_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.UDPWithInvalidStatsConf1' for " - "[test]. Incorrect number of stats_conf args, 1, should be 3 " + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.UDPWithInvalidStatsConf1' " + "for [test]. Incorrect number of stats_conf args, 1, should be 3 " "(cls, name, conf).") def test_configure_handler_invalid_stats_conf2(self): @@ -3448,9 +3546,10 @@ def test_configure_handler_invalid_stats_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " - "'brim.test.unit.test_server.UDPWithInvalidStatsConf2' for " - "[test]. stats_conf probably not a method.") + self.assertEquals( + str(exc), + "Cannot use 'brim.test.unit.test_server.UDPWithInvalidStatsConf2' " + "for [test]. stats_conf probably not a method.") def test_configure_handler_no_stats_conf(self): ss = self._class(FakeServer(), 'test') @@ -3477,8 +3576,8 @@ def test_privileged_start(self): ss._privileged_start() except Exception, err: exc = err - self.assertEquals(str(exc), - 'Could not bind to *:80: [Errno 13] Permission denied') + self.assertEquals( + str(exc), 'Could not bind to *:80: [Errno 13] Permission denied') ss = self._class(FakeServer(), 'test') confd = self._get_default_confd() @@ -3592,14 +3691,15 @@ def _func_before_start(created_ss): if output: self.assertEquals(capture_exceptions_stdout_stderr_calls, []) else: - self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), - {'exceptions': ss._capture_exception, - 'stdout_func': ss._capture_stdout, - 'stderr_func': ss._capture_stderr})]) + self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), { + 'exceptions': ss._capture_exception, + 'stdout_func': ss._capture_stdout, + 'stderr_func': ss._capture_stderr})]) self.assertEquals(ss.start_time, 1) self.assertEquals(time_calls, [()]) - self.assertEquals(get_logger_calls, [(ss.name, ss.log_name, - ss.log_level, ss.log_facility, ss.server.no_daemon)]) + self.assertEquals(get_logger_calls, [( + ss.name, ss.log_name, ss.log_level, ss.log_facility, + ss.server.no_daemon)]) self.assertEquals(ss.logger, fake_logger) self.assertEquals(fake_logger.error_calls, []) self.assertEquals(ss.handler.__class__.__name__, 'UDPEcho') @@ -3608,8 +3708,8 @@ def _func_before_start(created_ss): self.assertEquals(use_hub_calls, []) else: self.assertEquals(use_hub_calls, [(None,)]) - self.assertEquals(GreenPool_calls, - [((), {'size': ss.concurrent_per_worker})]) + self.assertEquals(GreenPool_calls, [ + ((), {'size': ss.concurrent_per_worker})]) self.assertEquals(len(spawn_n_calls), 1) self.assertEquals(len(spawn_n_calls[0]), 7) self.assertEquals(spawn_n_calls[0][0].__class__.__name__, 'UDPEcho') @@ -3622,8 +3722,8 @@ def _func_before_start(created_ss): if raises: self.assertEquals(recvfrom_calls, [(ss.max_datagram_size,)]) else: - self.assertEquals(recvfrom_calls, - [(ss.max_datagram_size,), (ss.max_datagram_size,)]) + self.assertEquals(recvfrom_calls, [ + (ss.max_datagram_size,), (ss.max_datagram_size,)]) if raises == 'socket einval': self.assertEquals(exc, None) elif raises == 'socket other': @@ -3671,10 +3771,11 @@ def test_capture_exception(self): self.assertEquals(len(ss.logger.error_calls), 1) self.assertEquals(len(ss.logger.error_calls[0]), 1) e = ss.logger.error_calls[0][0] - self.assertTrue(e.startswith("UNCAUGHT EXCEPTION: uid:123 Exception: " - "test ['Traceback (most recent call last):', ' File ")) - self.assertTrue(e.endswith('\', " raise Exception(\'test\')", ' - '\'Exception: test\']')) + self.assertTrue(e.startswith( + "UNCAUGHT EXCEPTION: uid:123 Exception: test ['Traceback (most " + "recent call last):', ' File ")) + self.assertTrue(e.endswith( + '\', " raise Exception(\'test\')", \'Exception: test\']')) self.assertEquals(ss.logger.exception_calls, []) def test_capture_stdout(self): @@ -3683,8 +3784,9 @@ def test_capture_stdout(self): ss.worker_id = 123 ss._capture_stdout('one\ntwo three\nfour\n') self.assertEquals(ss.logger.debug_calls, []) - self.assertEquals(ss.logger.info_calls, [('STDOUT: uid:123 one',), - ('STDOUT: uid:123 two three',), ('STDOUT: uid:123 four',)]) + self.assertEquals(ss.logger.info_calls, [ + ('STDOUT: uid:123 one',), ('STDOUT: uid:123 two three',), + ('STDOUT: uid:123 four',)]) self.assertEquals(ss.logger.notice_calls, []) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -3697,8 +3799,9 @@ def test_capture_stderr(self): self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) self.assertEquals(ss.logger.notice_calls, []) - self.assertEquals(ss.logger.error_calls, [('STDERR: uid:123 one',), - ('STDERR: uid:123 two three',), ('STDERR: uid:123 four',)]) + self.assertEquals(ss.logger.error_calls, [ + ('STDERR: uid:123 one',), ('STDERR: uid:123 two three',), + ('STDERR: uid:123 four',)]) self.assertEquals(ss.logger.exception_calls, []) @@ -3866,8 +3969,10 @@ def test_configure_daemons_conf_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Invalid call value " - "'brim_daemon_sample_DaemonSample' for daemon [one].") + self.assertEquals( + str(exc), + "Invalid call value 'brim_daemon_sample_DaemonSample' for daemon " + "[one].") def test_configure_daemons_no_load(self): ss = self._class(FakeServer(), 'test') @@ -3879,8 +3984,10 @@ def test_configure_daemons_no_load(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Could not load class " - "'brim.daemon_sample.aemon_sample' for daemon [one].") + self.assertEquals( + str(exc), + "Could not load class 'brim.daemon_sample.aemon_sample' for " + "daemon [one].") def test_configure_daemons_not_a_class(self): ss = self._class(FakeServer(), 'test') @@ -3892,9 +3999,10 @@ def test_configure_daemons_not_a_class(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " - "'brim.server._send_pid_sig' for daemon [one]. Probably not a " - "class.") + self.assertEquals( + str(exc), + "Would not be able to instantiate 'brim.server._send_pid_sig' for " + "daemon [one]. Probably not a class.") def test_configure_daemons_invalid_init(self): ss = self._class(FakeServer(), 'test') @@ -3907,7 +4015,9 @@ def test_configure_daemons_invalid_init(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to instantiate " + self.assertEquals( + str(exc), + "Would not be able to instantiate " "'brim.test.unit.test_server.DaemonWithInvalidInit' for daemon " "[one]. Incorrect number of args, 1, should be 3 (self, name, " "conf).") @@ -3923,7 +4033,9 @@ def test_configure_daemons_invalid_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.DaemonWithInvalidCall' for daemon " "[one]. Incorrect number of __call__ args, 1, should be 3 (self, " "subserver, stats).") @@ -3939,7 +4051,9 @@ def test_configure_daemons_no_call(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Would not be able to use " + self.assertEquals( + str(exc), + "Would not be able to use " "'brim.test.unit.test_server.DaemonWithNoCall' for daemon " "[one]. Probably no __call__ method.") @@ -3954,7 +4068,9 @@ def test_configure_daemons_invalid_parse_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " + self.assertEquals( + str(exc), + "Cannot use " "'brim.test.unit.test_server.DaemonWithInvalidParseConf1' for " "daemon [one]. Incorrect number of parse_conf args, 1, should be " "3 (cls, name, conf).") @@ -3970,7 +4086,9 @@ def test_configure_daemons_invalid_parse_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " + self.assertEquals( + str(exc), + "Cannot use " "'brim.test.unit.test_server.DaemonWithInvalidParseConf2' for " "daemon [one]. parse_conf probably not a method.") @@ -4004,7 +4122,9 @@ def test_configure_daemons_invalid_stats_conf1(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " + self.assertEquals( + str(exc), + "Cannot use " "'brim.test.unit.test_server.DaemonWithInvalidStatsConf1' for " "daemon [one]. Incorrect number of stats_conf args, 1, should be " "3 (cls, name, conf).") @@ -4020,7 +4140,9 @@ def test_configure_daemons_invalid_stats_conf2(self): ss._parse_conf(Conf(confd)) except Exception, err: exc = err - self.assertEquals(str(exc), "Cannot use " + self.assertEquals( + str(exc), + "Cannot use " "'brim.test.unit.test_server.DaemonWithInvalidStatsConf2' for " "daemon [one]. stats_conf probably not a method.") @@ -4089,16 +4211,17 @@ def _sustain_workers(*args, **kwargs): if output: self.assertEquals(capture_exceptions_stdout_stderr_calls, []) else: - self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), - {'exceptions': ss._capture_exception, - 'stdout_func': ss._capture_stdout, - 'stderr_func': ss._capture_stderr})]) + self.assertEquals(capture_exceptions_stdout_stderr_calls, [((), { + 'exceptions': ss._capture_exception, + 'stdout_func': ss._capture_stdout, + 'stderr_func': ss._capture_stderr})]) self.assertEquals(time_calls, [()]) - self.assertEquals(get_logger_calls, [(ss.name, ss.log_name, - ss.log_level, ss.log_facility, ss.server.no_daemon)]) + self.assertEquals(get_logger_calls, [( + ss.name, ss.log_name, ss.log_level, ss.log_facility, + ss.server.no_daemon)]) self.assertEquals(ss.worker_count, 1) - self.assertEquals(sustain_workers_calls, - [((ss.worker_count, ss._daemon), {'logger': fake_logger})]) + self.assertEquals(sustain_workers_calls, [ + ((ss.worker_count, ss._daemon), {'logger': fake_logger})]) self.assertEquals(ss.worker_id, -1) self.assertEquals(ss.start_time, 1) self.assertEquals(ss.logger, fake_logger) @@ -4149,8 +4272,8 @@ def _sustain_workers(*args, **kwargs): self.assertEquals(ss.bucket_stats.get(ss.worker_id, 'start_time'), 1) self.assertEquals(ss.daemons[0][0], 'one') self.assertEquals(ss.daemons[0][1].__name__, 'DaemonWithStatsConf') - self.assertEquals(ss.daemons[0][2].store, - {'test': {'daemons': 'one'}, + self.assertEquals(ss.daemons[0][2].store, { + 'test': {'daemons': 'one'}, 'one': {'call': 'brim.test.unit.test_server.DaemonWithStatsConf'}}) self.assertEquals(len(daemon.calls), 1) self.assertEquals(len(daemon.calls[0]), 2) @@ -4183,10 +4306,11 @@ def test_capture_exception(self): self.assertEquals(len(ss.logger.error_calls), 1) self.assertEquals(len(ss.logger.error_calls[0]), 1) e = ss.logger.error_calls[0][0] - self.assertTrue(e.startswith("UNCAUGHT EXCEPTION: did:123 Exception: " - "test ['Traceback (most recent call last):', ' File ")) - self.assertTrue(e.endswith('\', " raise Exception(\'test\')", ' - '\'Exception: test\']')) + self.assertTrue(e.startswith( + "UNCAUGHT EXCEPTION: did:123 Exception: test ['Traceback (most " + "recent call last):', ' File ")) + self.assertTrue(e.endswith( + '\', " raise Exception(\'test\')", \'Exception: test\']')) self.assertEquals(ss.logger.exception_calls, []) def test_capture_stdout(self): @@ -4195,8 +4319,9 @@ def test_capture_stdout(self): ss.worker_id = 123 ss._capture_stdout('one\ntwo three\nfour\n') self.assertEquals(ss.logger.debug_calls, []) - self.assertEquals(ss.logger.info_calls, [('STDOUT: did:123 one',), - ('STDOUT: did:123 two three',), ('STDOUT: did:123 four',)]) + self.assertEquals(ss.logger.info_calls, [ + ('STDOUT: did:123 one',), ('STDOUT: did:123 two three',), + ('STDOUT: did:123 four',)]) self.assertEquals(ss.logger.notice_calls, []) self.assertEquals(ss.logger.error_calls, []) self.assertEquals(ss.logger.exception_calls, []) @@ -4209,8 +4334,9 @@ def test_capture_stderr(self): self.assertEquals(ss.logger.debug_calls, []) self.assertEquals(ss.logger.info_calls, []) self.assertEquals(ss.logger.notice_calls, []) - self.assertEquals(ss.logger.error_calls, [('STDERR: did:123 one',), - ('STDERR: did:123 two three',), ('STDERR: did:123 four',)]) + self.assertEquals(ss.logger.error_calls, [ + ('STDERR: did:123 one',), ('STDERR: did:123 two three',), + ('STDERR: did:123 four',)]) self.assertEquals(ss.logger.exception_calls, []) @@ -4486,10 +4612,10 @@ def test_restart_has_conf_fork_side(self): self.assertEquals(self.stdout.getvalue(), '') self.assertEquals(self.stderr.getvalue(), '') self.assertEquals(self.fork_calls, [()]) - self.assertEquals(self.send_pid_sig_calls, - [((self.serv.pid_file, 0), {}), - ((self.serv.pid_file, server.SIGHUP), - {'expect_exit': True, 'pid_override': 12345})]) + self.assertEquals(self.send_pid_sig_calls, [ + ((self.serv.pid_file, 0), {}), + ((self.serv.pid_file, server.SIGHUP), + {'expect_exit': True, 'pid_override': 12345})]) def test_reload_no_conf(self): self.serv.args = ['reload'] @@ -4513,10 +4639,10 @@ def test_reload_has_conf_fork_side(self): self.assertEquals(self.stdout.getvalue(), '') self.assertEquals(self.stderr.getvalue(), '') self.assertEquals(self.fork_calls, [()]) - self.assertEquals(self.send_pid_sig_calls, - [((self.serv.pid_file, 0), {}), - ((self.serv.pid_file, server.SIGHUP), - {'expect_exit': True, 'pid_override': 12345})]) + self.assertEquals(self.send_pid_sig_calls, [ + ((self.serv.pid_file, 0), {}), + ((self.serv.pid_file, server.SIGHUP), + {'expect_exit': True, 'pid_override': 12345})]) def test_force_reload_no_conf(self): self.serv.args = ['force-reload'] @@ -4540,26 +4666,26 @@ def test_force_reload_has_conf_fork_side(self): self.assertEquals(self.stdout.getvalue(), '') self.assertEquals(self.stderr.getvalue(), '') self.assertEquals(self.fork_calls, [()]) - self.assertEquals(self.send_pid_sig_calls, - [((self.serv.pid_file, 0), {}), - ((self.serv.pid_file, server.SIGHUP), - {'expect_exit': True, 'pid_override': 12345})]) + self.assertEquals(self.send_pid_sig_calls, [ + ((self.serv.pid_file, 0), {}), + ((self.serv.pid_file, server.SIGHUP), + {'expect_exit': True, 'pid_override': 12345})]) def test_shutdown(self): self.serv.args = ['shutdown'] self.assertEquals(self.serv.main(), 0) self.assertEquals(self.stdout.getvalue(), '') self.assertEquals(self.stderr.getvalue(), '') - self.assertEquals(self.send_pid_sig_calls, - [((self.serv.pid_file, server.SIGHUP), {'expect_exit': True})]) + self.assertEquals(self.send_pid_sig_calls, [ + ((self.serv.pid_file, server.SIGHUP), {'expect_exit': True})]) def test_stop(self): self.serv.args = ['stop'] self.assertEquals(self.serv.main(), 0) self.assertEquals(self.stdout.getvalue(), '') self.assertEquals(self.stderr.getvalue(), '') - self.assertEquals(self.send_pid_sig_calls, - [((self.serv.pid_file, server.SIGTERM), {'expect_exit': True})]) + self.assertEquals(self.send_pid_sig_calls, [ + ((self.serv.pid_file, server.SIGTERM), {'expect_exit': True})]) def test_status_running(self): self.serv.args = ['status'] @@ -4626,7 +4752,8 @@ def test_parse_conf_default(self): self.assertEquals(self.serv.log_name, 'brim') self.assertEquals(self.serv.log_level, 'INFO') self.assertEquals(self.serv.log_facility, 'LOG_LOCAL0') - self.assertEquals(sorted(s.name for s in self.serv.subservers), + self.assertEquals( + sorted(s.name for s in self.serv.subservers), ['daemons', 'tcp', 'tcp2', 'udp', 'udp2', 'wsgi', 'wsgi2']) # Just verifies subserver._parse_conf was called. wsgi = [s for s in self.serv.subservers if s.name == 'wsgi'][0] @@ -4747,8 +4874,8 @@ def _sustain_workers(*args, **kwargs): server.sustain_workers = orig_sustain_workers # Since we're in no-daemon, Server didn't call sustain_workers, but the # wsgi subserver did. - self.assertEquals(sustain_workers_calls, - [((0, subserv._wsgi_worker), {'logger': subserv.logger})]) + self.assertEquals(sustain_workers_calls, [ + ((0, subserv._wsgi_worker), {'logger': subserv.logger})]) def test_start_no_subservers(self): self.conf = Conf({'brim': {'port': '0'}}) @@ -4825,8 +4952,8 @@ def _sustain_workers(*args, **kwargs): self.serv._start() finally: server.sustain_workers = orig_sustain_workers - self.assertEquals(sustain_workers_calls, - [((1, self.serv._start_subserver), {'logger': self.serv.logger})]) + self.assertEquals(sustain_workers_calls, [ + ((1, self.serv._start_subserver), {'logger': self.serv.logger})]) self.assertEquals(self.capture_calls, [ ((), {'exceptions': self.serv._capture_exception, 'stdout_func': self.serv._capture_stdout, @@ -4852,8 +4979,8 @@ def _sustain_workers(*args, **kwargs): self.serv._start() finally: server.sustain_workers = orig_sustain_workers - self.assertEquals(sustain_workers_calls, - [((1, self.serv._start_subserver), {'logger': self.serv.logger})]) + self.assertEquals(sustain_workers_calls, [ + ((1, self.serv._start_subserver), {'logger': self.serv.logger})]) self.assertEquals(self.capture_calls, []) def test_start_subserver(self, no_setproctitle=False): @@ -4876,8 +5003,8 @@ def _sustain_workers(*args, **kwargs): self.serv._start() finally: server.sustain_workers = orig_sustain_workers - self.assertEquals(sustain_workers_calls, - [((1, self.serv._start_subserver), {'logger': self.serv.logger})]) + self.assertEquals(sustain_workers_calls, [ + ((1, self.serv._start_subserver), {'logger': self.serv.logger})]) self.assertEquals(self.capture_calls, [ ((), {'exceptions': self.serv._capture_exception, 'stdout_func': self.serv._capture_stdout, @@ -4930,28 +5057,28 @@ def test_capture_exception(self): def test_capture_stdout(self): self.serv.logger = FakeLogger() self.serv._capture_stdout('one\ntwo\nthree\n') - self.assertEquals(self.serv.logger.info_calls, - [('STDOUT: main one',), ('STDOUT: main two',), - ('STDOUT: main three',)]) + self.assertEquals(self.serv.logger.info_calls, [ + ('STDOUT: main one',), ('STDOUT: main two',), + ('STDOUT: main three',)]) self.serv.logger = FakeLogger() self.serv._capture_stdout('one\ntwo\nthree\n') - self.assertEquals(self.serv.logger.info_calls, - [('STDOUT: main one',), ('STDOUT: main two',), - ('STDOUT: main three',)]) + self.assertEquals(self.serv.logger.info_calls, [ + ('STDOUT: main one',), ('STDOUT: main two',), + ('STDOUT: main three',)]) def test_capture_stderr(self): self.serv.logger = FakeLogger() self.serv._capture_stderr('one\ntwo\nthree\n') - self.assertEquals(self.serv.logger.error_calls, - [('STDERR: main one',), ('STDERR: main two',), - ('STDERR: main three',)]) + self.assertEquals(self.serv.logger.error_calls, [ + ('STDERR: main one',), ('STDERR: main two',), + ('STDERR: main three',)]) self.serv.logger = FakeLogger() self.serv._capture_stderr('one\ntwo\nthree\n') - self.assertEquals(self.serv.logger.error_calls, - [('STDERR: main one',), ('STDERR: main two',), - ('STDERR: main three',)]) + self.assertEquals(self.serv.logger.error_calls, [ + ('STDERR: main one',), ('STDERR: main two',), + ('STDERR: main three',)]) if __name__ == '__main__': diff --git a/brim/test/unit/test_service.py b/brim/test/unit/test_service.py index f04da82..b260390 100644 --- a/brim/test/unit/test_service.py +++ b/brim/test/unit/test_service.py @@ -592,7 +592,8 @@ def test_retries(self): sock = service.get_listening_tcp_socket('1.2.3.4', 5678) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 30 seconds.') # Calls time once before loop to calculate when to stop and once per # loop to see if it's time to stop. @@ -608,7 +609,8 @@ def test_uses_passed_retry(self): sock = service.get_listening_tcp_socket('1.2.3.4', 5678, retry=10) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 10 seconds.') # Calls time once before loop to calculate when to stop and once per # loop to see if it's time to stop. @@ -649,7 +651,8 @@ def _getaddrinfo(*args): ip = '1.2.3.4' port = 5678 sock = service.get_listening_tcp_socket(ip, port, style='eventlet') - self.assertEquals(egetaddrinfo_calls, + self.assertEquals( + egetaddrinfo_calls, [(ip, port, socket.AF_UNSPEC, socket.SOCK_STREAM)]) self.assertEquals(sock.init, (socket.AF_INET, socket.SOCK_STREAM)) self.assertEquals(set(sock.setsockopt_calls), set([ @@ -689,8 +692,9 @@ def _ewrap_socket(*args, **kwargs): eventlet.green.ssl.wrap_socket = _ewrap_socket certfile = 'certfile' keyfile = 'keyfile' - sock = service.get_listening_tcp_socket('1.2.3.4', 5678, - style='eventlet', certfile=certfile, keyfile=keyfile) + sock = service.get_listening_tcp_socket( + '1.2.3.4', 5678, style='eventlet', certfile=certfile, + keyfile=keyfile) self.assertEquals(sock, 'ewrappedsock') self.assertEquals(len(ewrap_socket_calls), 1) self.assertEquals(ewrap_socket_calls[0][1], @@ -718,7 +722,8 @@ def test_uses_eventlet_sleep(self): style='eventlet') except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 30 seconds.') self.assertEquals(len(esleep_calls), 29) self.assertEquals(len(self.sleep_calls), 0) @@ -749,7 +754,8 @@ def test_no_family_raises_exception(self): service.get_listening_tcp_socket('1.2.3.4', 5678) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not determine address family of 1.2.3.4:5678 for binding.') def test_odd_exception_reraised(self): @@ -818,7 +824,8 @@ def test_retries(self): sock = service.get_listening_udp_socket('1.2.3.4', 5678) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 30 seconds.') # Calls time once before loop to calculate when to stop and once per # loop to see if it's time to stop. @@ -834,7 +841,8 @@ def test_uses_passed_retry(self): sock = service.get_listening_udp_socket('1.2.3.4', 5678, retry=10) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 10 seconds.') # Calls time once before loop to calculate when to stop and once per # loop to see if it's time to stop. @@ -864,7 +872,8 @@ def _getaddrinfo(*args): ip = '1.2.3.4' port = 5678 sock = service.get_listening_udp_socket(ip, port, style='eventlet') - self.assertEquals(egetaddrinfo_calls, + self.assertEquals( + egetaddrinfo_calls, [(ip, port, socket.AF_UNSPEC, socket.SOCK_DGRAM)]) self.assertEquals(sock.init, (socket.AF_INET, socket.SOCK_DGRAM)) self.assertEquals(set(sock.setsockopt_calls), set([ @@ -892,7 +901,8 @@ def test_uses_eventlet_sleep(self): style='eventlet') except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not bind to 1.2.3.4:5678 after trying for 30 seconds.') self.assertEquals(len(esleep_calls), 29) self.assertEquals(len(self.sleep_calls), 0) @@ -923,7 +933,8 @@ def test_no_family_raises_exception(self): service.get_listening_udp_socket('1.2.3.4', 5678) except Exception, err: exc = err - self.assertEquals(str(exc), + self.assertEquals( + str(exc), 'Could not determine address family of 1.2.3.4:5678 for binding.') def test_odd_exception_reraised(self): @@ -997,9 +1008,11 @@ def test_workers0(self): logger = FakeLogger() service.sustain_workers(0, self.worker_func, logger) self.assertEquals(self.worker_func_calls, [(0,)]) - self.assertEquals(logger.debug_calls, + self.assertEquals( + logger.debug_calls, [('wid:000 pid:%s Starting inproc worker.' % service.getpid(),)]) - self.assertEquals(logger.info_calls, + self.assertEquals( + logger.info_calls, [('Exiting due to workers = 0 mode.',)]) def test_workers0_no_logger(self): @@ -1110,7 +1123,8 @@ def test_child(self): service.fork = lambda *a: 0 service.sustain_workers(1, self.worker_func, logger) # Asserts the TERM and HUP signal handlers are cleared with the child. - self.assertEquals(set(self.signal_calls[-2:]), + self.assertEquals( + set(self.signal_calls[-2:]), set([(service.SIGHUP, 0), (service.SIGTERM, 0)])) self.assertEquals(self.worker_func_calls, [(0,)]) self.assertEquals(logger.debug_calls, [ diff --git a/brim/test/unit/test_stats.py b/brim/test/unit/test_stats.py index 72ba8fc..a78afef 100644 --- a/brim/test/unit/test_stats.py +++ b/brim/test/unit/test_stats.py @@ -58,27 +58,27 @@ class FakeServer(object): def __init__(self): self.start_time = 1234 self.subservers = [ - FakeSubserver(self, 'wsgi', 2, ['0', '1'], - {'one': 'worker', 'two': 'sum', 'three': 'min', - 'four': 'max'}), - FakeSubserver(self, 'wsgi2', 2, ['0', '1'], - {'One': 'worker', 'Two': 'sum', 'Three': 'min', - 'Four': 'max'}), - FakeSubserver(self, 'tcp', 2, ['0', '1'], - {'one': 'worker', 'two': 'sum', 'three': 'min', - 'four': 'max'}), - FakeSubserver(self, 'tcp2', 2, ['0', '1'], - {'One': 'worker', 'Two': 'sum', 'Three': 'min', - 'Four': 'max'}), - FakeSubserver(self, 'udp', 1, ['0'], - {'one': 'worker', 'two': 'worker', 'three': 'worker', - 'four': 'worker'}), - FakeSubserver(self, 'udp2', 1, ['0'], - {'One': 'worker', 'Two': 'worker', 'Three': 'worker', - 'Four': 'worker'}), - FakeSubserver(self, 'daemons', 2, ['a', 'b'], - {'one': 'worker', 'two': 'worker', 'three': 'worker', - 'four': 'worker'})] + FakeSubserver(self, 'wsgi', 2, ['0', '1'], { + 'one': 'worker', 'two': 'sum', 'three': 'min', + 'four': 'max'}), + FakeSubserver(self, 'wsgi2', 2, ['0', '1'], { + 'One': 'worker', 'Two': 'sum', 'Three': 'min', + 'Four': 'max'}), + FakeSubserver(self, 'tcp', 2, ['0', '1'], { + 'one': 'worker', 'two': 'sum', 'three': 'min', + 'four': 'max'}), + FakeSubserver(self, 'tcp2', 2, ['0', '1'], { + 'One': 'worker', 'Two': 'sum', 'Three': 'min', + 'Four': 'max'}), + FakeSubserver(self, 'udp', 1, ['0'], { + 'one': 'worker', 'two': 'worker', 'three': 'worker', + 'four': 'worker'}), + FakeSubserver(self, 'udp2', 1, ['0'], { + 'One': 'worker', 'Two': 'worker', 'Three': 'worker', + 'Four': 'worker'}), + FakeSubserver(self, 'daemons', 2, ['a', 'b'], { + 'one': 'worker', 'two': 'worker', 'three': 'worker', + 'four': 'worker'})] self.bucket_stats = [FakeStats(s.worker_names, s.stats_conf) for s in self.subservers] @@ -115,7 +115,7 @@ def test_init_attrs(self): def test_call_ignores_non_path(self): self.env['PATH_INFO'] = '/' stats.Stats('test', self.parsed_conf, - self.next_app)(self.env, self.start_response) + self.next_app)(self.env, self.start_response) self.assertEquals(self.next_app_calls, [(self.env, self.start_response)]) self.assertEquals(self.start_response_calls, @@ -123,16 +123,18 @@ def test_call_ignores_non_path(self): def test_call_not_implemented(self): self.env['REQUEST_METHOD'] = 'PUT' - body = ''.join(stats.Stats('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(stats.Stats( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('501 Not Implemented', [('Content-Length', '0')])]) self.assertEquals(body, '') def test_call_stats_zeroed(self): - body = ''.join(stats.Stats('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(stats.Stats( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '811'), ('Content-Type', 'application/json')])]) @@ -166,8 +168,9 @@ def test_call_stats_zeroed(self): def test_call_stats_zeroed_head(self): self.env['REQUEST_METHOD'] = 'HEAD' - body = ''.join(stats.Stats('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(stats.Stats( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '811'), ('Content-Type', 'application/json')])]) @@ -236,8 +239,9 @@ def test_call_stats(self): bstats.set(1, 'two', daemons_tag + 12) bstats.set(1, 'three', daemons_tag + 13) bstats.set(1, 'four', daemons_tag + 14) - body = ''.join(stats.Stats('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(stats.Stats( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '931'), ('Content-Type', 'application/json')])]) diff --git a/brim/test/unit/test_tcp_echo.py b/brim/test/unit/test_tcp_echo.py index a1ac2f1..d644c2a 100644 --- a/brim/test/unit/test_tcp_echo.py +++ b/brim/test/unit/test_tcp_echo.py @@ -139,8 +139,8 @@ def test_parse_conf(self): self.assertEquals(c, {'chunk_read': 1234}) exc = None try: - c = tcp_echo.TCPEcho.parse_conf('test', - Conf({'test': {'chunk_read': 'abc'}})) + c = tcp_echo.TCPEcho.parse_conf( + 'test', Conf({'test': {'chunk_read': 'abc'}})) except SystemExit, err: exc = err self.assertEquals(str(exc), "Configuration value [test] chunk_read of " diff --git a/brim/test/unit/test_udp_echo.py b/brim/test/unit/test_udp_echo.py index d9b0c87..0bb7535 100644 --- a/brim/test/unit/test_udp_echo.py +++ b/brim/test/unit/test_udp_echo.py @@ -77,7 +77,8 @@ def test_call(self): datagram = '1234' udp_echo.UDPEcho('test', {})(subserver, stats, sock, datagram, ip, port) - self.assertEquals(subserver.logger.notice_calls, + self.assertEquals( + subserver.logger.notice_calls, [(('served request of 4 bytes from %s:%d' % (ip, port),), {})]) self.assertEquals(stats.stats, {'byte_count': len(datagram)}) self.assertEquals(sock.sendto_calls, [((datagram, (ip, port)), {})]) diff --git a/brim/test/unit/test_wsgi_echo.py b/brim/test/unit/test_wsgi_echo.py index 11ac70b..d313d84 100644 --- a/brim/test/unit/test_wsgi_echo.py +++ b/brim/test/unit/test_wsgi_echo.py @@ -81,24 +81,27 @@ def test_call_stat_incr(self): self.assertEquals(self.env['brim.stats'].get('test.requests'), 1) def test_call_echo(self): - body = ''.join(wsgi_echo.WSGIEcho('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(wsgi_echo.WSGIEcho( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '8')])]) self.assertEquals(body, 'testbody') def test_call_echo_capped(self): self.env['wsgi.input'] = StringIO('1234567890123') - body = ''.join(wsgi_echo.WSGIEcho('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(wsgi_echo.WSGIEcho( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '10')])]) self.assertEquals(body, '1234567890') def test_call_echo_exception_on_read(self): del self.env['wsgi.input'] - body = ''.join(wsgi_echo.WSGIEcho('test', self.parsed_conf, - self.next_app)(self.env, self.start_response)) + body = ''.join(wsgi_echo.WSGIEcho( + 'test', self.parsed_conf, self.next_app)( + self.env, self.start_response)) self.assertEquals(self.start_response_calls, [('200 OK', [('Content-Length', '0')])]) self.assertEquals(body, '') @@ -106,11 +109,11 @@ def test_call_echo_exception_on_read(self): def test_parse_conf(self): c = wsgi_echo.WSGIEcho.parse_conf('test', Conf({})) self.assertEquals(c, {'path': '/echo', 'max_echo': 65536}) - c = wsgi_echo.WSGIEcho.parse_conf('test', - Conf({'test': {'path': '/blah', 'max_echo': 1}})) + c = wsgi_echo.WSGIEcho.parse_conf( + 'test', Conf({'test': {'path': '/blah', 'max_echo': 1}})) self.assertEquals(c, {'path': '/blah', 'max_echo': 1}) - c = wsgi_echo.WSGIEcho.parse_conf('test', - Conf({'test2': {'path': '/blah', 'max_echo': 1}})) + c = wsgi_echo.WSGIEcho.parse_conf( + 'test', Conf({'test2': {'path': '/blah', 'max_echo': 1}})) self.assertEquals(c, {'path': '/echo', 'max_echo': 65536}) def test_stats_conf(self):