Commit f3acb176 authored by Jason Madden's avatar Jason Madden

More pylint for examples and tests

parent 4f267154
...@@ -10,10 +10,10 @@ from psycopg2 import extensions, OperationalError, connect ...@@ -10,10 +10,10 @@ from psycopg2 import extensions, OperationalError, connect
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
integer_types = int, integer_types = (int,)
else: else:
import __builtin__ import __builtin__
integer_types = int, __builtin__.long integer_types = (int, __builtin__.long)
def gevent_wait_callback(conn, timeout=None): def gevent_wait_callback(conn, timeout=None):
...@@ -50,14 +50,14 @@ class AbstractDatabaseConnectionPool(object): ...@@ -50,14 +50,14 @@ class AbstractDatabaseConnectionPool(object):
pool = self.pool pool = self.pool
if self.size >= self.maxsize or pool.qsize(): if self.size >= self.maxsize or pool.qsize():
return pool.get() return pool.get()
else:
self.size += 1 self.size += 1
try: try:
new_item = self.create_connection() new_item = self.create_connection()
except: except:
self.size -= 1 self.size -= 1
raise raise
return new_item return new_item
def put(self, item): def put(self, item):
self.pool.put(item) self.pool.put(item)
......
...@@ -104,12 +104,11 @@ def join(url1, *rest): ...@@ -104,12 +104,11 @@ def join(url1, *rest):
if url1.endswith(b'/'): if url1.endswith(b'/'):
if url2.startswith(b'/'): if url2.startswith(b'/'):
return join(url1 + url2[1:], *rest) return join(url1 + url2[1:], *rest)
else: return join(url1 + url2, *rest)
return join(url1 + url2, *rest)
elif url2.startswith(b'/'): elif url2.startswith(b'/'):
return join(url1 + url2, *rest) return join(url1 + url2, *rest)
else:
return join(url1 + b'/' + url2, *rest) return join(url1 + b'/' + url2, *rest)
def fix_links(data, proxy_url, host_url): def fix_links(data, proxy_url, host_url):
......
...@@ -8,9 +8,9 @@ def application(env, start_response): ...@@ -8,9 +8,9 @@ def application(env, start_response):
if env['PATH_INFO'] == '/': if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')]) start_response('200 OK', [('Content-Type', 'text/html')])
return [b"<b>hello world</b>"] return [b"<b>hello world</b>"]
else:
start_response('404 Not Found', [('Content-Type', 'text/html')]) start_response('404 Not Found', [('Content-Type', 'text/html')])
return [b'<h1>Not Found</h1>'] return [b'<h1>Not Found</h1>']
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -9,9 +9,9 @@ def hello_world(env, start_response): ...@@ -9,9 +9,9 @@ def hello_world(env, start_response):
if env['PATH_INFO'] == '/': if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')]) start_response('200 OK', [('Content-Type', 'text/html')])
return [b"<b>hello world</b>"] return [b"<b>hello world</b>"]
else:
start_response('404 Not Found', [('Content-Type', 'text/html')]) start_response('404 Not Found', [('Content-Type', 'text/html')])
return [b'<h1>Not Found</h1>'] return [b'<h1>Not Found</h1>']
print('Serving on https://:8443') print('Serving on https://:8443')
server = pywsgi.WSGIServer(('', 8443), hello_world, keyfile='server.key', certfile='server.crt') server = pywsgi.WSGIServer(('', 8443), hello_world, keyfile='server.key', certfile='server.crt')
......
# pylint:disable=too-many-lines, protected-access, redefined-outer-name, not-callable, # pylint:disable=too-many-lines, protected-access, redefined-outer-name, not-callable,
# pylint:disable=no-member
from __future__ import absolute_import, print_function from __future__ import absolute_import, print_function
import sys import sys
import os import os
......
...@@ -136,7 +136,7 @@ class ExpectedException(Exception): ...@@ -136,7 +136,7 @@ class ExpectedException(Exception):
def wrap_switch_count_check(method): def wrap_switch_count_check(method):
@wraps(method) @wraps(method)
def wrap_switch_count_check(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
initial_switch_count = getattr(_get_hub(), 'switch_count', None) initial_switch_count = getattr(_get_hub(), 'switch_count', None)
self.switch_expected = getattr(self, 'switch_expected', True) self.switch_expected = getattr(self, 'switch_expected', True)
if initial_switch_count is not None: if initial_switch_count is not None:
...@@ -156,7 +156,7 @@ def wrap_switch_count_check(method): ...@@ -156,7 +156,7 @@ def wrap_switch_count_check(method):
else: else:
raise AssertionError('Invalid value for switch_expected: %r' % (self.switch_expected, )) raise AssertionError('Invalid value for switch_expected: %r' % (self.switch_expected, ))
return result return result
return wrap_switch_count_check return wrapper
def wrap_timeout(timeout, method): def wrap_timeout(timeout, method):
...@@ -164,11 +164,11 @@ def wrap_timeout(timeout, method): ...@@ -164,11 +164,11 @@ def wrap_timeout(timeout, method):
return method return method
@wraps(method) @wraps(method)
def wrap_timeout(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
with gevent.Timeout(timeout, 'test timed out', ref=False): with gevent.Timeout(timeout, 'test timed out', ref=False):
return method(self, *args, **kwargs) return method(self, *args, **kwargs)
return wrap_timeout return wrapper
def ignores_leakcheck(func): def ignores_leakcheck(func):
func.ignore_leakcheck = True func.ignore_leakcheck = True
...@@ -212,7 +212,7 @@ def wrap_refcount(method): ...@@ -212,7 +212,7 @@ def wrap_refcount(method):
return diff return diff
@wraps(method) @wraps(method)
def wrap_refcount(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
gc.collect() gc.collect()
gc.collect() gc.collect()
gc.collect() gc.collect()
...@@ -272,12 +272,12 @@ def wrap_refcount(method): ...@@ -272,12 +272,12 @@ def wrap_refcount(method):
gc.enable() gc.enable()
self.skipTearDown = True self.skipTearDown = True
return wrap_refcount return wrapper
def wrap_error_fatal(method): def wrap_error_fatal(method):
@wraps(method) @wraps(method)
def wrap_error_fatal(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
# XXX should also be able to do gevent.SYSTEM_ERROR = object # XXX should also be able to do gevent.SYSTEM_ERROR = object
# which is a global default to all hubs # which is a global default to all hubs
SYSTEM_ERROR = gevent.get_hub().SYSTEM_ERROR SYSTEM_ERROR = gevent.get_hub().SYSTEM_ERROR
...@@ -286,12 +286,12 @@ def wrap_error_fatal(method): ...@@ -286,12 +286,12 @@ def wrap_error_fatal(method):
return method(self, *args, **kwargs) return method(self, *args, **kwargs)
finally: finally:
gevent.get_hub().SYSTEM_ERROR = SYSTEM_ERROR gevent.get_hub().SYSTEM_ERROR = SYSTEM_ERROR
return wrap_error_fatal return wrapper
def wrap_restore_handle_error(method): def wrap_restore_handle_error(method):
@wraps(method) @wraps(method)
def wrap_restore_handle_error(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
old = gevent.get_hub().handle_error old = gevent.get_hub().handle_error
try: try:
return method(self, *args, **kwargs) return method(self, *args, **kwargs)
...@@ -299,7 +299,7 @@ def wrap_restore_handle_error(method): ...@@ -299,7 +299,7 @@ def wrap_restore_handle_error(method):
gevent.get_hub().handle_error = old gevent.get_hub().handle_error = old
if self.peek_error()[0] is not None: if self.peek_error()[0] is not None:
gevent.getcurrent().throw(*self.peek_error()[1:]) gevent.getcurrent().throw(*self.peek_error()[1:])
return wrap_restore_handle_error return wrapper
def _get_class_attr(classDict, bases, attr, default=AttributeError): def _get_class_attr(classDict, bases, attr, default=AttributeError):
...@@ -369,6 +369,7 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})): ...@@ -369,6 +369,7 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
close_on_teardown = () close_on_teardown = ()
def run(self, *args, **kwargs): def run(self, *args, **kwargs):
# pylint:disable=arguments-differ
if self.switch_expected == 'default': if self.switch_expected == 'default':
self.switch_expected = get_switch_expected(self.fullname) self.switch_expected = get_switch_expected(self.fullname)
return BaseTestCase.run(self, *args, **kwargs) return BaseTestCase.run(self, *args, **kwargs)
...@@ -521,6 +522,7 @@ class CountingHub(_original_Hub): ...@@ -521,6 +522,7 @@ class CountingHub(_original_Hub):
switch_count = 0 switch_count = 0
def switch(self, *args): def switch(self, *args):
# pylint:disable=arguments-differ
self.switch_count += 1 self.switch_count += 1
return _original_Hub.switch(self, *args) return _original_Hub.switch(self, *args)
...@@ -722,7 +724,7 @@ def _run_lsof(): ...@@ -722,7 +724,7 @@ def _run_lsof():
os.remove(tmpname) os.remove(tmpname)
return data return data
def get_open_files(pipes=False): def default_get_open_files(pipes=False):
data = _run_lsof() data = _run_lsof()
results = {} results = {}
for line in data.split('\n'): for line in data.split('\n'):
...@@ -746,7 +748,7 @@ def get_open_files(pipes=False): ...@@ -746,7 +748,7 @@ def get_open_files(pipes=False):
results['data'] = data results['data'] = data
return results return results
def get_number_open_files(): def default_get_number_open_files():
if os.path.exists('/proc/'): if os.path.exists('/proc/'):
# Linux only # Linux only
fd_directory = '/proc/%d/fd' % os.getpid() fd_directory = '/proc/%d/fd' % os.getpid()
...@@ -757,12 +759,13 @@ def get_number_open_files(): ...@@ -757,12 +759,13 @@ def get_number_open_files():
except (OSError, AssertionError): except (OSError, AssertionError):
return 0 return 0
lsof_get_open_files = get_open_files lsof_get_open_files = default_get_open_files
try: try:
import psutil import psutil
except ImportError: except ImportError:
pass get_open_files = default_get_open_files
get_number_open_files = default_get_number_open_files
else: else:
# If psutil is available (it is cross-platform) use that. # If psutil is available (it is cross-platform) use that.
# It is *much* faster than shelling out to lsof each time # It is *much* faster than shelling out to lsof each time
......
...@@ -497,7 +497,7 @@ if hasattr(sys, 'pypy_version_info') and sys.version_info[:2] >= (3, 3): ...@@ -497,7 +497,7 @@ if hasattr(sys, 'pypy_version_info') and sys.version_info[:2] >= (3, 3):
] ]
if hasattr(sys, 'pypy_version_info') and sys.pypy_version_info[:4] == (5, 7, 1, 'beta'): if hasattr(sys, 'pypy_version_info') and sys.pypy_version_info[:4] == (5, 7, 1, 'beta'): # pylint:disable=no-member
# 3.5 is beta. Hard to say what are real bugs in us vs real bugs in pypy. # 3.5 is beta. Hard to say what are real bugs in us vs real bugs in pypy.
# For that reason, we pin these patches exactly to the version in use. # For that reason, we pin these patches exactly to the version in use.
...@@ -728,7 +728,7 @@ def _build_test_structure(sequence_of_tests): ...@@ -728,7 +728,7 @@ def _build_test_structure(sequence_of_tests):
disabled_tests_by_file = collections.defaultdict(set) disabled_tests_by_file = collections.defaultdict(set)
for file_case_meth in _disabled_tests: for file_case_meth in _disabled_tests:
file_name, _case, meth = file_case_meth.split('.') file_name, _case, _meth = file_case_meth.split('.')
by_file = disabled_tests_by_file[file_name] by_file = disabled_tests_by_file[file_name]
......
...@@ -193,7 +193,7 @@ def run(command, **kwargs): ...@@ -193,7 +193,7 @@ def run(command, **kwargs):
finally: finally:
kill(popen) kill(popen)
assert not err assert not err
with lock: with lock: # pylint:disable=not-context-manager
failed = bool(result) failed = bool(result)
if out and (failed or verbose): if out and (failed or verbose):
out = out.strip().decode('utf-8', 'ignore') out = out.strip().decode('utf-8', 'ignore')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment