micropython

test_all.py

397:7cc5058cbfb6
2011-02-20 Paul Boddie Fixed __class__ to always be at instance attribute position 0, thus matching its class attribute position. Added notes about the __class__ attribute, its definition in the object table, and the copying of the attribute from instance templates upon instantiation.
     1 #!/usr/bin/env python     2      3 import micropython.cmd     4 import rsvp     5 import sys     6 import os     7 from glob import glob     8 import operator     9     10 libdirs = [    11     os.path.join(os.path.split(__file__)[0], "lib"),    12     "/usr/share/micropython/lib"    13     ]    14     15 # Main program.    16     17 if __name__ == "__main__":    18     args = sys.argv[1:]    19     path = libdirs + sys.path[:]    20     path.append("tests")    21     22     # Process all tests.    23     24     try:    25         _f = args.index("-f")    26         filenames = args[_f+1:]    27     except ValueError:    28         filenames = glob(os.path.join("tests", "*.py"))    29     30     filenames.sort()    31     32     results = []    33     34     for filename in filenames:    35         print "Processing", filename    36     37         try:    38             p = micropython.cmd.get_program(path, args)    39             m = p.get_importer().load_from_file(filename)    40     41         # Report any errors.    42     43         except micropython.ProcessingError, exc:    44             print repr(exc)    45             if "-tb" in args:    46                 raise    47             results.append((filename, 0))    48     49         else:    50             rm = rsvp.machine(p)    51             success = rm.test(m)    52             print "Test successful?", success and "Yes" or "No"    53             results.append((filename, success))    54     55     failed = [result[0] for result in results if not result[1]]    56     if failed:    57         print    58         print "Failed tests:"    59         for filename in failed:    60             print filename    61     62     print    63     print "All successful?"    64     print reduce(operator.and_, [x[1] for x in results], 1) and "Yes" or "No"    65     66 # vim: tabstop=4 expandtab shiftwidth=4