From 433bff53eec623542c0f8ffd926b6ecc4909728d Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Moreira dos Santos Date: Thu, 6 Apr 2017 11:51:17 -0300 Subject: [PATCH 1/2] Test packaging with tox New tests: - tox: all tests below + package installation - python setup.py test: unit tests - python setup.py coverage: test coverage - python setup.py doctest: documentation test - python setup.py lint: linter --- .scrutinizer.yml | 11 -------- setup.cfg | 2 +- setup.py | 69 ++++++++++++++++++++++++------------------------ tox.ini | 15 +++++++++++ 4 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 tox.ini diff --git a/.scrutinizer.yml b/.scrutinizer.yml index b93075d0f..1af21daa3 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,14 +14,3 @@ build: dependencies: override: - true - tests: - before: - - pip install git+git://github.com/kytos/python-openflow.git - - pip install -r requirements.txt -r requirements-dev.txt - override: - - - command: 'coverage run setup.py test' - coverage: - file: '.coverage' - config_file: '.coveragerc' - format: 'py-cc' diff --git a/setup.cfg b/setup.cfg index 5ba937138..c9e388763 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,5 +11,5 @@ ignore = D203,D213,I0011 [isort] # The first party was necessary to fix travis build. -known_first_party = tests +known_first_party = kytos.core,tests known_third_party = pyof diff --git a/setup.py b/setup.py index 0b3d5c6c4..05e947513 100644 --- a/setup.py +++ b/setup.py @@ -7,11 +7,10 @@ import re import sys from abc import abstractmethod -from subprocess import CalledProcessError, call, check_call +from subprocess import call from setuptools import Command, find_packages, setup from setuptools.command.develop import develop -from setuptools.command.test import test as TestCommand if 'bdist_wheel' in sys.argv: raise RuntimeError("This setup.py does not support wheels") @@ -46,48 +45,49 @@ def finalize_options(self): pass -class Linter(SimpleCommand): - """Code linters.""" +class Cleaner(SimpleCommand): + """Custom clean command to tidy up the project root.""" - description = 'run Pylama on Python files' + description = 'clean build, dist, pyc and egg from package and docs' def run(self): - """Run linter.""" - self.lint() + """Clean build, dist, pyc and egg from package and docs.""" + call('rm -vrf ./build ./dist ./*.pyc ./*.egg-info', shell=True) + call('make -C docs clean', shell=True) - @staticmethod - def lint(): - """Run pylama and radon.""" - files = 'setup.py tests kytos' - print('Pylama is running. It may take several seconds...') - cmd = 'pylama ' + files - try: - check_call(cmd, shell=True) - except CalledProcessError as e: - print('FAILED: please, fix the error(s) above.') - sys.exit(e.returncode) +class TestCoverage(SimpleCommand): + """Display test coverage.""" -class Test(TestCommand): - """Run doctest and linter besides tests/*.""" + description = 'run unit tests and display code coverage' def run(self): - """First, tests/*.""" - super().run() - print('Running examples in documentation') - check_call('make doctest -C docs/', shell=True) - Linter.lint() + """Run unittest quietly and display coverage report.""" + cmd = 'coverage3 run -m unittest discover -qs tests' \ + ' && coverage3 report' + call(cmd, shell=True) -class Cleaner(SimpleCommand): - """Custom clean command to tidy up the project root.""" +class DocTest(SimpleCommand): + """Run documentation tests.""" - description = 'clean build, dist, pyc and egg from package and docs' + description = 'run documentation tests' def run(self): - """Clean build, dist, pyc and egg from package and docs.""" - call('rm -vrf ./build ./dist ./*.pyc ./*.egg-info', shell=True) - call('make -C docs clean', shell=True) + """Run doctests using Sphinx Makefile.""" + cmd = 'make -C docs/ doctest' + call(cmd, shell=True) + + +class Linter(SimpleCommand): + """Code linters.""" + + description = 'lint Python source code' + + def run(self): + """Run pylama.""" + print('Pylama is running. It may take several seconds...') + call('pylama setup.py tests kytos', shell=True) class DevelopMode(develop): @@ -153,10 +153,11 @@ def create_path(file_name): data_files=[(os.path.join(BASE_ENV, 'etc/kytos'), ETC_FILES)], packages=find_packages(exclude=['tests']), cmdclass={ - 'develop': DevelopMode, - 'lint': Linter, 'clean': Cleaner, - 'test': Test + 'coverage': TestCoverage, + 'develop': DevelopMode, + 'doctest': DocTest, + 'lint': Linter }, zip_safe=False, classifiers=[ diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..7c8fbee29 --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +[tox] +envlist = py36 + +[testenv] +whitelist_externals = rm +commands= + ; Force packaging even if setup.{py,cfg} haven't changed + rm -rf ./kytos.egg-info/ + coverage run setup.py test + sphinx-build -b doctest -d docs/_build/doctrees docs/ docs/_build/doctest + pylama tests setup.py kytos + +deps= + git+git://github.com/kytos/python-openflow.git + -rrequirements-dev.txt From 7c365d7432cf5d472a17e95661362ac1bd8b42ce Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Moreira dos Santos Date: Thu, 6 Apr 2017 12:18:00 -0300 Subject: [PATCH 2/2] Improve setup.py clean --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 05e947513..6bc83e4bd 100644 --- a/setup.py +++ b/setup.py @@ -52,8 +52,9 @@ class Cleaner(SimpleCommand): def run(self): """Clean build, dist, pyc and egg from package and docs.""" - call('rm -vrf ./build ./dist ./*.pyc ./*.egg-info', shell=True) - call('make -C docs clean', shell=True) + call('rm -vrf ./build ./dist ./*.egg-info', shell=True) + call('find . -name __pycache__ -type d | xargs rm -rf') + call('make -C docs/ clean', shell=True) class TestCoverage(SimpleCommand):