micropython

test.py

402:c87bdb84d9d3
2011-02-27 Paul Boddie Introduced placeholder functions for print in order to let all tests pass. Added TestIdentity and status-related optimisation suggestions.
     1 #!/usr/bin/env python     2      3 import micropython.cmd     4 import micropython.report     5 from micropython.graph import get_graph     6 import rsvp     7 import sys     8 import os     9     10 libdirs = [    11     os.path.join(os.path.split(__file__)[0], "lib"),    12     "/usr/share/micropython/lib"    13     ]    14     15 def show_code(code):    16     for i, x in enumerate(code):    17         print i, x    18     19 def show_table_usage(raw_table, slice_size=100):    20     for x in xrange(0, len(raw_table), slice_size):    21         table_slice = raw_table[x:x+slice_size]    22         print "%6d" % (len(table_slice) - table_slice.count(None)), \    23             "".join(entry and "#" or "_" for entry in table_slice)    24     25 def attrs(obj):    26     for name, attr in obj.items():    27         print name, attr    28     29 # Main program.    30     31 if __name__ == "__main__":    32     args = sys.argv[2:]    33     path = libdirs + sys.path[:]    34     35     if "--help" in sys.argv:    36         print "Optimisations:"    37         print micropython.cmd.show_optimisations()    38         sys.exit(1)    39     40     if len(sys.argv) > 1 and sys.argv[1] != "-":    41         filename = os.path.abspath(sys.argv[1])    42         path.append(os.path.split(filename)[0])    43     else:    44         filename = None    45     46     # Load the program.    47     48     try:    49         p = micropython.cmd.get_program(path, args)    50         i = p.get_importer()    51     52         if filename is None or filename == "-":    53             print "Loading module micropython ..."    54             m = i.load("micropython")    55         else:    56             print "Loading from", filename, "..."    57             m = i.load_from_file(filename)    58     59         p.finalise()    60     61         # Make a report.    62     63         if "-d" in args:    64             try:    65                 directory = args[args.index("-d") + 1]    66             except IndexError:    67                 print "No directory specified. Not generating report."    68             else:    69                 print "Generating report in", directory    70                 micropython.report.report(p, directory)    71     72         # Build the program.    73     74         if "-m" in args or "-t" in args:    75             rm = rsvp.machine(p, debug=("-g" in args), abort_upon_exception=("-x" in args))    76     77             if "-t" in args:    78                 success = rm.test(m)    79                 print "Test successful?", success    80     81             print "RSVP machine:    rm = %r" % rm    82     83         ot = p.get_object_table()    84         pt = p.get_parameter_table()    85     86         print "Object table:    ot = %r" % ot    87         print "Parameter table: pt = %r" % pt    88         print "Importer:        i = %r" % i    89         print "Program:         p = %r" % p    90         print "Module:          m = %r" % m    91     92     # Report any errors.    93     94     except micropython.ProcessingError, exc:    95         print repr(exc)    96         if "-tb" in args:    97             raise    98     99 # vim: tabstop=4 expandtab shiftwidth=4