File: run.py

package info (click to toggle)
python-spectral 0.22.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,064 kB
  • sloc: python: 13,161; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,370 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
'''
Runs a set of unit tests for the spectral package.

To run all unit tests, type the following from the system command line:

    # python -m spectral.tests.run
'''
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from optparse import OptionParser

import spectral.tests

def parse_args():
    parser = OptionParser()
    parser.add_option('-c', '--continue', dest='continue_tests',
                      action='store_true', default=False,
                      help='Continue with remaining tests after a '
                           'failed test.')
    (options, args) = parser.parse_args()
    spectral.tests.abort_on_fail = not options.continue_tests

def reset_stats():
    spectral.tests._num_tests_run = 0
    spectral.tests._num_tests_failed = 0

def print_summary():
    if spectral.tests._num_tests_failed > 0:
        msg =  '%d of %d tests FAILED.' % (spectral.tests._num_tests_failed,
                                           spectral.tests._num_tests_run)
    else:
        msg =  'All %d tests PASSED!' % spectral.tests._num_tests_run
    print('\n' + '-' * 72)
    print(msg)
    print('-' * 72)

if __name__ == '__main__':
    logging.getLogger('spectral').setLevel(logging.ERROR)
    parse_args()
    reset_stats()
    for test in spectral.tests.all_tests:
        test.run()
    print_summary()