#!/usr/bin/env python # Copyright (c) 2003-2004 TundraWare Inc. All Rights Reserved. PROGNAME = "tconfpy Test Driver" RCSID = "$Id: test-tc.py,v 1.111 2004/03/20 00:03:54 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 ########## # 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: d = data[val] f = "'%s'" if d.Type != type(f): f = "%s" print val + (15-len(val)) * " ", d.Value, " ", d.Writeable, d.Type, f % d.Default, d.LegalVals, d.Min, d.Max 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])