Skip to content

Commit

Permalink
add setuputil based test running and makefile support
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Narayana <[email protected]>
  • Loading branch information
harshanarayana committed Dec 18, 2018
1 parent 3470fa4 commit 9eedfbc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 22 deletions.
23 changes: 5 additions & 18 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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]
34 changes: 32 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
test:
find . -name "*.pyc" -delete
.PHONY: help test test-coverage install docker-test

.DEFAULT: help

help:
@echo "Please use \`make <target>' where <target> 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
37 changes: 35 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
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'):
Expand All @@ -26,7 +41,6 @@ def open_local(paths, mode='r', encoding='utf8'):
except IndexError:
raise RuntimeError('Unable to determine version.')


with open_local(['README.rst']) as rm:
long_description = rm.read()

Expand Down Expand Up @@ -64,14 +78,33 @@ def open_local(paths, mode='r', encoding='utf8'):
'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)

0 comments on commit 9eedfbc

Please sign in to comment.