Commit f5da156b authored by Jason Madden's avatar Jason Madden

Fix pylint errors in our tests.

parent d4d19fb0
...@@ -42,6 +42,10 @@ ...@@ -42,6 +42,10 @@
Objects/tupleobject.c: bad argument to internal function``. Reported Objects/tupleobject.c: bad argument to internal function``. Reported
in :issue:`1302` by Ulrich Petri. in :issue:`1302` by Ulrich Petri.
- Refactored the gevent test runner and test suite to make them more
reusable. In particular, the tests are now run with ``python -m
gevent.tests``. See :issue:`1293`.
1.3.7 (2018-10-12) 1.3.7 (2018-10-12)
================== ==================
......
...@@ -177,8 +177,7 @@ tests on one version of Python during development, begin with the ...@@ -177,8 +177,7 @@ tests on one version of Python during development, begin with the
above instructions to install gevent in a virtual environment and then above instructions to install gevent in a virtual environment and then
run:: run::
(env) $ cd src/greentest (env) $ python -mgevent.tests
(env) $ python ./testrunner.py
Before submitting a pull request, it's a good idea to run the tests Before submitting a pull request, it's a good idea to run the tests
across all supported versions of Python, and to check the code quality across all supported versions of Python, and to check the code quality
...@@ -192,8 +191,7 @@ The testrunner accepts a ``--coverage`` argument to enable code ...@@ -192,8 +191,7 @@ The testrunner accepts a ``--coverage`` argument to enable code
coverage metrics through the `coverage.py`_ package. That would go coverage metrics through the `coverage.py`_ package. That would go
something like this:: something like this::
cd src/greentest python -m gevent.tests --coverage
python testrunner.py --coverage
coverage combine coverage combine
coverage html -i coverage html -i
<open htmlcov/index.html> <open htmlcov/index.html>
......
""" """
Various tests for synchronization primitives. Various tests for synchronization primitives.
""" """
# pylint:disable=no-member,abstract-method
import sys import sys
import time import time
try: try:
...@@ -131,7 +132,7 @@ class BaseLockTests(BaseTestCase): ...@@ -131,7 +132,7 @@ class BaseLockTests(BaseTestCase):
def _with(err=None): def _with(err=None):
with lock: with lock:
if err is not None: if err is not None:
raise err raise err # pylint:disable=raising-bad-type
_with() _with()
# Check the lock is unacquired # Check the lock is unacquired
Bunch(f, 1).wait_for_finished() Bunch(f, 1).wait_for_finished()
...@@ -153,7 +154,7 @@ class BaseLockTests(BaseTestCase): ...@@ -153,7 +154,7 @@ class BaseLockTests(BaseTestCase):
self.assertEqual(n, len(threading.enumerate())) self.assertEqual(n, len(threading.enumerate()))
class LockTests(BaseLockTests): class LockTests(BaseLockTests): # pylint:disable=abstract-method
""" """
Tests for non-recursive, weak locks Tests for non-recursive, weak locks
(which can be acquired and released from different threads). (which can be acquired and released from different threads).
...@@ -168,7 +169,7 @@ class LockTests(BaseLockTests): ...@@ -168,7 +169,7 @@ class LockTests(BaseLockTests):
lock.acquire() lock.acquire()
phase.append(None) phase.append(None)
start_new_thread(f, ()) start_new_thread(f, ())
while len(phase) == 0: while not phase:
_wait() _wait()
_wait() _wait()
self.assertEqual(len(phase), 1) self.assertEqual(len(phase), 1)
...@@ -436,9 +437,10 @@ class BaseSemaphoreTests(BaseTestCase): ...@@ -436,9 +437,10 @@ class BaseSemaphoreTests(BaseTestCase):
raise NotImplementedError() raise NotImplementedError()
def test_constructor(self): def test_constructor(self):
self.assertRaises(ValueError, self.semtype, value = -1) self.assertRaises(ValueError, self.semtype, value=-1)
# Py3 doesn't have sys.maxint # Py3 doesn't have sys.maxint
self.assertRaises(ValueError, self.semtype, value = -getattr(sys, 'maxint', getattr(sys, 'maxsize', None))) self.assertRaises(ValueError, self.semtype,
value=-getattr(sys, 'maxint', getattr(sys, 'maxsize', None)))
def test_acquire(self): def test_acquire(self):
sem = self.semtype(1) sem = self.semtype(1)
...@@ -509,7 +511,7 @@ class BaseSemaphoreTests(BaseTestCase): ...@@ -509,7 +511,7 @@ class BaseSemaphoreTests(BaseTestCase):
# There can be a thread switch between acquiring the semaphore and # There can be a thread switch between acquiring the semaphore and
# appending the result, therefore results will not necessarily be # appending the result, therefore results will not necessarily be
# ordered. # ordered.
self.assertEqual(sorted(results), [False] * 7 + [True] * 3 ) self.assertEqual(sorted(results), [False] * 7 + [True] * 3)
def test_default_value(self): def test_default_value(self):
# The default initial value is 1. # The default initial value is 1.
...@@ -534,7 +536,7 @@ class BaseSemaphoreTests(BaseTestCase): ...@@ -534,7 +536,7 @@ class BaseSemaphoreTests(BaseTestCase):
with sem: with sem:
self.assertFalse(sem.acquire(False)) self.assertFalse(sem.acquire(False))
if err: if err:
raise err raise err # pylint:disable=raising-bad-type
_with() _with()
self.assertTrue(sem.acquire(False)) self.assertTrue(sem.acquire(False))
sem.release() sem.release()
...@@ -603,7 +605,7 @@ class BarrierTests(BaseTestCase): ...@@ -603,7 +605,7 @@ class BarrierTests(BaseTestCase):
""" """
Test that a barrier is passed in lockstep Test that a barrier is passed in lockstep
""" """
results = [[],[]] results = [[], []]
def f(): def f():
self.multipass(results, passes) self.multipass(results, passes)
self.run_threads(f) self.run_threads(f)
...@@ -657,7 +659,6 @@ class BarrierTests(BaseTestCase): ...@@ -657,7 +659,6 @@ class BarrierTests(BaseTestCase):
results2.append(True) results2.append(True)
except RuntimeError: except RuntimeError:
self.barrier.abort() self.barrier.abort()
pass
self.run_threads(f) self.run_threads(f)
self.assertEqual(len(results1), 0) self.assertEqual(len(results1), 0)
...@@ -713,7 +714,7 @@ class BarrierTests(BaseTestCase): ...@@ -713,7 +714,7 @@ class BarrierTests(BaseTestCase):
results2.append(True) results2.append(True)
except RuntimeError: except RuntimeError:
self.barrier.abort() self.barrier.abort()
pass
# Synchronize and reset the barrier. Must synchronize first so # Synchronize and reset the barrier. Must synchronize first so
# that everyone has left it when we reset, and after so that no # that everyone has left it when we reset, and after so that no
# one enters it before the reset. # one enters it before the reset.
......
...@@ -133,7 +133,7 @@ class Test(unittest.TestCase): ...@@ -133,7 +133,7 @@ class Test(unittest.TestCase):
if hasattr(self.stdlib_module, name): if hasattr(self.stdlib_module, name):
raise AssertionError("'%r' is not an extension, it is found in %r" % (name, self.stdlib_module)) raise AssertionError("'%r' is not an extension, it is found in %r" % (name, self.stdlib_module))
def check_completeness(self): def check_completeness(self): # pylint:disable=too-many-branches
"""Check that __all__ (or dir()) of the corresponsing stdlib is a subset of __all__ of this module""" """Check that __all__ (or dir()) of the corresponsing stdlib is a subset of __all__ of this module"""
missed = [] missed = []
for name in self.stdlib_all: for name in self.stdlib_all:
......
...@@ -36,10 +36,10 @@ class Test(greentest.TestCase): ...@@ -36,10 +36,10 @@ class Test(greentest.TestCase):
try: try:
state.append('start') state.append('start')
gevent.sleep(DELAY * 3.0) gevent.sleep(DELAY * 3.0)
except: except: # pylint:disable=bare-except
state.append('except') state.append('except')
# catching GreenletExit # catching GreenletExit
pass
state.append('finished') state.append('finished')
g = gevent.spawn(test) g = gevent.spawn(test)
...@@ -68,7 +68,9 @@ class Test(greentest.TestCase): ...@@ -68,7 +68,9 @@ class Test(greentest.TestCase):
def _test_wait_read_invalid_switch(self, sleep): def _test_wait_read_invalid_switch(self, sleep):
sock1, sock2 = socket.socketpair() sock1, sock2 = socket.socketpair()
try: try:
p = gevent.spawn(util.wrap_errors(AssertionError, socket.wait_read), sock1.fileno()) p = gevent.spawn(util.wrap_errors(AssertionError,
socket.wait_read), # pylint:disable=no-member
sock1.fileno())
gevent.get_hub().loop.run_callback(switch_None, p) gevent.get_hub().loop.run_callback(switch_None, p)
if sleep is not None: if sleep is not None:
gevent.sleep(sleep) gevent.sleep(sleep)
......
from __future__ import print_function from __future__ import print_function
import gevent.monkey; gevent.monkey.patch_all() import gevent.monkey
gevent.monkey.patch_all()
import gevent import gevent
import os import os
......
...@@ -6,11 +6,11 @@ import test__core_loop_run # this runs main tests, fails if signal() is not call ...@@ -6,11 +6,11 @@ import test__core_loop_run # this runs main tests, fails if signal() is not call
assert test__core_loop_run # pyflakes assert test__core_loop_run # pyflakes
from gevent.hub import signal as hub_signal from gevent.hub import signal as hub_signal
from gevent import signal from gevent import signal as top_signal # pylint:disable=reimported
assert gevent.signal is hub_signal assert gevent.signal is hub_signal
assert gevent.signal is signal assert gevent.signal is top_signal
assert hasattr(gevent.signal, 'signal') assert hasattr(gevent.signal, 'signal')
s = signal(2, sys.stderr.write, 'INTERRUPT') s = top_signal(2, sys.stderr.write, 'INTERRUPT')
assert isinstance(s, signal) assert isinstance(s, top_signal)
assert isinstance(s, hub_signal) assert isinstance(s, hub_signal)
...@@ -94,7 +94,7 @@ class TestTimerResolution(Test): ...@@ -94,7 +94,7 @@ class TestTimerResolution(Test):
# On CI, with *all* backends, sometimes we get timer values of # On CI, with *all* backends, sometimes we get timer values of
# 0.02 or higher. # 0.02 or higher.
@reraises_flaky_timeout(AssertionError) @reraises_flaky_timeout(AssertionError)
def test_resolution(self): def test_resolution(self): # pylint:disable=too-many-locals
# Make sure that having an active IO watcher # Make sure that having an active IO watcher
# doesn't badly throw off our timer resolution. # doesn't badly throw off our timer resolution.
# (This was a specific problem with libuv) # (This was a specific problem with libuv)
......
...@@ -14,7 +14,7 @@ class TestExec(unittest.TestCase): ...@@ -14,7 +14,7 @@ class TestExec(unittest.TestCase):
def make_exec_test(path, module): def make_exec_test(path, module):
def test(self): def test(_):
#sys.stderr.write('%s %s\n' % (module, path)) #sys.stderr.write('%s %s\n' % (module, path))
with open(path, 'rb') as f: with open(path, 'rb') as f:
src = f.read() src = f.read()
...@@ -24,8 +24,8 @@ def make_exec_test(path, module): ...@@ -24,8 +24,8 @@ def make_exec_test(path, module):
test.__name__ = name test.__name__ = name
setattr(TestExec, name, test) setattr(TestExec, name, test)
def make_all_tests():
for path, module in walk_modules(): for path, module in walk_modules():
ignored = False ignored = False
for x in NON_APPLICABLE_SUFFIXES: for x in NON_APPLICABLE_SUFFIXES:
if module.endswith(x): if module.endswith(x):
...@@ -37,5 +37,7 @@ for path, module in walk_modules(): ...@@ -37,5 +37,7 @@ for path, module in walk_modules():
make_exec_test(path, module) make_exec_test(path, module)
make_all_tests()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -142,7 +142,7 @@ class Test(greentest.TestCase): ...@@ -142,7 +142,7 @@ class Test(greentest.TestCase):
def f(): def f():
try: try:
gevent.sleep(1.5) gevent.sleep(1.5)
except: except: # pylint:disable=bare-except
gevent.sleep(1) gevent.sleep(1)
p1 = GreenletSubclass.spawn(f) p1 = GreenletSubclass.spawn(f)
p2 = GreenletSubclass.spawn(f) p2 = GreenletSubclass.spawn(f)
......
...@@ -23,7 +23,7 @@ def main(): ...@@ -23,7 +23,7 @@ def main():
workers = [gevent.spawn(worker, i) for i in range(3)] workers = [gevent.spawn(worker, i) for i in range(3)]
workers.append(done_worker) workers.append(done_worker)
for g in gevent.iwait(workers): for _ in gevent.iwait(workers):
finished += 1 finished += 1
# Simulate doing something that causes greenlets to switch; # Simulate doing something that causes greenlets to switch;
# a non-zero timeout is crucial # a non-zero timeout is crucial
......
...@@ -160,7 +160,7 @@ class TestGeventLocal(greentest.TestCase): ...@@ -160,7 +160,7 @@ class TestGeventLocal(greentest.TestCase):
self.assertEqual(a.initialized, 2) self.assertEqual(a.initialized, 2)
# The slot overrides dict values # The slot overrides dict values
a.__dict__['initialized'] = 42 a.__dict__['initialized'] = 42 # pylint:disable=unsupported-assignment-operation
self.assertEqual(a.initialized, 2) self.assertEqual(a.initialized, 2)
# Deleting the slot deletes the slot, but not the dict # Deleting the slot deletes the slot, but not the dict
......
import sys import sys
import unittest
from gevent.testing import TestCase, main from gevent.testing import TestCase, main
import gevent import gevent
from gevent.timeout import Timeout from gevent.timeout import Timeout
@unittest.skipUnless(
hasattr(sys, 'gettotalrefcount'),
"Needs debug build"
)
class TestQueue(TestCase): class TestQueue(TestCase):
# pylint:disable=bare-except,no-member
def test(self): def test(self):
result = '' result = ''
...@@ -43,12 +47,10 @@ class TestQueue(TestCase): ...@@ -43,12 +47,10 @@ class TestQueue(TestCase):
result += '%s' % sys.gettotalrefcount() result += '%s' % sys.gettotalrefcount()
a, b, c = result.split() _, b, c = result.split()
assert b == c, 'total refcount mismatch: %s' % result assert b == c, 'total refcount mismatch: %s' % result
if not hasattr(sys, 'gettotalrefcount'):
del TestQueue
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -16,7 +16,7 @@ def _inner_lock(lock): ...@@ -16,7 +16,7 @@ def _inner_lock(lock):
def checkLocks(kind, ignore_none=True): def checkLocks(kind, ignore_none=True):
handlers = logging._handlerList handlers = logging._handlerList
assert len(handlers) > 0 assert handlers
for weakref in handlers: for weakref in handlers:
# In py26, these are actual handlers, not weakrefs # In py26, these are actual handlers, not weakrefs
......
...@@ -11,7 +11,7 @@ pid = None ...@@ -11,7 +11,7 @@ pid = None
awaiting_child = [] awaiting_child = []
def handle_sigchld(*args): def handle_sigchld(*_args):
# Make sure we can do a blocking operation # Make sure we can do a blocking operation
gevent.sleep() gevent.sleep()
# Signal completion # Signal completion
......
...@@ -16,12 +16,12 @@ import sys ...@@ -16,12 +16,12 @@ import sys
import signal import signal
import subprocess import subprocess
def _waitpid(pid): def _waitpid(p):
try: try:
_, stat = os.waitpid(pid, 0) _, stat = os.waitpid(p, 0)
except OSError: except OSError:
# Interrupted system call # Interrupted system call
_, stat = os.waitpid(pid, 0) _, stat = os.waitpid(p, 0)
assert stat == 0, stat assert stat == 0, stat
if hasattr(signal, 'SIGCHLD'): if hasattr(signal, 'SIGCHLD'):
......
...@@ -78,7 +78,7 @@ class TestCoroutinePool(unittest.TestCase): ...@@ -78,7 +78,7 @@ class TestCoroutinePool(unittest.TestCase):
timer_fired.append(True) timer_fired.append(True)
def some_work(): def some_work():
gevent.timer(0, fire_timer) gevent.timer(0, fire_timer) # pylint:disable=no-member
pool = self.klass(2) pool = self.klass(2)
pool.apply(some_work) pool.apply(some_work)
......
...@@ -611,10 +611,12 @@ class TestChunkedPost(TestCase): ...@@ -611,10 +611,12 @@ class TestChunkedPost(TestCase):
if env['PATH_INFO'] == '/a': if env['PATH_INFO'] == '/a':
data = env['wsgi.input'].read(6) data = env['wsgi.input'].read(6)
return [data] return [data]
elif env['PATH_INFO'] == '/b':
if env['PATH_INFO'] == '/b':
lines = [x for x in iter(lambda: env['wsgi.input'].read(6), b'')] lines = [x for x in iter(lambda: env['wsgi.input'].read(6), b'')]
return lines return lines
elif env['PATH_INFO'] == '/c':
if env['PATH_INFO'] == '/c':
return [x for x in iter(lambda: env['wsgi.input'].read(1), b'')] return [x for x in iter(lambda: env['wsgi.input'].read(1), b'')]
def test_014_chunked_post(self): def test_014_chunked_post(self):
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
are not leaked by the hub. are not leaked by the hub.
""" """
from __future__ import print_function from __future__ import print_function
from _socket import socket from _socket import socket as c_socket
import sys import sys
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
# Python3 enforces that __weakref__ appears only once, # Python3 enforces that __weakref__ appears only once,
...@@ -32,9 +32,9 @@ if sys.version_info[0] >= 3: ...@@ -32,9 +32,9 @@ if sys.version_info[0] >= 3:
# (because socket.socket defines __slots__ with __weakref__), # (because socket.socket defines __slots__ with __weakref__),
# so import socket.socket before that can happen. # so import socket.socket before that can happen.
__import__('socket') __import__('socket')
Socket = socket Socket = c_socket
else: else:
class Socket(socket): class Socket(c_socket):
"Something we can have a weakref to" "Something we can have a weakref to"
import _socket import _socket
...@@ -117,7 +117,7 @@ def run_interaction(run_client): ...@@ -117,7 +117,7 @@ def run_interaction(run_client):
# strong refs to the socket still around. # strong refs to the socket still around.
try: try:
sleep(0.1 + SOCKET_TIMEOUT) sleep(0.1 + SOCKET_TIMEOUT)
except Exception: except Exception: # pylint:disable=broad-except
pass pass
return w return w
...@@ -139,7 +139,8 @@ def run_and_check(run_client): ...@@ -139,7 +139,8 @@ def run_and_check(run_client):
@greentest.skipOnCI("Often fail with timeouts or force closed connections; not sure why.") @greentest.skipOnCI("Often fail with timeouts or force closed connections; not sure why.")
@greentest.skipIf(greentest.RUN_LEAKCHECKS and greentest.PY3, @greentest.skipIf(
greentest.RUN_LEAKCHECKS and greentest.PY3,
"Often fail with force closed connections; not sure why. " "Often fail with force closed connections; not sure why. "
) )
class Test(greentest.TestCase): class Test(greentest.TestCase):
......
...@@ -14,7 +14,7 @@ from gevent.server import StreamServer ...@@ -14,7 +14,7 @@ from gevent.server import StreamServer
class SimpleStreamServer(StreamServer): class SimpleStreamServer(StreamServer):
def handle(self, client_socket, _address): def handle(self, client_socket, _address): # pylint:disable=method-hidden
fd = client_socket.makefile() fd = client_socket.makefile()
try: try:
request_line = fd.readline() request_line = fd.readline()
...@@ -487,7 +487,7 @@ class TestSSLGetCertificate(TestCase): ...@@ -487,7 +487,7 @@ class TestSSLGetCertificate(TestCase):
self.init_server() self.init_server()
server_host, server_port, _family = self.get_server_host_port_family() server_host, server_port, _family = self.get_server_host_port_family()
ssl.get_server_certificate((server_host, server_port)) ssl.get_server_certificate((server_host, server_port)) # pylint:disable=no-member
def test_wrap_socket_and_handle_wrap_failure(self): def test_wrap_socket_and_handle_wrap_failure(self):
......
...@@ -6,7 +6,7 @@ import pkg_resources ...@@ -6,7 +6,7 @@ import pkg_resources
try: try:
cffi_version = pkg_resources.get_distribution('cffi').parsed_version cffi_version = pkg_resources.get_distribution('cffi').parsed_version
except Exception: except Exception: # pylint:disable=broad-except
# No cffi installed. Shouldn't happen to gevent standard tests, # No cffi installed. Shouldn't happen to gevent standard tests,
# but maybe some downstream distributor removed it. # but maybe some downstream distributor removed it.
cffi_version = None cffi_version = None
...@@ -50,7 +50,7 @@ if hasattr(signal, 'SIGALRM'): ...@@ -50,7 +50,7 @@ if hasattr(signal, 'SIGALRM'):
except Expected as ex: except Expected as ex:
assert str(ex) == 'TestSignal', ex assert str(ex) == 'TestSignal', ex
finally: finally:
sig.cancel() sig.cancel() # pylint:disable=no-member
@greentest.skipIf((greentest.PY3 @greentest.skipIf((greentest.PY3
......
...@@ -320,7 +320,7 @@ class TestTCP(greentest.TestCase): ...@@ -320,7 +320,7 @@ class TestTCP(greentest.TestCase):
# Issue 944 # Issue 944
# If we have SOCK_CLOEXEC or similar, we shouldn't be passing # If we have SOCK_CLOEXEC or similar, we shouldn't be passing
# them through to the getaddrinfo call that connect() makes # them through to the getaddrinfo call that connect() makes
SOCK_CLOEXEC = socket.SOCK_CLOEXEC SOCK_CLOEXEC = socket.SOCK_CLOEXEC # pylint:disable=no-member
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM | SOCK_CLOEXEC) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM | SOCK_CLOEXEC)
def accept_once(): def accept_once():
...@@ -421,7 +421,7 @@ class TestFunctions(greentest.TestCase): ...@@ -421,7 +421,7 @@ class TestFunctions(greentest.TestCase):
gevent.sleep(10) gevent.sleep(10)
with self.assertRaises(gevent.socket.timeout): with self.assertRaises(gevent.socket.timeout):
gevent.socket.wait(io(), timeout=0.01) gevent.socket.wait(io(), timeout=0.01) # pylint:disable=no-member
def test_signatures(self): def test_signatures(self):
......
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# pylint:disable=broad-except
import gevent import gevent
from gevent import monkey from gevent import monkey
...@@ -83,9 +83,9 @@ def run(function, *args): ...@@ -83,9 +83,9 @@ def run(function, *args):
return result, delta return result, delta
def log_call(result, time, function, *args): def log_call(result, runtime, function, *args):
log(format_call(function, args)) log(format_call(function, args))
log_fresult(result, time) log_fresult(result, runtime)
def compare_relaxed(a, b): def compare_relaxed(a, b):
...@@ -332,9 +332,11 @@ class TestCase(greentest.TestCase): ...@@ -332,9 +332,11 @@ class TestCase(greentest.TestCase):
# If we're using the ares resolver, allow the real resolver to generate an # If we're using the ares resolver, allow the real resolver to generate an
# error that the ares resolver actually gets an answer to. # error that the ares resolver actually gets an answer to.
if (RESOLVER_NOT_SYSTEM if (
RESOLVER_NOT_SYSTEM
and isinstance(real_result, errors) and isinstance(real_result, errors)
and not isinstance(gevent_result, errors)): and not isinstance(gevent_result, errors)
):
return return
# From 2.7 on, assertEqual does a better job highlighting the results than we would # From 2.7 on, assertEqual does a better job highlighting the results than we would
...@@ -453,7 +455,7 @@ class SanitizedHostsFile(HostsFile): ...@@ -453,7 +455,7 @@ class SanitizedHostsFile(HostsFile):
# the system's etc hosts? # the system's etc hosts?
class TestEtcHosts(TestCase): class TestEtcHosts(TestCase):
MAX_HOSTS = os.getenv('GEVENTTEST_MAX_ETC_HOSTS', 10) MAX_HOSTS = int(os.getenv('GEVENTTEST_MAX_ETC_HOSTS', '10'))
@classmethod @classmethod
def populate_tests(cls): def populate_tests(cls):
...@@ -493,7 +495,7 @@ class TestFamily(TestCase): ...@@ -493,7 +495,7 @@ class TestFamily(TestCase):
cls._result = getattr(socket, 'getaddrinfo')(TestGeventOrg.HOSTNAME, None) cls._result = getattr(socket, 'getaddrinfo')(TestGeventOrg.HOSTNAME, None)
return cls._result return cls._result
def assert_error(self, error, function, *args): def assert_error(self, error, function, *args): # pylint:disable=arguments-differ
try: try:
result = function(*args) result = function(*args)
raise AssertionError('%s: Expected to raise %s, instead returned %r' % (function, error, result)) raise AssertionError('%s: Expected to raise %s, instead returned %r' % (function, error, result))
......
#!/usr/bin/python #!/usr/bin/python
from gevent import monkey; monkey.patch_all() from gevent import monkey
import sys monkey.patch_all()
import gevent.testing as greentest
import unittest
try: try:
import httplib import httplib
except ImportError: except ImportError:
from http import client as httplib from http import client as httplib
import socket import socket
if not hasattr(socket, 'ssl'):
sys.exit(0) import gevent.testing as greentest
@unittest.skipUnless(
hasattr(socket, 'ssl'),
"Needs socket.ssl"
)
class AmazonHTTPSTests(greentest.TestCase): class AmazonHTTPSTests(greentest.TestCase):
__timeout__ = 30 __timeout__ = 30
...@@ -25,7 +30,7 @@ class AmazonHTTPSTests(greentest.TestCase): ...@@ -25,7 +30,7 @@ class AmazonHTTPSTests(greentest.TestCase):
def test_str_and_repr(self): def test_str_and_repr(self):
conn = socket.socket() conn = socket.socket()
conn.connect(('sdb.amazonaws.com', 443)) conn.connect(('sdb.amazonaws.com', 443))
ssl_conn = socket.ssl(conn) ssl_conn = socket.ssl(conn) # pylint:disable=no-member
assert str(ssl_conn) assert str(ssl_conn)
assert repr(ssl_conn) assert repr(ssl_conn)
......
...@@ -28,7 +28,7 @@ class TestSSL(test__socket.TestTCP): ...@@ -28,7 +28,7 @@ class TestSSL(test__socket.TestTCP):
self._close_on_teardown(raw_listener) self._close_on_teardown(raw_listener)
return listener return listener
def create_connection(self, *args, **kwargs): def create_connection(self, *args, **kwargs): # pylint:disable=arguments-differ
return ssl.wrap_socket(super(TestSSL, self).create_connection(*args, **kwargs)) return ssl.wrap_socket(super(TestSSL, self).create_connection(*args, **kwargs))
# The SSL library can take a long time to buffer the large amount of data we're trying # The SSL library can take a long time to buffer the large amount of data we're trying
......
...@@ -222,7 +222,7 @@ class Test(greentest.TestCase): ...@@ -222,7 +222,7 @@ class Test(greentest.TestCase):
def test_check_output_keyword_error(self): def test_check_output_keyword_error(self):
try: try:
subprocess.check_output([sys.executable, '-c', 'import sys; sys.exit(44)']) subprocess.check_output([sys.executable, '-c', 'import sys; sys.exit(44)'])
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e: # pylint:disable=no-member
self.assertEqual(e.returncode, 44) self.assertEqual(e.returncode, 44)
else: else:
raise AssertionError('must fail with CalledProcessError') raise AssertionError('must fail with CalledProcessError')
...@@ -282,7 +282,6 @@ class Test(greentest.TestCase): ...@@ -282,7 +282,6 @@ class Test(greentest.TestCase):
# If the file is in universal_newlines mode, we should always get a str when # If the file is in universal_newlines mode, we should always get a str when
# there is no output. # there is no output.
# https://github.com/gevent/gevent/pull/939 # https://github.com/gevent/gevent/pull/939
kwargs = {'universal_newlines': True}
self.__test_no_output({'universal_newlines': True}, str) self.__test_no_output({'universal_newlines': True}, str)
@greentest.skipIf(sys.version_info[:2] < (3, 6), "Need encoding argument") @greentest.skipIf(sys.version_info[:2] < (3, 6), "Need encoding argument")
...@@ -397,11 +396,11 @@ class RunFuncTestCase(greentest.TestCase): ...@@ -397,11 +396,11 @@ class RunFuncTestCase(greentest.TestCase):
# call() function with sequence argument # call() function with sequence argument
cp = self.run_python("import sys; sys.exit(47)") cp = self.run_python("import sys; sys.exit(47)")
self.assertEqual(cp.returncode, 47) self.assertEqual(cp.returncode, 47)
with self.assertRaises(subprocess.CalledProcessError): with self.assertRaises(subprocess.CalledProcessError): # pylint:disable=no-member
cp.check_returncode() cp.check_returncode()
def test_check(self): def test_check(self):
with self.assertRaises(subprocess.CalledProcessError) as c: with self.assertRaises(subprocess.CalledProcessError) as c: # pylint:disable=no-member
self.run_python("import sys; sys.exit(47)", check=True) self.run_python("import sys; sys.exit(47)", check=True)
self.assertEqual(c.exception.returncode, 47) self.assertEqual(c.exception.returncode, 47)
......
...@@ -35,7 +35,7 @@ class Test(greentest.TestCase): ...@@ -35,7 +35,7 @@ class Test(greentest.TestCase):
thread.start() thread.start()
try: try:
thread.join() thread.join()
except: except: # pylint:disable=bare-except
# XXX: This can raise LoopExit in some cases. # XXX: This can raise LoopExit in some cases.
greentest.reraiseFlakyTestRaceCondition() greentest.reraiseFlakyTestRaceCondition()
......
from gevent import monkey; monkey.patch_all() from gevent import monkey; monkey.patch_all()
import threading import threading
localdata = threading.local() localdata = threading.local()
localdata.x = "hello" localdata.x = "hello"
assert localdata.x == 'hello' assert localdata.x == 'hello'
...@@ -9,7 +10,7 @@ success = [] ...@@ -9,7 +10,7 @@ success = []
def func(): def func():
try: try:
localdata.x getattr(localdata, 'x')
raise AssertionError('localdata.x must raise AttributeError') raise AssertionError('localdata.x must raise AttributeError')
except AttributeError: except AttributeError:
pass pass
......
...@@ -89,7 +89,7 @@ class Test(greentest.TestCase): ...@@ -89,7 +89,7 @@ class Test(greentest.TestCase):
except TypeError as ex: except TypeError as ex:
self.assertTrue(greentest.PY3, "Py3 raises a TypeError for non-BaseExceptions") self.assertTrue(greentest.PY3, "Py3 raises a TypeError for non-BaseExceptions")
self.assert_type_err(ex) self.assert_type_err(ex)
except: except: # pylint:disable=bare-except
self.assertTrue(greentest.PY2, "Old style classes can only be raised on Py2") self.assertTrue(greentest.PY2, "Old style classes can only be raised on Py2")
t = sys.exc_info()[0] t = sys.exc_info()[0]
self.assertEqual(t, OldStyle) self.assertEqual(t, OldStyle)
...@@ -103,7 +103,7 @@ class Test(greentest.TestCase): ...@@ -103,7 +103,7 @@ class Test(greentest.TestCase):
except TypeError as ex: except TypeError as ex:
self.assertTrue(greentest.PY3, "Py3 raises a TypeError for non-BaseExceptions") self.assertTrue(greentest.PY3, "Py3 raises a TypeError for non-BaseExceptions")
self.assert_type_err(ex) self.assert_type_err(ex)
except: except: # pylint:disable=bare-except
self.assertTrue(greentest.PY2, "Old style classes can only be raised on Py2") self.assertTrue(greentest.PY2, "Old style classes can only be raised on Py2")
t = sys.exc_info()[0] t = sys.exc_info()[0]
self.assertEqual(t, OldStyle) self.assertEqual(t, OldStyle)
......
...@@ -231,6 +231,9 @@ class ThreadTests(unittest.TestCase): ...@@ -231,6 +231,9 @@ class ThreadTests(unittest.TestCase):
worker_saw_exception = threading.Event() worker_saw_exception = threading.Event()
class Worker(threading.Thread): class Worker(threading.Thread):
id = None
finished = False
def run(self): def run(self):
self.id = thread.get_ident() self.id = thread.get_ident()
self.finished = False self.finished = False
...@@ -278,7 +281,7 @@ class ThreadTests(unittest.TestCase): ...@@ -278,7 +281,7 @@ class ThreadTests(unittest.TestCase):
def test_limbo_cleanup(self): def test_limbo_cleanup(self):
# Issue 7481: Failure to start thread should cleanup the limbo map. # Issue 7481: Failure to start thread should cleanup the limbo map.
def fail_new_thread(*args): def fail_new_thread(*_args):
raise thread.error() raise thread.error()
_start_new_thread = threading._start_new_thread _start_new_thread = threading._start_new_thread
threading._start_new_thread = fail_new_thread threading._start_new_thread = fail_new_thread
...@@ -406,7 +409,7 @@ class ThreadTests(unittest.TestCase): ...@@ -406,7 +409,7 @@ class ThreadTests(unittest.TestCase):
kwargs={'yet_another': self}) kwargs={'yet_another': self})
self.thread.start() self.thread.start()
def _run(self, other_ref, yet_another): def _run(self, _other_ref, _yet_another):
if self.should_raise: if self.should_raise:
raise SystemExit raise SystemExit
...@@ -542,23 +545,24 @@ class ThreadJoinOnShutdown(unittest.TestCase): ...@@ -542,23 +545,24 @@ class ThreadJoinOnShutdown(unittest.TestCase):
class ThreadingExceptionTests(unittest.TestCase): class ThreadingExceptionTests(unittest.TestCase):
# A RuntimeError should be raised if Thread.start() is called # A RuntimeError should be raised if Thread.start() is called
# multiple times. # multiple times.
# pylint:disable=bad-thread-instantiation
def test_start_thread_again(self): def test_start_thread_again(self):
thread = threading.Thread() thread_ = threading.Thread()
thread.start() thread_.start()
self.assertRaises(RuntimeError, thread.start) self.assertRaises(RuntimeError, thread_.start)
def test_joining_current_thread(self): def test_joining_current_thread(self):
current_thread = threading.current_thread() current_thread = threading.current_thread()
self.assertRaises(RuntimeError, current_thread.join) self.assertRaises(RuntimeError, current_thread.join)
def test_joining_inactive_thread(self): def test_joining_inactive_thread(self):
thread = threading.Thread() thread_ = threading.Thread()
self.assertRaises(RuntimeError, thread.join) self.assertRaises(RuntimeError, thread_.join)
def test_daemonize_active_thread(self): def test_daemonize_active_thread(self):
thread = threading.Thread() thread_ = threading.Thread()
thread.start() thread_.start()
self.assertRaises(RuntimeError, setattr, thread, "daemon", True) self.assertRaises(RuntimeError, setattr, thread_, "daemon", True)
class LockTests(lock_tests.LockTests): class LockTests(lock_tests.LockTests):
......
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