micropython

Annotated test_all.py

435:29c1a9810249
2011-06-26 Paul Boddie Changed the title of generated graphs.
paul@233 1
#!/usr/bin/env python
paul@233 2
paul@233 3
import sys
paul@233 4
import os
paul@233 5
from glob import glob
paul@317 6
import operator
paul@233 7
paul@352 8
libdirs = [
paul@352 9
    os.path.join(os.path.split(__file__)[0], "lib"),
paul@352 10
    "/usr/share/micropython/lib"
paul@352 11
    ]
paul@352 12
paul@233 13
# Main program.
paul@233 14
paul@233 15
if __name__ == "__main__":
paul@233 16
    args = sys.argv[1:]
paul@352 17
    path = libdirs + sys.path[:]
paul@233 18
    path.append("tests")
paul@233 19
paul@233 20
    # Process all tests.
paul@233 21
paul@233 22
    try:
paul@233 23
        _f = args.index("-f")
paul@233 24
        filenames = args[_f+1:]
paul@407 25
        args = args[:_f]
paul@233 26
    except ValueError:
paul@233 27
        filenames = glob(os.path.join("tests", "*.py"))
paul@233 28
paul@233 29
    filenames.sort()
paul@233 30
paul@407 31
    # Make some arguments for the test program.
paul@407 32
paul@407 33
    args.append("-t")
paul@407 34
    if "-tb" not in args:
paul@407 35
        args.append("-exit")
paul@407 36
paul@233 37
    results = []
paul@233 38
paul@233 39
    for filename in filenames:
paul@233 40
        print "Processing", filename
paul@407 41
        success = 0 == os.system("%s test.py %s %s" % (sys.executable, filename, " ".join(args)))
paul@407 42
        print "Test successful?", success and "Yes" or "No"
paul@407 43
        results.append((filename, success))
paul@233 44
paul@362 45
    failed = [result[0] for result in results if not result[1]]
paul@362 46
    if failed:
paul@362 47
        print
paul@362 48
        print "Failed tests:"
paul@362 49
        for filename in failed:
paul@362 50
            print filename
paul@317 51
paul@317 52
    print
paul@317 53
    print "All successful?"
paul@317 54
    print reduce(operator.and_, [x[1] for x in results], 1) and "Yes" or "No"
paul@233 55
paul@233 56
# vim: tabstop=4 expandtab shiftwidth=4