Ejemplo n.º 1
0
def tester(usage_msg):
    import random
    import getopt
    import generators

    def usage(msg=None):
        if msg is not None: sys.stderr.write("ERROR MSG: " + str(msg))
        sys.stderr.write(usage_msg)
        sys.exit(-1)

    def rand_vals(len=4):
        n = ""
        for c in range(0, len):
            n += chr(int(random.random() * (ord('z') - ord('a'))) + ord('a'))
        return (n, int(random.random() * 50))

    def set_data(diagram, dataset):
        datasets = { 'print' : [('Yahoo', 30), ('Google', 40), ('Ask.com', 12),
                                 ('AOL', 21), ('Altavista', 3), ('MSN', 7)],
                     'test' : [ ('Short', 30), ('Very long title name', 50),
                                ('S', 0), ('ao', 1), ('Test', 25), ('x', 10)],
                     'test2' : [ ('One', 20), ('Twooooooo', 1), ('Thre', 50)],
                     'random' : [ rand_vals(6) for i in range(0, 6) ],
                     'random2' : [ rand_vals(6) for i in range(0, 8) ] }
        diagram.set_range(0, 50)
        for val in datasets[dataset]:
            diagram.add_row(val[0], val[1])

    try:
        opts, args = getopt.getopt(sys.argv[1:], "", [])
    except getopt.error:
        usage("extra args...")
    if len(args) == 2:
        dataset = args[0]
        if dataset not in ['print', 'test', 'test2', 'random', 'random2']:
            usage("incorrect dataset: " + dataset)
        filename = args[1]
    elif len(args) == 1:
        dataset = 'print'
        filename = args[0]
    else:
        usage()
    if filename[:10] == "generators":
        filename = filename[11:]
    diagram = generators.get_instance(filename[:-3])
    if diagram is None:
        usage("import failed from \"" + filename + "\"")
    set_data(diagram, dataset)
    return diagram
Ejemplo n.º 2
0
 def me(self):
     return generators.get_instance(self.name)