Newer
Older
tconfpy / test-tc.py
#!/usr/bin/env python
# Copyright (c) 2003-2004 TundraWare Inc.  All Rights Reserved.

PROGNAME = "tconfpy Test Driver"
RCSID = "$Id: test-tc.py,v 1.112 2004/03/20 00:40:01 tundra Exp $"
VERSION = RCSID.split()[2]

# Copyright Information

CPRT         = chr(169)
DATE         = "2004"
OWNER        = "TundraWare Inc."
RIGHTS       = "All Rights Reserved"
COPYRIGHT    = "Copyright %s %s %s,  %s." % (CPRT, DATE, OWNER, RIGHTS)
PROGINFO     = PROGNAME + " " + VERSION
BANNER       = "%s\n%s\n%s\n" % (PROGINFO, COPYRIGHT, RCSID)

import tconfpy
import sys


##########
# Format and return contents of a variable descriptor
##########


def dumpdescript(val, d):

    retval = str(val) + " " * (15 - len(val))

    for v, p in ((d.Value, 10), (d.Writeable, 7), (d.Type, 17), (d.Default, 10), (d.LegalVals, 10), (d.Min, 10), (d.Max, 10)):
        retval += str(v) + (p - len(str(v))) * ' '

    return retval

# End of 'dumpdescript()'

##########
# Routine to dump returned values
##########


def dumpreturn(name, data, isdict=False):

    print name
    print len(name) * '=' + '\n'


    items = data
    if isdict:
        items = data.keys()
        items.sort()

    for val in items:
        if isdict:
            print dumpdescript(val, data[val])
        else:
            print val

    print '\n'
    

# End of 'dumpreturn()'


#---------------------------------------------------------------------------#

##########
# Beginning of test driver
##########

files = 1
DEBUG = False

syms = {"foo" : 1,
        "fox" : 1.0,
        "bar" : "stringy",
        "baz" : 4+5j,
        "boo" : True
        }

symtbl = {}

for sym in syms:

    # Create and init the descriptor
    
    d = tconfpy.VarDescriptor()
    d.Value = syms[sym]
    d.Type  = type(syms[sym])

    # Set default value according to type

    for typ in ((tconfpy.TYPE_BOOL, True), (tconfpy.TYPE_COMPLEX, 0+0j),
                (tconfpy.TYPE_FLOAT, 0.00), (tconfpy.TYPE_INT, 0),
                (tconfpy.TYPE_STRING, "")):
        
        if typ[0] == d.Type:
            d.Default = typ[1]

    # Load the table with this entry
    symtbl[sym] = d


if len(sys.argv) < 2:
    print BANNER
    print "Usage: test-tc.py [debug] file file ..."
    sys.exit(1)

if sys.argv[1].lower() == "debug":
    files = 2
    DEBUG = True

for fn in sys.argv[files:]:

    retval = tconfpy.ParseConfig(fn, symtbl, debug=DEBUG)

    if retval[1]:
        print "Errors Were Found In '%s'!" % fn
    else:
        print "No Errors Found In '%s'!" % fn

    print
    
    dumpreturn("SYMBOL TABLE", retval[0], isdict=True)
    dumpreturn("ERRORS", retval[1])
    dumpreturn("WARNINGS", retval[2])
    dumpreturn("DEBUG", retval[3])