Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #336 from cemsbr/tox
Browse files Browse the repository at this point in the history
Test packaging with tox
  • Loading branch information
beraldoleal committed Apr 6, 2017
2 parents b66a43d + 7c365d7 commit e2074e3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
11 changes: 0 additions & 11 deletions .scrutinizer.yml
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -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
70 changes: 36 additions & 34 deletions setup.py
Expand Up @@ -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")
Expand Down Expand Up @@ -46,48 +45,50 @@ 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 ./*.egg-info', shell=True)
call('find . -name __pycache__ -type d | xargs rm -rf')
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):
Expand Down Expand Up @@ -153,10 +154,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=[
Expand Down
15 changes: 15 additions & 0 deletions 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

0 comments on commit e2074e3

Please sign in to comment.