Commit d4d19fb0 authored by Jason Madden's avatar Jason Madden

Get the tests running.

parent 71b5c5cf
...@@ -35,9 +35,9 @@ Makefile.ext ...@@ -35,9 +35,9 @@ Makefile.ext
MANIFEST MANIFEST
*_flymake.py *_flymake.py
src/greentest/.coverage\.* src/gevent/tests/.coverage\.*
src/greentest/htmlcov htmlcov/
src/greentest/.coverage .coverage
doc/_build doc/_build
doc/__pycache__ doc/__pycache__
......
...@@ -98,7 +98,7 @@ ignored-classes=SSLContext, SSLSocket, greenlet, Greenlet, parent, dead ...@@ -98,7 +98,7 @@ ignored-classes=SSLContext, SSLSocket, greenlet, Greenlet, parent, dead
# (useful for modules/projects where namespaces are manipulated during runtime # (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It # and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching. # supports qualified module names, as well as Unix pattern matching.
ignored-modules=gevent._corecffi,gevent.os,os,greenlet,threading,gevent.libev.corecffi ignored-modules=gevent._corecffi,gevent.os,os,greenlet,threading,gevent.libev.corecffi,gevent.socket,gevent.core
[DESIGN] [DESIGN]
max-attributes=12 max-attributes=12
......
...@@ -22,7 +22,7 @@ clean: ...@@ -22,7 +22,7 @@ clean:
rm -rf src/gevent/libev/*.o src/gevent/libuv/*.o src/gevent/*.o rm -rf src/gevent/libev/*.o src/gevent/libuv/*.o src/gevent/*.o
rm -rf src/gevent/__pycache__ src/greentest/__pycache__ src/greentest/greentest/__pycache__ src/gevent/libev/__pycache__ rm -rf src/gevent/__pycache__ src/greentest/__pycache__ src/greentest/greentest/__pycache__ src/gevent/libev/__pycache__
rm -rf src/gevent/*.pyc src/greentest/*.pyc src/gevent/libev/*.pyc rm -rf src/gevent/*.pyc src/greentest/*.pyc src/gevent/libev/*.pyc
rm -rf src/greentest/htmlcov src/greentest/.coverage rm -rf htmlcov .coverage
rm -rf build rm -rf build
distclean: clean distclean: clean
...@@ -57,28 +57,25 @@ test_prelim: ...@@ -57,28 +57,25 @@ test_prelim:
basictest: test_prelim basictest: test_prelim
@${PYTHON} scripts/travis.py fold_start basictest "Running basic tests" @${PYTHON} scripts/travis.py fold_start basictest "Running basic tests"
cd src/greentest && GEVENT_RESOLVER=thread ${PYTHON} testrunner.py --config known_failures.py --quiet GEVENT_RESOLVER=thread ${PYTHON} -mgevent.tests --config known_failures.py --quiet
@${PYTHON} scripts/travis.py fold_end basictest @${PYTHON} scripts/travis.py fold_end basictest
alltest: basictest alltest: basictest
@${PYTHON} scripts/travis.py fold_start ares "Running c-ares tests" @${PYTHON} scripts/travis.py fold_start ares "Running c-ares tests"
cd src/greentest && GEVENT_RESOLVER=ares ${PYTHON} testrunner.py --config known_failures.py --ignore tests_that_dont_use_resolver.txt --quiet GEVENT_RESOLVER=ares ${PYTHON} -mgevent.tests --config known_failures.py --ignore tests_that_dont_use_resolver.txt --quiet
@${PYTHON} scripts/travis.py fold_end ares @${PYTHON} scripts/travis.py fold_end ares
@${PYTHON} scripts/travis.py fold_start dnspython "Running dnspython tests" @${PYTHON} scripts/travis.py fold_start dnspython "Running dnspython tests"
cd src/greentest && GEVENT_RESOLVER=dnspython ${PYTHON} testrunner.py --config known_failures.py --ignore tests_that_dont_use_resolver.txt --quiet GEVENT_RESOLVER=dnspython ${PYTHON} -mgevent.tests --config known_failures.py --ignore tests_that_dont_use_resolver.txt --quiet
@${PYTHON} scripts/travis.py fold_end dnspython @${PYTHON} scripts/travis.py fold_end dnspython
# In the past, we included all test files that had a reference to 'subprocess'' somewhere in their # In the past, we included all test files that had a reference to 'subprocess'' somewhere in their
# text. The monkey-patched stdlib tests were specifically included here. # text. The monkey-patched stdlib tests were specifically included here.
# However, we now always also test on AppVeyor (Windows) which only has GEVENT_FILE=thread, # However, we now always also test on AppVeyor (Windows) which only has GEVENT_FILE=thread,
# so we can save a lot of CI time by reducing the set and excluding the stdlib tests without # so we can save a lot of CI time by reducing the set and excluding the stdlib tests without
# losing any coverage. See the `threadfiletest` for what command used to run. # losing any coverage.
@${PYTHON} scripts/travis.py fold_start thread "Running GEVENT_FILE=thread tests" @${PYTHON} scripts/travis.py fold_start thread "Running GEVENT_FILE=thread tests"
cd src/greentest && GEVENT_FILE=thread ${PYTHON} testrunner.py --config known_failures.py test__*subprocess*.py --quiet cd src/gevent/tests && GEVENT_FILE=thread ${PYTHON} -mgevent.tests --config known_failures.py test__*subprocess*.py --quiet
@${PYTHON} scripts/travis.py fold_end thread @${PYTHON} scripts/travis.py fold_end thread
threadfiletest:
cd src/greentest && GEVENT_FILE=thread ${PYTHON} testrunner.py --config known_failures.py `grep -l subprocess test_*.py` --quiet
allbackendtest: allbackendtest:
@${PYTHON} scripts/travis.py fold_start default "Testing default backend" @${PYTHON} scripts/travis.py fold_start default "Testing default backend"
GEVENTTEST_COVERAGE=1 make alltest GEVENTTEST_COVERAGE=1 make alltest
...@@ -99,7 +96,7 @@ cffibackendtest: ...@@ -99,7 +96,7 @@ cffibackendtest:
leaktest: test_prelim leaktest: test_prelim
@${PYTHON} scripts/travis.py fold_start leaktest "Running leak tests" @${PYTHON} scripts/travis.py fold_start leaktest "Running leak tests"
cd src/greentest && GEVENT_RESOLVER=thread GEVENTTEST_LEAKCHECK=1 ${PYTHON} testrunner.py --config known_failures.py --quiet --ignore tests_that_dont_do_leakchecks.txt GEVENT_RESOLVER=thread GEVENTTEST_LEAKCHECK=1 ${PYTHON} -mgevent.tests --config known_failures.py --quiet --ignore tests_that_dont_do_leakchecks.txt
@${PYTHON} scripts/travis.py fold_end leaktest @${PYTHON} scripts/travis.py fold_end leaktest
@${PYTHON} scripts/travis.py fold_start default "Testing default backend pure python" @${PYTHON} scripts/travis.py fold_start default "Testing default backend pure python"
PURE_PYTHON=1 GEVENTTEST_COVERAGE=1 make basictest PURE_PYTHON=1 GEVENTTEST_COVERAGE=1 make basictest
...@@ -114,8 +111,8 @@ travis_test_linters: ...@@ -114,8 +111,8 @@ travis_test_linters:
make cffibackendtest make cffibackendtest
coverage_combine: coverage_combine:
coverage combine . src/greentest/ coverage combine . src/gevent/tests/
-coveralls --rcfile=src/greentest/.coveragerc -coveralls --rcfile=src/gevent/tests/.coveragerc
.PHONY: clean doc prospector lint travistest travis .PHONY: clean doc prospector lint travistest travis
......
...@@ -235,6 +235,7 @@ def discover(tests=None, ignore_files=None, ...@@ -235,6 +235,7 @@ def discover(tests=None, ignore_files=None,
# Thus, be sure to open and compare in binary mode. # Thus, be sure to open and compare in binary mode.
contents = f.read() contents = f.read()
if b'TESTRUNNER' in contents: # test__monkey_patching.py if b'TESTRUNNER' in contents: # test__monkey_patching.py
# XXX: Rework this to avoid importing.
module = __import__(filename.rsplit('.', 1)[0]) module = __import__(filename.rsplit('.', 1)[0])
for cmd, options in module.TESTRUNNER(): for cmd, options in module.TESTRUNNER():
if remove_options(cmd)[-1] in ignore: if remove_options(cmd)[-1] in ignore:
...@@ -260,7 +261,8 @@ def remove_options(lst): ...@@ -260,7 +261,8 @@ def remove_options(lst):
def load_list_from_file(filename): def load_list_from_file(filename):
result = [] result = []
if filename: if filename:
for x in open(filename): with open(filename) as f:
for x in f:
x = x.split('#', 1)[0].strip() x = x.split('#', 1)[0].strip()
if x: if x:
result.append(x) result.append(x)
......
...@@ -298,8 +298,18 @@ def run(command, **kwargs): ...@@ -298,8 +298,18 @@ def run(command, **kwargs):
return RunResult(result, out, name) return RunResult(result, out, name)
def find_setup_py_above(a_file):
"Return the directory containing setup.py somewhere above *a_file*"
root = os.path.dirname(os.path.abspath(a_file))
while not os.path.exists(os.path.join(root, 'setup.py')):
prev, root = root, os.path.dirname(root)
if root == prev:
# Let's avoid infinite loops at root
raise AssertionError('could not find my setup.py')
return root
class TestServer(unittest.TestCase): class TestServer(unittest.TestCase):
cwd = '../../examples/'
args = [] args = []
before_delay = 3 before_delay = 3
after_delay = 0.5 after_delay = 0.5
...@@ -307,6 +317,19 @@ class TestServer(unittest.TestCase): ...@@ -307,6 +317,19 @@ class TestServer(unittest.TestCase):
server = None # subclasses define this to be the path to the server.py server = None # subclasses define this to be the path to the server.py
start_kwargs = None start_kwargs = None
def find_setup_py(self):
"Return the directory containing setup.py"
return find_setup_py_above(__file__)
# XXX: We need to extend this if we want it to be useful
# for other packages; our __file__ won't work for them.
# We can look at the CWD, and we can look at the __file__ of the
# sys.modules[type(self).__module__].
@property
def cwd(self):
root = self.find_setup_py()
return os.path.join(root, 'examples')
def start(self): def start(self):
kwargs = self.start_kwargs or {} kwargs = self.start_kwargs or {}
return start([sys.executable, '-u', self.server] + self.args, cwd=self.cwd, **kwargs) return start([sys.executable, '-u', self.server] + self.args, cwd=self.cwd, **kwargs)
......
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANtb0+YrKuxevGpm
LrjaUhZSgz6zFAmuGFmKmUbdjmfv9zSmmdsQIksK++jK0Be9LeZy20j6ahOfuVa0
ufEmPoP7Fy4hXegKZR9cCWcIe/A6H2xWF1IIJLRTLaU8ol/I7T+um5HD5AwAwNPP
USNU0Eegmvp+xxWu3NX2m1Veot85AgMBAAECgYA3ZdZ673X0oexFlq7AAmrutkHt
CL7LvwrpOiaBjhyTxTeSNWzvtQBkIU8DOI0bIazA4UreAFffwtvEuPmonDb3F+Iq
SMAu42XcGyVZEl+gHlTPU9XRX7nTOXVt+MlRRRxL6t9GkGfUAXI3XxJDXW3c0vBK
UL9xqD8cORXOfE06rQJBAP8mEX1ERkR64Ptsoe4281vjTlNfIbs7NMPkUnrn9N/Y
BLhjNIfQ3HFZG8BTMLfX7kCS9D593DW5tV4Z9BP/c6cCQQDcFzCcVArNh2JSywOQ
ZfTfRbJg/Z5Lt9Fkngv1meeGNPgIMLN8Sg679pAOOWmzdMO3V706rNPzSVMME7E5
oPIfAkEA8pDddarP5tCvTTgUpmTFbakm0KoTZm2+FzHcnA4jRh+XNTjTOv98Y6Ik
eO5d1ZnKXseWvkZncQgxfdnMqqpj5wJAcNq/RVne1DbYlwWchT2Si65MYmmJ8t+F
0mcsULqjOnEMwf5e+ptq5LzwbyrHZYq5FNk7ocufPv/ZQrcSSC+cFwJBAKvOJByS
x56qyGeZLOQlWS2JS3KJo59XuLFGqcbgN9Om9xFa41Yb4N9NvplFivsvZdw3m1Q/
SPIXQuT8RMPDVNQ=
-----END PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIICVDCCAb2gAwIBAgIJANfHOBkZr8JOMA0GCSqGSIb3DQEBBQUAMF8xCzAJBgNV
BAYTAlhZMRcwFQYDVQQHEw5DYXN0bGUgQW50aHJheDEjMCEGA1UEChMaUHl0aG9u
IFNvZnR3YXJlIEZvdW5kYXRpb24xEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0xMDEw
MDgyMzAxNTZaFw0yMDEwMDUyMzAxNTZaMF8xCzAJBgNVBAYTAlhZMRcwFQYDVQQH
Ew5DYXN0bGUgQW50aHJheDEjMCEGA1UEChMaUHl0aG9uIFNvZnR3YXJlIEZvdW5k
YXRpb24xEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
gYkCgYEA21vT5isq7F68amYuuNpSFlKDPrMUCa4YWYqZRt2OZ+/3NKaZ2xAiSwr7
6MrQF70t5nLbSPpqE5+5VrS58SY+g/sXLiFd6AplH1wJZwh78DofbFYXUggktFMt
pTyiX8jtP66bkcPkDADA089RI1TQR6Ca+n7HFa7c1fabVV6i3zkCAwEAAaMYMBYw
FAYDVR0RBA0wC4IJbG9jYWxob3N0MA0GCSqGSIb3DQEBBQUAA4GBAHPctQBEQ4wd
BJ6+JcpIraopLn8BGhbjNWj40mmRqWB/NAWF6M5ne7KpGAu7tLeG4hb1zLaldK8G
lxy2GPSRF6LFS48dpEj2HbMv2nvv6xxalDMJ9+DicWgAKTQ6bcX2j3GUkCR0g/T1
CRlNBAAlvhKzO7Clpf9l0YKBEfraJByX
-----END CERTIFICATE-----
...@@ -2,5 +2,17 @@ ...@@ -2,5 +2,17 @@
from __future__ import print_function, absolute_import, division from __future__ import print_function, absolute_import, division
if __name__ == '__main__': if __name__ == '__main__':
# We expect to be running in this directory, to do test discovery
# etc, automatically.
import os
import os.path
this_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(this_dir)
# We also expect this directory to be on the path, because we
# try to import some test files by their bare name
import sys
sys.path.append(this_dir)
from gevent.testing import testrunner from gevent.testing import testrunner
testrunner.main() testrunner.main()
...@@ -7,12 +7,20 @@ import atexit ...@@ -7,12 +7,20 @@ import atexit
from gevent.testing import util from gevent.testing import util
# XXX: Generalize this so other packages can use it.
setup_py = util.find_setup_py_above(__file__)
greentest = os.path.join(setup_py, 'src', 'greentest')
TIMEOUT = 120 TIMEOUT = 120
directory = '%s.%s' % sys.version_info[:2] directory = '%s.%s' % sys.version_info[:2]
full_directory = '%s.%s.%s' % sys.version_info[:3] full_directory = '%s.%s.%s' % sys.version_info[:3]
if hasattr(sys, 'pypy_version_info'): if hasattr(sys, 'pypy_version_info'):
directory += 'pypy' directory += 'pypy'
full_directory += 'pypy' full_directory += 'pypy'
directory = os.path.join(greentest, directory)
full_directory = os.path.join(greentest, full_directory)
version = '%s.%s.%s' % sys.version_info[:3] version = '%s.%s.%s' % sys.version_info[:3]
if sys.version_info[3] == 'alpha': if sys.version_info[3] == 'alpha':
version += 'a%s' % sys.version_info[4] version += 'a%s' % sys.version_info[4]
......
from __future__ import print_function from __future__ import print_function
import doctest import doctest
import functools import functools
import os import os
import re import re
import sys import sys
import traceback
import unittest import unittest
import gevent import gevent
from gevent import socket from gevent import socket
from gevent.testing import walk_modules from gevent.testing import walk_modules
from gevent.testing import sysinfo from gevent.testing import sysinfo
from gevent.testing import util
# Ignore tracebacks: ZeroDivisionError # Ignore tracebacks: ZeroDivisionError
def myfunction(*args, **kwargs): def myfunction(*_args, **_kwargs):
pass pass
...@@ -44,29 +45,44 @@ if sysinfo.WIN: ...@@ -44,29 +45,44 @@ if sysinfo.WIN:
'gevent.subprocess', 'gevent.subprocess',
} }
if __name__ == '__main__': class Modules(object):
def __init__(self, allowed_modules):
self.allowed_modules = allowed_modules
self.modules = set()
for path, module in walk_modules():
self.add_module(module, path)
def add_module(self, name, path):
if self.allowed_modules and name not in self.allowed_modules:
return
if name in FORBIDDEN_MODULES:
return
self.modules.add((name, path))
def __bool__(self):
return bool(self.modules)
__nonzero__ = __bool__
def __iter__(self):
return iter(self.modules)
def main():
cwd = os.getcwd() cwd = os.getcwd()
try: try:
allowed_modules = sys.argv[1:] allowed_modules = sys.argv[1:]
sys.path.append('.') sys.path.append('.')
base = os.path.dirname(gevent.__file__) os.chdir(util.find_setup_py_above(__file__))
print(base)
os.chdir('../..')
globs = {'myfunction': myfunction, 'gevent': gevent, 'socket': socket} globs = {'myfunction': myfunction, 'gevent': gevent, 'socket': socket}
modules = set() modules = Modules(allowed_modules)
def add_module(name, path): modules.add_module('setup', 'setup.py')
if allowed_modules and name not in allowed_modules:
return
if name in FORBIDDEN_MODULES:
return
modules.add((name, path))
for path, module in walk_modules():
add_module(module, path)
add_module('setup', 'setup.py')
if not modules: if not modules:
sys.exit('No modules found matching %s' % ' '.join(allowed_modules)) sys.exit('No modules found matching %s' % ' '.join(allowed_modules))
...@@ -88,18 +104,18 @@ if __name__ == '__main__': ...@@ -88,18 +104,18 @@ if __name__ == '__main__':
with open(path, 'rb') as f: with open(path, 'rb') as f:
contents = f.read() contents = f.read()
if re.search(br'^\s*>>> ', contents, re.M): if re.search(br'^\s*>>> ', contents, re.M):
try:
s = doctest.DocTestSuite(m, extraglobs=globs, checker=checker) s = doctest.DocTestSuite(m, extraglobs=globs, checker=checker)
test_count = len(s._tests) # pylint: disable=W0212 test_count = len(s._tests)
print('%s (from %s): %s tests' % (m, path, test_count)) print('%s (from %s): %s tests' % (m, path, test_count))
suite.addTest(s) suite.addTest(s)
modules_count += 1 modules_count += 1
tests_count += test_count tests_count += test_count
except Exception:
traceback.print_exc()
sys.stderr.write('Failed to process %s\n\n' % path)
print('Total: %s tests in %s modules' % (tests_count, modules_count)) print('Total: %s tests in %s modules' % (tests_count, modules_count))
# TODO: Pass this off to unittest.main()
runner = unittest.TextTestRunner(verbosity=2) runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite) runner.run(suite)
finally: finally:
os.chdir(cwd) os.chdir(cwd)
if __name__ == '__main__':
main()
from gevent import monkey; monkey.patch_all(subprocess=True) from gevent import monkey
monkey.patch_all(subprocess=True)
import sys import sys
from gevent.server import DatagramServer from gevent.server import DatagramServer
from unittest import TestCase
from gevent.testing.util import run from gevent.testing.util import run
from gevent.testing import util
from gevent.testing import main from gevent.testing import main
class Test_udp_client(TestCase): class Test_udp_client(util.TestServer):
def test(self): def test(self):
log = [] log = []
...@@ -18,7 +21,7 @@ class Test_udp_client(TestCase): ...@@ -18,7 +21,7 @@ class Test_udp_client(TestCase):
server.start() server.start()
try: try:
run([sys.executable, '-W', 'ignore', '-u', 'udp_client.py', 'Test_udp_client'], run([sys.executable, '-W', 'ignore', '-u', 'udp_client.py', 'Test_udp_client'],
timeout=10, cwd='../../examples/') timeout=10, cwd=self.cwd)
finally: finally:
server.close() server.close()
self.assertEqual(log, [b'Test_udp_client']) self.assertEqual(log, [b'Test_udp_client'])
......
...@@ -13,7 +13,7 @@ import gevent.testing as greentest ...@@ -13,7 +13,7 @@ import gevent.testing as greentest
dirname = os.path.dirname(os.path.abspath(__file__)) dirname = os.path.dirname(os.path.abspath(__file__))
certfile = os.path.join(dirname, '2.7/keycert.pem') certfile = os.path.join(dirname, '2_7_keycert.pem')
pid = os.getpid() pid = os.getpid()
PY3 = greentest.PY3 PY3 = greentest.PY3
......
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