Skip to content

Commit

Permalink
Made compliant with PEP8 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gholt committed Jun 23, 2012
1 parent 0f5e098 commit 24d9d80
Show file tree
Hide file tree
Showing 15 changed files with 714 additions and 520 deletions.
3 changes: 2 additions & 1 deletion brim/http.py
Expand Up @@ -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 ''
Expand Down
6 changes: 3 additions & 3 deletions brim/httpform.py
Expand Up @@ -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',
Expand All @@ -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):
Expand Down
251 changes: 139 additions & 112 deletions brim/server.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions brim/service.py
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions brim/stats.py
Expand Up @@ -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'
Expand Down
42 changes: 22 additions & 20 deletions brim/test/unit/test_conf.py
Expand Up @@ -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'},
Expand All @@ -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(
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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',
Expand Down
15 changes: 8 additions & 7 deletions brim/test/unit/test_daemon_sample.py
Expand Up @@ -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'])
Expand All @@ -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__':
Expand Down
24 changes: 15 additions & 9 deletions brim/test/unit/test_http.py
Expand Up @@ -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):
Expand All @@ -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')
Expand All @@ -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), '')
Expand All @@ -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), '')
Expand All @@ -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), '')
Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down
40 changes: 22 additions & 18 deletions brim/test/unit/test_log.py
Expand Up @@ -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')
Expand All @@ -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'}})])


Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 24d9d80

Please sign in to comment.