From 954e8db094b7f1f6be65b8ec37303a611008f2ff Mon Sep 17 00:00:00 2001 From: Elvis Pranskevichus Date: Mon, 11 Sep 2017 19:44:19 -0400 Subject: [PATCH] Add a way to run tests on an installed version of uvloop --- .ci/build-manylinux-wheels.sh | 4 ++-- .ci/travis-build-wheels.sh | 2 +- .travis.yml | 2 +- Makefile | 8 ++++++-- tests/__init__.py | 12 +++++++++++- tests/test_tcp.py | 3 +++ tests/test_unix.py | 3 +++ uvloop/_testbase.py | 11 ++++------- 8 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.ci/build-manylinux-wheels.sh b/.ci/build-manylinux-wheels.sh index 18f47a0..49f7c61 100755 --- a/.ci/build-manylinux-wheels.sh +++ b/.ci/build-manylinux-wheels.sh @@ -8,7 +8,7 @@ PIP="/opt/python/${PYTHON_VERSION}/bin/pip" ${PIP} install --upgrade pip wheel ${PIP} install --upgrade setuptools ${PIP} install -r /io/.ci/requirements.txt -make -C /io/ PYTHON="${PYTHON}" +make -C /io/ PYTHON="${PYTHON}" clean compile ${PIP} wheel /io/ -w /io/dist/ # Bundle external shared libraries into the wheels. @@ -21,5 +21,5 @@ PYTHON="/opt/python/${PYTHON_VERSION}/bin/python" PIP="/opt/python/${PYTHON_VERSION}/bin/pip" ${PIP} install ${PYMODULE} --no-index -f file:///io/dist rm -rf /io/tests/__pycache__ -make -C /io/ PYTHON="${PYTHON}" test +make -C /io/ PYTHON="${PYTHON}" testinstalled rm -rf /io/tests/__pycache__ diff --git a/.ci/travis-build-wheels.sh b/.ci/travis-build-wheels.sh index 8150c7c..c1d9b77 100755 --- a/.ci/travis-build-wheels.sh +++ b/.ci/travis-build-wheels.sh @@ -62,7 +62,7 @@ elif [ "${TRAVIS_OS_NAME}" == "osx" ]; then pip install ${PYMODULE} --no-index -f "file:///${_root}/dist" pushd / >/dev/null - make -C "${_root}" test + make -C "${_root}" testinstalled popd >/dev/null _upload_wheels diff --git a/.travis.yml b/.travis.yml index 07fe061..aae27de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ matrix: dist: trusty sudo: false language: python - python: "3.6-dev" + python: "3.6" env: BUILD=tests - os: linux diff --git a/Makefile b/Makefile index e894a95..20eadcf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: _default clean clean-libuv distclean compile debug docs test release +.PHONY: _default clean clean-libuv distclean compile debug docs test testinstalled release PYTHON ?= python @@ -9,7 +9,7 @@ _default: compile clean: rm -fr dist/ doc/_build/ *.egg-info uvloop/loop.*.pyd - rm -fr build/lib.* build/temp.* + rm -fr build/lib.* build/temp.* build/libuv rm -fr uvloop/*.c uvloop/*.html uvloop/*.so rm -fr uvloop/handles/*.html uvloop/includes/*.html find . -name '__pycache__' | xargs rm -rf @@ -44,5 +44,9 @@ test: $(PYTHON) setup.py test +testinstalled: + $(PYTHON) tests/__init__.py + + release: distclean compile test $(PYTHON) setup.py sdist bdist_wheel upload diff --git a/tests/__init__.py b/tests/__init__.py index 51eccca..0f18e3f 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,17 @@ +import os.path +import sys import unittest +import unittest.runner def suite(): test_loader = unittest.TestLoader() - test_suite = test_loader.discover('.', pattern='test_*.py') + test_suite = test_loader.discover( + os.path.dirname(__file__), pattern='test_*.py') return test_suite + + +if __name__ == '__main__': + runner = unittest.runner.TextTestRunner() + result = runner.run(suite()) + sys.exit(not result.wasSuccessful()) diff --git a/tests/test_tcp.py b/tests/test_tcp.py index b323a3a..08d4eb6 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -842,6 +842,9 @@ class Test_AIO_TCP(_TestTCP, tb.AIOTestCase): class _TestSSL(tb.SSLTestCase): + ONLYCERT = tb._cert_fullname(__file__, 'ssl_cert.pem') + ONLYKEY = tb._cert_fullname(__file__, 'ssl_key.pem') + def test_create_server_ssl_1(self): CNT = 0 # number of clients that were successful TOTAL_CNT = 25 # total number of clients that test will create diff --git a/tests/test_unix.py b/tests/test_unix.py index 2d39843..e76d0b0 100644 --- a/tests/test_unix.py +++ b/tests/test_unix.py @@ -420,6 +420,9 @@ class Test_AIO_Unix(_TestUnix, tb.AIOTestCase): class _TestSSL(tb.SSLTestCase): + ONLYCERT = tb._cert_fullname(__file__, 'ssl_cert.pem') + ONLYKEY = tb._cert_fullname(__file__, 'ssl_key.pem') + def test_create_unix_server_ssl_1(self): CNT = 0 # number of clients that were successful TOTAL_CNT = 25 # total number of clients that test will create diff --git a/uvloop/_testbase.py b/uvloop/_testbase.py index 6ae9220..2607160 100644 --- a/uvloop/_testbase.py +++ b/uvloop/_testbase.py @@ -133,10 +133,10 @@ class BaseTestCase(unittest.TestCase, metaclass=BaseTestCaseMeta): def skip_unclosed_handles_check(self): self._check_unclosed_resources_in_debug = False -def _cert_fullname(name): - fullname = os.path.join( - os.path.dirname(os.path.dirname(__file__)), - 'tests', 'certs', name) + +def _cert_fullname(test_file_name, cert_file_name): + fullname = os.path.abspath(os.path.join( + os.path.dirname(test_file_name), 'certs', cert_file_name)) assert os.path.isfile(fullname) return fullname @@ -173,9 +173,6 @@ def find_free_port(start_from=50000): class SSLTestCase: - ONLYCERT = _cert_fullname('ssl_cert.pem') - ONLYKEY = _cert_fullname('ssl_key.pem') - def _create_server_ssl_context(self, certfile, keyfile=None): sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23) sslcontext.options |= ssl.OP_NO_SSLv2