From 20baaed758506fd441a7c45d1ac40248fa202784 Mon Sep 17 00:00:00 2001 From: Jezra Date: Wed, 8 Sep 2010 19:09:01 +0100 Subject: [PATCH] Added number testing testcase --- gcc/testsuite/python.dg/t_number_1.py | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 gcc/testsuite/python.dg/t_number_1.py diff --git a/gcc/testsuite/python.dg/t_number_1.py b/gcc/testsuite/python.dg/t_number_1.py new file mode 100755 index 00000000000..2651e32a9b2 --- /dev/null +++ b/gcc/testsuite/python.dg/t_number_1.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +class numberThing: + def __init__(self): + #make a dict to hold data + self.users = dict() + '''define some variable''' + self.looping = True + #what is the file? + self.list_file = "thelist" + #map some function with a dict + self.functions = {"q":self.quit, + "?":self.print_help, + "h":self.print_help, + "i":self.insert_user, + "l":self.list_users, + "s":self.save} + #what is the help string? + self.help_string=''' +--Usage-- +========= +?: this help message +h: this help message +i: insert a user +l: list users +s: save +q: quit + ''' + #read the list file + self.read_list() + #start the shitty loop + while self.looping: + #get some input from the user + user_input = raw_input("what do you want to do (? or h for help):") + function = self.functions.get(user_input) + if function: + function() + else: + #there was no mapped function + self.print_help() + + def quit(self): + print "quit" + self.looping=False + + def read_list(self): + try: + f = open(self.list_file) + for line in f: + strippedline = line.strip() + if strippedline!='': + (name,number) = strippedline.split("::") + self.users[name]=number + f.close() + print "file has been read" + except Exception as e: + print "there is no file" + + def insert_user(self): + name = self.get_string_from_user("Enter the Name") + number = self.get_string_from_user("What is %s's number" % (name) ) + self.users[name]=number + + def list_users(self): + print "Users" + for user in self.users: + print "%s: %s" % (user, self.users[user]) + + + def get_string_from_user(self,string): + valid_string = False + while not valid_string: + user_input = raw_input("%s:" % (string)).strip() + if len(string)>0: + valid_string = True + return user_input + + def print_help(self): + #print the help + print self.help_string + + def save(self): + f = open(self.list_file, 'w') + for user in self.users: + f.write("%s::%s\n" % (user, self.users[user])) + f.close() + +if __name__=="__main__": + p = numberThing() + -- 2.11.4.GIT