File: ci_tests

package info (click to toggle)
python-milc 1.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 788 kB
  • sloc: python: 1,868; sh: 55; makefile: 3
file content (62 lines) | stat: -rwxr-xr-x 1,622 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
"""Run everything that needs to pass for CI to be green.

This is executed by GitHub actions against Python 3.7 - 3.12 on both Windows and Ubuntu.

PYTHON_ARGCOMPLETE_OK
"""
import os
from pathlib import Path
from shutil import rmtree
from subprocess import CalledProcessError, DEVNULL, run

from milc import cli

cli.milc_options(name='ci_tests', author='MILC', version='1.9.1')


@cli.entrypoint('Run CI Tests...')
def main(cli):
    build_ok = True

    if Path('build').exists():
        rmtree('build')

    cli.log.info('Running nose2 tests...')
    cmd = ['nose2']
    result = run(cmd, stdin=DEVNULL)
    if result.returncode != 0:
        build_ok = False

    cli.log.info('Running flake8...')
    cmd = ['flake8']
    result = run(cmd, stdin=DEVNULL)
    if result.returncode != 0:
        build_ok = False

    cli.log.info('Running yapf...')
    cmd = ['yapf', '-q', '-r', '--exclude', 'venv/**', '--exclude', '.venv/**', '.']
    result = run(cmd, stdin=DEVNULL)
    if result.returncode != 0:
        build_ok = False
        cli.log.error('Improperly formatted code. Please run this: yapf -i -r .')

    cli.log.info('Running mypy...')
    cmd = ['mypy', '--strict', '--disable-error-code', 'unused-ignore', 'milc']
    result = run(cmd, stdin=DEVNULL)
    if result.returncode != 0:
        build_ok = False

    if build_ok:
        cli.log.info('{fg_green}All tests passed!')
        return True

    cli.log.error('Tests are not passing! Please fix them before opening a PR.')
    return False


if __name__ == '__main__':
    if cli():
        exit(0)
    else:
        exit(1)