From 4880761fe0093e21f6adb382d76fea70da43c8d8 Mon Sep 17 00:00:00 2001 From: Harsha Narayana Date: Tue, 18 Dec 2018 22:12:32 +0530 Subject: [PATCH] add setuputil based test running and makefile support Signed-off-by: Harsha Narayana --- MANIFEST.in | 23 +++++------------------ Makefile | 34 ++++++++++++++++++++++++++++++++-- setup.py | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 22 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 084d6f89..89b33477 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,27 +1,14 @@ # Non Code related contents -include LICENSE *.rst *.md *.yml *.toml Makefile *.cfg -graft .github +include LICENSE +include README.rst -# Release -include release.py +# Setup include setup.py - -# Requirements -include *.txt +include Makefile # Tests -include tox.ini .coveragerc +include .coveragerc graft tests -# Examples -graft examples - -# Documentation -graft docs -prune docs/_build - -# Docker setup -graft docker - global-exclude __pycache__ global-exclude *.py[co] \ No newline at end of file diff --git a/Makefile b/Makefile index 6fc1c8fa..b6b31dca 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,34 @@ -test: - find . -name "*.pyc" -delete +.PHONY: help test test-coverage install docker-test + +.DEFAULT: help + +help: + @echo "Please use \`make ' where is one of" + @echo "test" + @echo " Run Sanic Unit Tests" + @echo "test-coverage" + @echo " Run Sanic Unit Tests with Coverage" + @echo "install" + @echo " Install Sanic" + @echo "docker-test" + @echo " Run Sanic Unit Tests using Docker" + @echo "" + +clean: + find . ! -path "./.eggs/*" -name "*.pyc" -exec rm {} \; + find . ! -path "./.eggs/*" -name "*.pyo" -exec rm {} \; + rm -rf build/* > /dev/null 2>&1 + rm -rf dist/* > /dev/null 2>&1 + +test: clean + python setup.py test + +test-coverage: clean + python setup.py test --pytest-args="--cov sanic --cov-report term --cov-append " + +install: + python setup.py install + +docker-test: clean docker build -t sanic/test-image -f docker/Dockerfile . docker run -t sanic/test-image tox diff --git a/setup.py b/setup.py index 37164336..311a91ad 100644 --- a/setup.py +++ b/setup.py @@ -4,10 +4,25 @@ Sanic import codecs import os import re -from distutils.errors import DistutilsPlatformError +import sys from distutils.util import strtobool from setuptools import setup +from setuptools.command.test import test as TestCommand + + +class PyTest(TestCommand): + user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = '' + + def run_tests(self): + import shlex + import pytest + errno = pytest.main(shlex.split(self.pytest_args)) + sys.exit(errno) def open_local(paths, mode='r', encoding='utf8'): @@ -26,7 +41,6 @@ with open_local(['sanic', '__init__.py'], encoding='latin1') as fp: except IndexError: raise RuntimeError('Unable to determine version.') - with open_local(['README.rst']) as rm: long_description = rm.read() @@ -64,14 +78,33 @@ requirements = [ 'websockets>=6.0,<7.0', 'multidict>=4.0,<5.0', ] +tests_require = [ + 'pytest==3.3.2', + 'multidict>=4.0,<5.0', + 'gunicorn', + 'pytest-cov', + 'aiohttp>=2.3.0,<=3.2.1', + 'beautifulsoup4', + uvloop, + ujson, + 'pytest-sanic', + 'pytest-sugar' +] + if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON") requirements.remove(ujson) + tests_require.remove(ujson) # 'nt' means windows OS if strtobool(os.environ.get("SANIC_NO_UVLOOP", "no")): print("Installing without uvLoop") requirements.remove(uvloop) + tests_require.remove(uvloop) setup_kwargs['install_requires'] = requirements +setup_kwargs['tests_require'] = tests_require +setup_kwargs['cmdclass'] = { + 'test': PyTest +} setup(**setup_kwargs)