micropython

Annotated test.py

254:13558f703a70
2009-07-13 Paul Boddie Added tuple methods and tests.
paul@0 1
#!/usr/bin/env python
paul@0 2
paul@233 3
import micropython.cmd
paul@149 4
from micropython.graph import get_graph
paul@90 5
import rsvp
paul@0 6
import sys
paul@94 7
import os
paul@4 8
paul@90 9
def show_code(code):
paul@77 10
    for i, x in enumerate(code):
paul@22 11
        print i, x
paul@22 12
paul@135 13
def show_table_usage(raw_table, slice_size=100):
paul@135 14
    for x in xrange(0, len(raw_table), slice_size):
paul@135 15
        table_slice = raw_table[x:x+slice_size]
paul@135 16
        print "%6d" % (len(table_slice) - table_slice.count(None)), \
paul@135 17
            "".join(entry and "#" or "_" for entry in table_slice)
paul@135 18
paul@52 19
def attrs(obj):
paul@52 20
    for name, attr in obj.items():
paul@52 21
        print name, attr
paul@52 22
paul@228 23
# Main program.
paul@228 24
paul@228 25
if __name__ == "__main__":
paul@228 26
    args = sys.argv[2:]
paul@228 27
    path = sys.path[:]
paul@228 28
paul@228 29
    if len(sys.argv) > 1:
paul@228 30
        filename = os.path.abspath(sys.argv[1])
paul@228 31
        path.append(os.path.split(filename)[0])
paul@228 32
    else:
paul@228 33
        filename = None
paul@228 34
paul@228 35
    # Make the program.
paul@167 36
paul@62 37
    try:
paul@233 38
        p = micropython.cmd.get_program(filename, path, args)
paul@228 39
        if filename is None:
paul@94 40
            print "Loading module micropython ..."
paul@228 41
            m = p.get_importer().load("micropython")
paul@62 42
        else:
paul@228 43
            m = p.get_importer().get_module("__main__")
paul@228 44
paul@228 45
    # Report any errors.
paul@228 46
paul@62 47
    except micropython.ProcessingError, exc:
paul@62 48
        print repr(exc)
paul@99 49
        if "-tb" in args:
paul@99 50
            raise
paul@228 51
paul@228 52
    # Provide information to any interactive session.
paul@228 53
paul@37 54
    else:
paul@175 55
        ot = p.get_object_table()
paul@175 56
        pt = p.get_parameter_table()
paul@0 57
paul@228 58
        if "-m" in args or "-t" in args:
paul@246 59
            rm = rsvp.machine(p, debug=("-g" in args), abort_upon_exception=("-x" in args))
paul@228 60
            if "-t" in args:
paul@228 61
                success = rm.test(m)
paul@228 62
                print "Test successful?", success
paul@187 63
paul@0 64
# vim: tabstop=4 expandtab shiftwidth=4