mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Add folding to travis script section (#686)
This commit is contained in:
parent
b4b0eb4686
commit
564d361cdf
3 changed files with 95 additions and 3 deletions
|
@ -29,9 +29,7 @@ install:
|
|||
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
|
||||
|
||||
script:
|
||||
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/ tests
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then pre-commit run --all-files; fi
|
||||
- python ./setup.py bdist_dumb
|
||||
- python travis.py
|
||||
|
||||
after_success:
|
||||
coveralls
|
|
@ -7,3 +7,4 @@ yapf
|
|||
pre-commit
|
||||
pre-commit-hooks
|
||||
beautifulsoup4
|
||||
rednose
|
||||
|
|
93
travis.py
Normal file
93
travis.py
Normal file
|
@ -0,0 +1,93 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from platform import python_implementation
|
||||
import inspect
|
||||
|
||||
import nose
|
||||
from nose.config import Config
|
||||
from nose.plugins import Plugin, DefaultPluginManager
|
||||
from nose.plugins.cover import Coverage
|
||||
|
||||
import tests
|
||||
|
||||
|
||||
class CustomCoverage(Coverage):
|
||||
enabled = True
|
||||
name = 'coverage'
|
||||
score = 201 # One higher than original package
|
||||
|
||||
def report(self, stream):
|
||||
fold('coverage', 'Coverage report', stream=stream)
|
||||
super(CustomCoverage, self).report(stream)
|
||||
fold('coverage', stream=stream)
|
||||
|
||||
|
||||
class FoldPlugin(Plugin):
|
||||
enabled = True
|
||||
name = 'travis-fold'
|
||||
score = 100
|
||||
|
||||
def setOutputStream(self, stream):
|
||||
self.stream = stream
|
||||
|
||||
def startContext(self, context):
|
||||
if inspect.ismodule(context) and context != tests:
|
||||
fold(context.__name__, context.__name__, stream=self.stream)
|
||||
|
||||
def stopContext(self, context):
|
||||
if inspect.ismodule(context) and context != tests:
|
||||
fold(context.__name__, stream=self.stream)
|
||||
|
||||
folds = set()
|
||||
|
||||
|
||||
def fold(foldname, comment=None, stream=sys.stdout):
|
||||
if foldname in folds:
|
||||
folds.remove(foldname)
|
||||
print('\ntravis_fold:end:{}'.format(foldname), file=stream, end='')
|
||||
else:
|
||||
folds.add(foldname)
|
||||
print('travis_fold:start:{}'.format(foldname), file=stream, end='')
|
||||
|
||||
if comment:
|
||||
print('\n{}'.format(comment), file=stream)
|
||||
else:
|
||||
print('', file=stream)
|
||||
|
||||
|
||||
def main():
|
||||
print('Starting...')
|
||||
fold('tests', 'Running tests...')
|
||||
config = Config(verbosity=2, plugins=DefaultPluginManager(), env={'NOSE_REDNOSE': '1'})
|
||||
tests = nose.run(argv=['--with-flaky', '--no-flaky-report',
|
||||
'--with-coverage', '--cover-package=telegram/',
|
||||
'--with-travis-fold',
|
||||
'tests'],
|
||||
addplugins=[FoldPlugin(), CustomCoverage()],
|
||||
config=config)
|
||||
print('\n' * 2)
|
||||
if tests:
|
||||
fold('tests')
|
||||
|
||||
# Only run pre-commit hooks once
|
||||
pre_commit = True
|
||||
if sys.version_info[:2] == (3, 6) and python_implementation() == 'CPython':
|
||||
fold('pre-commit', 'Running pre-commits')
|
||||
# TODO: Only run pre-commit hooks on changed files
|
||||
# Using something like git diff-tree and $TRAVIS_COMMIT_RANGE
|
||||
pre_commit = subprocess.call(['pre-commit', 'run', '--all-files']) == 0
|
||||
if pre_commit:
|
||||
fold('pre-commit')
|
||||
|
||||
fold('bdist_dumb', 'Testing build...')
|
||||
# run_setup('setup.py', ['bdist_dumb']) # Makes us unable to fetch exit code
|
||||
bdist_dumb = subprocess.call(['python', 'setup.py', 'bdist_dumb']) == 0
|
||||
if bdist_dumb:
|
||||
fold('bdist_dumb')
|
||||
|
||||
sys.exit(0 if all((tests, pre_commit, bdist_dumb)) else 1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue