/ ci_tests
ci_tests
1 #!/usr/bin/env python3 2 """Run everything that needs to pass for CI to be green. 3 4 This is executed by GitHub actions against Python 3.6, 3.7, 3.8, and 3.9 on both Windows and Ubuntu. 5 6 PYTHON_ARGCOMPLETE_OK 7 """ 8 import os 9 from pathlib import Path 10 from shutil import rmtree 11 from subprocess import CalledProcessError, DEVNULL, run 12 13 from milc import set_metadata 14 15 set_metadata(name='ci_tests', author='MILC', version='1.3.0') 16 17 from milc import cli 18 19 20 @cli.entrypoint('Run CI Tests...') 21 def main(cli): 22 build_ok = True 23 24 if Path('build').exists(): 25 rmtree('build') 26 27 cli.log.info('Running nose2 tests...') 28 cmd = ['nose2'] 29 result = run(cmd, stdin=DEVNULL) 30 if result.returncode != 0: 31 build_ok = False 32 33 cli.log.info('Running flake8...') 34 cmd = ['flake8'] 35 result = run(cmd, stdin=DEVNULL) 36 if result.returncode != 0: 37 build_ok = False 38 39 cli.log.info('Running yapf...') 40 cmd = ['yapf', '-q', '-r', '--exclude', 'venv/**', '--exclude', '.venv/**', '.'] 41 result = run(cmd, stdin=DEVNULL) 42 if result.returncode != 0: 43 build_ok = False 44 cli.log.error('Improperly formatted code. Please run this: yapf -i -r .') 45 46 if build_ok: 47 cli.log.info('{fg_green}All tests passed!') 48 return True 49 50 cli.log.error('Tests are not passing! Please fix them before opening a PR.') 51 return False 52 53 54 if __name__ == '__main__': 55 if cli(): 56 exit(0) 57 else: 58 exit(1)