diff options
author | wbond <will@wbond.net> | 2015-11-04 23:47:34 -0500 |
---|---|---|
committer | wbond <will@wbond.net> | 2015-11-05 02:15:36 -0500 |
commit | 801ce8636654d8efab71b079c46765e66e0359f1 (patch) | |
tree | 2e58c2250b2a0633c43f52ce69e8e5e86e5266fc | |
parent | 277d76d3699ca93084c3e25965b6a7dd965e68ea (diff) | |
download | asn1crypto-801ce8636654d8efab71b079c46765e66e0359f1.tar.gz |
Add "ci" task and Travis CI config
-rw-r--r-- | .travis.yml | 67 | ||||
-rw-r--r-- | dev/coverage.py | 12 | ||||
-rw-r--r-- | dev/lint.py | 15 | ||||
-rw-r--r-- | dev/tests.py | 14 | ||||
-rw-r--r-- | run.py | 20 |
5 files changed, 120 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6c870ed --- /dev/null +++ b/.travis.yml @@ -0,0 +1,67 @@ +sudo: false +language: c +matrix: + include: + - os: osx + python: "2.7" + env: TRAVIS_PYTHON_VERSION=2.7 + - os: osx + python: "3.5" + env: TRAVIS_PYTHON_VERSION=3.5 + - os: osx + python: "pypy" + env: TRAVIS_PYTHON_VERSION=pypy + - os: linux + language: python + python: "2.6" + - os: linux + language: python + python: "2.7" + - os: linux + language: python + python: "3.2" + - os: linux + language: python + python: "3.3" + - os: linux + language: python + python: "3.4" + - os: linux + language: python + python: "3.5" + - os: linux + language: python + python: "pypy" + - os: linux + language: python + python: "pypy3" +install: + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then + if [ "$TRAVIS_PYTHON_VERSION" == "3.5" ]; then + brew install python3; + /usr/local/bin/pip3 install flake8; + else + if [ "$TRAVIS_PYTHON_VERSION" == "pypy" ]; then + brew install pypy; + /usr/local/bin/pip_pypy install flake8; + else + sudo /usr/bin/easy_install-2.7 flake8; + fi + fi + else + pip install flake8; + fi +script: + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then + if [ "$TRAVIS_PYTHON_VERSION" == "3.5" ]; then + /usr/local/bin/python3 run.py ci; + else + if [ "$TRAVIS_PYTHON_VERSION" == "pypy" ]; then + /usr/local/bin/pypy run.py ci; + else + /usr/bin/python2.7 run.py ci; + fi + fi + else + python run.py ci; + fi diff --git a/dev/coverage.py b/dev/coverage.py index 8961f6f..8f836c5 100644 --- a/dev/coverage.py +++ b/dev/coverage.py @@ -4,16 +4,24 @@ from __future__ import unicode_literals, division, absolute_import, print_functi import coverage - def run(): + """ + Runs the tests while measuring coverage + + :return: + A bool - if the tests ran successfully + """ + cov = coverage.Coverage(include='asn1crypto/*.py') cov.start() from .tests import run as run_tests - run_tests() + result = run_tests() print() cov.stop() cov.save() cov.report(show_missing=False) + + return result diff --git a/dev/lint.py b/dev/lint.py index ec35573..2ac8159 100644 --- a/dev/lint.py +++ b/dev/lint.py @@ -11,7 +11,14 @@ config_file = os.path.join(cur_dir, '..', '.pep8') def run(): - print('Running flake8...') + """ + Runs flake8 lint + + :return: + A bool - if flake8 did not find any errors + """ + + print('Running flake8') flake8_style = get_style_guide(config_file=config_file) @@ -21,4 +28,8 @@ def run(): if not filename.endswith('.py'): continue paths.append(os.path.join(root, filename)) - flake8_style.check_files(paths) + report = flake8_style.check_files(paths) + success = report.total_errors == 0 + if success: + print('OK') + return success diff --git a/dev/tests.py b/dev/tests.py index 553e27f..b9c54b5 100644 --- a/dev/tests.py +++ b/dev/tests.py @@ -19,6 +19,17 @@ test_classes = [CMSTests, CRLTests, CSRTests, KeysTests, OCSPTests, PEMTests, TS def run(matcher=None): + """ + Runs the tests + + :param matcher: + A unicode string containing a regular expression to use to filter test + names by. A value of None will cause no filtering. + + :return: + A bool - if the tests succeeded + """ + suite = unittest.TestSuite() loader = unittest.TestLoader() for test_class in test_classes: @@ -30,4 +41,5 @@ def run(matcher=None): else: suite.addTest(loader.loadTestsFromTestCase(test_class)) verbosity = 2 if matcher else 1 - unittest.TextTestRunner(verbosity=verbosity).run(suite) + result = unittest.TextTestRunner(verbosity=verbosity).run(suite) + return result.wasSuccessful() @@ -11,7 +11,7 @@ else: def show_usage(): - print('Usage: run.py (lint | tests [regex] | coverage)', file=sys.stderr) + print('Usage: run.py (lint | tests [regex] | coverage | ci)', file=sys.stderr) sys.exit(1) @@ -29,7 +29,7 @@ if len(sys.argv) < 2 or len(sys.argv) > 3: task = get_arg(1) -if task not in ('lint', 'tests', 'coverage'): +if task not in set(['lint', 'tests', 'coverage', 'ci']): show_usage() if task != 'tests' and len(sys.argv) == 3: @@ -48,4 +48,18 @@ elif task == 'tests': elif task == 'coverage': from dev.coverage import run -run(*params) +elif task == 'ci': + from dev.tests import run as run_tests + from dev.lint import run as run_lint + + def run(): + print('Python ' + sys.version.replace('\n', '')) + print('') + lint_result = run_lint() + print('\nRunning tests') + tests_result = run_tests() + + return lint_result and tests_result + +result = run(*params) +sys.exit(int(not result)) |