def test_s3_get(self): teller = ATM(s3_cache_dir) s3_content = teller.get_cache(s3_file).content requests_content = requests.get(s3_file).content assert s3_content == requests_content
def train_atm_model(cross_validation): current_dir = path.abspath('.') cross_validation_data_dir = '{}/dataset/{}'.format(current_dir, cross_validation) train_file = path.join(cross_validation_data_dir, 'atm_train.csv') np.random.seed(0) # for replication purposes random.seed(0) atm_models_dir = '{}/atm-models'.format(current_dir) cross_validation_atm_model_dir = '{}/{}'.format(atm_models_dir, cross_validation) if not path.exists(cross_validation_atm_model_dir): makedirs(cross_validation_atm_model_dir) chdir(cross_validation_atm_model_dir) clf = ATM() results = clf.run(train_path=train_file, name=cross_validation, budget=200, budget_type='classifier', metric='accuracy', methods=['svm']) best_classifier_pkl_file = '{}/model_{}.pkl'.format( cross_validation_atm_model_dir, cross_validation) results.export_best_classifier(best_classifier_pkl_file) chdir(current_dir) return cross_validation
def test_get_currency_amount(print_mock, input_mock): input_mock.side_effect = ['A', '1000'] atm = ATM() result = atm._get_currency_amount() assert result == '1000' print_mock.assert_called_once()
def test_choice(sb_mock): atm = ATM() atm.choice(1) sb_mock.assert_called_once() with pytest.raises(InvalidChoice): assert atm.choice(99)
def test_get_account(print_mock, input_mock, build_account): input_mock.sid_effect = ['5', '1'] atm = ATM() account = build_account() atm.accounts.append(account) assert atm._get_account() == account
def main(): admin = Admin() #管理员对象 admin.printAdminView() #管理员开机 if admin.adminOperation(): return -1 atm = ATM() while True: #等待用户操作 admin.sysFunctionView() option = input("请输入你的操作:") if option == '0': atm.createUser() if option == '1': pass elif option == '2': pass elif option == '3': pass elif option == '4': pass elif option == '5': pass elif option == '6': pass elif option == '7': pass elif option == '8': pass elif option == '9': if admin.adminOperation(): return -1
def test_add_account(input_mock, print_mock): input_mock.side_effect = ['3', '1', '1000.00'] atm = ATM() account = atm.add_account() assert print_mock.call_count > 2 assert account.amount == Decimal('1000.00')
def __init__(self, win,passwd): self.passwd = passwd self.win = win self.atm = ATM() # self.header = Label(self.win, text="TAN BANK", bg="#50A8B0", fg="white", font=("arial", 20, "bold")) # self.header.grid(row = 0, column = 0) self.uentry = Entry(win, bg="honeydew", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.pentry = Entry(win, bg="honeydew", show="*", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.top_frame = Frame(self.win, bg="#50A8B0") self.frame = Frame(self.win, bg="#728B8E", width=40, height=12) self.left_frame = Frame(self.win) self.right_frame = Frame(self.win) self.top_frame.grid(row=0, columnspan=3) self.frame.grid(row=1, column=1) self.left_frame.grid(row=1, column=0) self.right_frame.grid(row=1, column=2) self.header = Label(self.top_frame, text="TAN BANK", bg="#50A8B0", fg="white", font=("arial", 20, "bold"), width=40) self.header.grid() self.content = tkinter.Text(self.frame, width=40, height=12, font=("arial", 15, "bold"), bg="#728B8E", fg="white") self.content.grid(row=0) info = self.inputPasswd() self.content.insert(tkinter.INSERT, info) self.content.config(stat=DISABLED) self.lb1 = Button(self.left_frame, text="LB1", width=10, height=3) self.lb2 = Button(self.left_frame, text="LB2", width=10, height=3) self.lb3 = Button(self.left_frame, text="LB3", width=10, height=3) self.lb4 = Button(self.left_frame, text="LB4", width=10, height=3) # self.lb1.pack(side=tkinter.LEFT, fill=tkinter.Y) # self.lb2.pack(side=tkinter.LEFT, fill=tkinter.Y) # self.lb3.pack(side=tkinter.LEFT, fill=tkinter.Y) self.lb1.grid(row=0, column=0, sticky=E, padx=5, pady=5) self.lb2.grid(row=1, column=0, sticky=E, padx=5, pady=5) self.lb3.grid(row=2, column=0, sticky=E, padx=5, pady=5) self.lb4.grid(row=3, column=0, sticky=E, padx=5, pady=5) self.rb1 = Button(self.right_frame, text="RB1", width=10, height=3) self.rb2 = Button(self.right_frame, text="RB2", width=10, height=3) self.rb3 = Button(self.right_frame, text="RB3", width=10, height=3) self.rb4 = Button(self.right_frame, text="RB4", width=10, height=3) # self.rb1.pack(side=tkinter.RIGHT ,fill=tkinter.Y) # self.rb2.pack(side=tkinter.RIGHT, fill=tkinter.Y) # self.rb3.pack(side=tkinter.RIGHT, fill=tkinter.Y) self.rb1.grid(row=0, column=0, sticky=W, padx=5, pady=5) self.rb2.grid(row=1, column=0, sticky=W, padx=5, pady=5) self.rb3.grid(row=2, column=0, sticky=W, padx=5, pady=5) self.rb4.grid(row=3, column=0, sticky=W, padx=5, pady=5)
def test_withdraw(print_mock, input_mock, build_account): input_mock.side_effect = ['1', '500.00'] atm = ATM() assert atm.withdraw() is None atm.accounts.append(build_account()) atm.withdraw() assert atm.accounts[0].amount == Decimal('700.00')
def test_show_balance(print_mock, input_mock, build_account): input_mock.side_effect = ['1'] atm = ATM() assert atm.show_balance() is None atm.accounts.append(build_account()) atm.show_balance() assert print_mock.call_count > 1
def train_atm(X_train, X_test, y_train, y_test, mtype, common_name_model, problemtype, classes, default_featurenames, transform_model, settings, model_session): # create file names model_name = common_name_model + '.pickle' csvname = common_name_model.split('_')[0] files = list() # initialize and train classifier atm = ATM() # create a temporary directory for all models curdir = os.getcwd() try: os.mkdir('atm_temp') os.chdir('atm_temp') except: shutil.rmtree('atm_temp') os.mkdir('atm_temp') os.chdir('atm_temp') try: shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_train_transformed.csv', os.getcwd() + '/train.csv') shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_test_transformed.csv', os.getcwd() + '/test.csv') except: shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_train.csv', os.getcwd() + '/train.csv') shutil.copy( curdir + '/' + model_session + '/data/' + csvname + '_test.csv', os.getcwd() + '/test.csv') # train models results = atm.run(train_path='train.csv', class_column='class_') data_results_ = str(results.describe()) bestclassifier = str(results.get_best_classifier()) scores = str(results.get_scores()) # export classifier / transfer to model directory results.export_best_classifier(model_name, force=True) shutil.move(os.getcwd() + '/' + model_name, curdir + '/' + model_name) files.append('atm_temp') files.append(model_name) files.append('atm.db') os.chdir(curdir) model_dir = os.getcwd() return model_name, model_dir, files
def test__url_to_filepath(self): filepath1 = local_cache_dir + '/' + sha1(url).hexdigest() + '.txt' teller = ATM(local_cache_dir) filepath2 = teller._url_to_filepath(url, interval_string=None) # remove cache directory shutil.rmtree(local_cache_dir) # test assert filepath1 == filepath2
def test_local_liquidate(self): teller = ATM(local_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) files = [f for f in teller.liquidate()] # remove cache directory shutil.rmtree(local_cache_dir) assert len(files) == 2
def test__url_to_filepath(self): filepath1 = local_cache_dir + "/" + sha1(url).hexdigest() + ".txt" teller = ATM(local_cache_dir) filepath2 = teller._url_to_filepath(url, interval_string=None) # remove cache directory shutil.rmtree(local_cache_dir) # test assert filepath1 == filepath2
def test_source(self): teller = ATM(s3_cache_dir, interval=10) r = teller.get_cache(url) source1 = r.source r = teller.get_cache(url) source2 = r.source teller.default() assert source1 == "url" and source2 == "cache"
def test_local_statement(self): teller = ATM(local_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) # statement statement = teller.statement() # remove cache directory shutil.rmtree(local_cache_dir) assert len(statement) == 2
def main(): # 界面对象 admin = Admin() # 管理员开机 admin.printAdminView() if admin.adminOption( ): # view.printAdminView()返回值为-1则进入函数,返回-1,返回值为0则继续向下进行 return -1 # 提款机对象 atm = ATM() while True: admin.printSysFunctionView() # 等待用户的操作 option = input("请输入您的操作:") if option == "1": # 开户 atm.createUser() elif option == "2": # 查询 atm.searchUserInfo() elif option == "3": # 取款 pass elif option == "4": # 存储 pass elif option == "5": # 转账 pass elif option == "6": # 改密 pass elif option == "7": # 锁定 atm.lockUser() elif option == "8": # 解锁l atm.unlockUser() elif option == "9": # 补卡 pass elif option == "0": # 销户 pass elif option == "t": # 退出 if not admin.adminOption(): return -1 time.sleep(1)
def test_transfer(print_mock, input_mock, build_account): input_mock.side_effect = ['1', '2', '500.00'] acct1 = build_account(acc_type='Fake Account 1') acct2 = build_account(acc_type='Fake Account 2') atm = ATM() assert atm.transfer_funds() is None atm.accounts.extend([acct1, acct2]) atm.transfer_funds() assert atm.accounts[0].amount == Decimal('700.00') assert atm.accounts[1].amount == Decimal('1700.00')
def UserInput(self): adminview = Welcomeview() while True: option = input("等待用户输入:") if option == "1": atm_create = ATM() atm_create.createUser() break elif option == "2": atm_search = ATM() atm_search.searchUser() return -1 elif option == "3": print("取款") elif option == "4": print("存款") elif option == "5": print("转账") elif option == "6": print("改密") elif option == "7": print("锁定") elif option == "8": print("解锁") elif option == "9": print("补卡") elif option == "10": print("销户") elif option == "q": verifty_admin = VerifyAdmin() if verifty_admin.verify() == 1: break else: print("请输入正常的数字:") time.sleep(2)
def run(train_path, test_path, time_limit, dataset_name, metric="accuracy"): '''initialization ''' atm = ATM() print(os.path.isfile(os.path.abspath(train_path))) rslt = atm.run(train_path=train_path, test_path=test_path, budget=time_limit, budget_type="walltime", metric=metric) # f1 or accuracy return rslt
def main(): # 管理员登录为'admin',密码为'123' view = View("admin", "123") view.initface() atm = ATM() view.login() user = Users() while True: view.sysInit() c = input("Please input business: ") if c == "1": user.createAccount(atm) elif c == "2": if user.log(atm): while True: if func(view, atm, user) == None: continue else: break elif c == "3": user.findBackPwd(atm) elif c == "4": user.lockAccount(atm) elif c == "T": if user.exitSys(atm): # 管理员注销系统 if view.logout(): return True else: print("The input have something wrong")
def main(): try: f = open(filePath, "rb") allUsers = pickle.load(f) except EOFError: allUsers = {} # 初始化实例 admin = Admin() atm = ATM(allUsers) # 登录界面 admin.printLoginView() # 验证信息 if admin.logCheck(): return -1 # 进入操作界面 else: admin.printFuncView() while 1: option = input("$ Please input your choice: ") if option == 'q': print("Thanks for support! Bye~") # 将用户信息保存在本地 f = open(filePath, "wb") pickle.dump(atm.allUsers, f) f.close() return 0 # 验证身份 # 进行操作 optionSel(atm, option)
def login(accountListFile, transactionSummary): try: choice = input("Welcome to the front end: \n") if choice == 'login': # use correctly input login print("Successfully login.") status = False # check the validation of input while status == False: # loop if user input invalid command mode = input("Select mode to enter: \n") # select mode if mode == "atm": # user correctly input atm print("Successfully entered ATM mode.") newAtm = ATM(accountListFile, transactionSummary) # create new atm object status = True elif mode == "agent": # user correctly input agent print("Successfully entered agent mode.") newAgent = AGENT(accountListFile, transactionSummary) # create new agent object status = True elif mode == "logout": status = True f = open(transactionSummary, "w") f.writelines("EOS") f.close() else: # error for anything else print("Error:Invalid mode choice, please input a valid mode choice!") print("Successfully logout.") login(accountListFile, transactionSummary) else: # invalid input print("Error:Please login first!") login(accountListFile, transactionSummary) except: quit # exit program
def test_local_interval(self): teller = ATM(local_cache_dir, interval=10) r = teller.get_cache(url) r = teller.get_cache(url) time.sleep(10) r = teller.get_cache(url) statement = teller.statement() # remove cache directory shutil.rmtree(local_cache_dir) # test assert len(statement) == 2
def test_local_interval(self): teller = ATM(local_cache_dir, interval=10) r = teller.get_cache(url) r = teller.get_cache(url) time.sleep(10) r = teller.get_cache(url) statement = teller.statement() # remove cache directory shutil.rmtree(local_cache_dir) # test assert len(statement)==2
def __init__(self,win): self.win = win self.atm = ATM() self.uentry = Entry(win, bg="honeydew", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.pentry = Entry(win, bg="honeydew", show="*", highlightcolor="#50A8B0", highlightthickness=2, highlightbackground="white", width=40) self.top_frame= Frame(self.win,bg="#50A8B0") self.frame = Frame(self.win, bg="#728B8E",width=40,height=12) self.left_frame = Frame(self.win) self.right_frame = Frame(self.win) self.top_frame.grid(row =0,columnspan=3) self.frame.grid(row=1, column=1) self.left_frame.grid(row=1, column=0) self.right_frame.grid(row=1, column=2) self.header = Label(self.top_frame, text="TAN BANK", bg="#50A8B0", fg="white", font=("arial", 20, "bold"),width=40) self.header.grid() self.content = tkinter.Text(self.frame,width=40,height=12,font=("arial", 15, "bold"),bg="#728B8E",fg="white") self.content.grid(row = 0) info = self.atmInitView() self.content.insert(tkinter.INSERT, info) self.content.config(stat = DISABLED) self.lb1 = Button(self.left_frame, text="登陆",width=10, height=3, command=self.checkPasswd_view) self.lb2 = Button(self.left_frame, text="提额",width=10, height=3,command=self.addMoney_view) self.lb3 = Button(self.left_frame, text="LB3",width=10, height=3) self.lb4 = Button(self.left_frame, text="LB4", width=10, height=3) self.lb1.grid(row=0, column=0, sticky=E, padx=5, pady=5) self.lb2.grid(row=1, column=0, sticky=E, padx=5, pady=5) self.lb3.grid(row=2, column=0, sticky=E, padx=5, pady=5) self.lb4.grid(row=3, column=0, sticky=E, padx=5, pady=5) self.rb1 = Button(self.right_frame, text="关机",width=10, height=3,command = self.win.destroy) self.rb2 = Button(self.right_frame, text="改密",width=10, height=3,command = self.changeAtmPasswd_view) self.rb3 = Button(self.right_frame, text="RB3",width=10, height=3) self.rb4 = Button(self.right_frame, text="RB4", width=10, height=3,command = self.atmInitView_refresh) self.rb1.grid(row=0, column=0, sticky=W, padx=5, pady=5) self.rb2.grid(row=1, column=0,sticky=W, padx=5, pady=5) self.rb3.grid(row=2, column=0, sticky=W, padx=5, pady=5) self.rb4.grid(row=3, column=0, sticky=W, padx=5, pady=5)
def test_s3_default(self): teller = ATM(s3_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) statement1 = teller.statement() # now delete teller.default() # statement again statement2 = teller.statement() # remove files teller.default() assert len(statement1) == 2 and len(statement2) == 0
def main(): # 创建窗口对象 view = View() #创建atm对象 filePath = os.path.join(os.getcwd(), "practice.txt") if os.path.isfile(filePath): with open(filePath, "rb") as f: allUsers = pickle.load(f) else: allUsers = {} atm = ATM(allUsers) if view.printAdminView(): return 1 while True: view.sysFuncView() #等待用户操作 option = input("请输入您的操作:") if option == "open": atm.createUser() # 开户 elif option == "search": atm.searchUserInfo() elif option == "withdrawal": pass elif option == "deposit": pass elif option == "tranfer": pass elif option == "change": pass elif option == "lock": atm.lockUser() elif option == "unlock": atm.unLockUser() elif option == "reissue": pass elif option == "close": pass elif option == "quit": filePath = os.path.join(os.getcwd(), "practice.txt") with open(filePath, "wb") as f: pickle.dump(atm.allUser, f) return 1 time.sleep(2)
def main(): admin = Admin() if admin.adminOption(): return -1 # admin.printAdminView() # path = r"/home/intfreedom/PycharmProjects/identify/20180628/allUsers.txt" filepath = os.path.join(os.getcwd(), 'allusers.txt') # f = open(path, "rb") f = open(filepath, "rb") allUsers = pickle.load(f) # print("**********") # print(allUsers) # allUsers = {} atm = ATM(allUsers) while True: admin.printSysFunctionView() option = input("please input your move:") if option == "1": atm.createUser() print("kaihu") elif option == "2": atm.searchUserInfo() print("cunkuan") elif option == "3": atm.getMoney() elif option == "7": atm.lockUser() elif option == "t": if not admin.adminOption(): filepath = os.path.join(os.getcwd(), 'allusers.txt') f = open(filepath, "wb") # filepath = os.path.join(filepath, 'allusers.txt' ) # # print(filepath) # f = open(filepath, "wb") pickle.dump(atm.allUsers, f) f.close() return -1 time.sleep(2)
def main(): # 界面对象 admin = Admin() # 开机 admin.printAdminView() # 管理员登录 if admin.adminOperate(): return -1 atm = ATM() while True: admin.systemFunctionView() option = input('请输入你的操作:') if option == '1': print('开户') atm.createUser() elif option == '2': print('查询') elif option == '3': print('取款') elif option == '4': print('存储') elif option == '5': print('转账') elif option == '6': print('改密') elif option == '7': print('锁定') elif option == '8': print('解锁') elif option == '9': print('补卡') elif option == '0': print('销户') elif option == 't': print('退出') if admin.adminOperate(): return -1
def ok(self): atm = ATM() # print(self.passwd,self.name,atm.passwd,atm.account) if self.passwd.get() != atm.passwd or self.name.get() != atm.account: self.tip.set("账号或密码错误!请重新输入") self.name.set("") self.passwd.set("") else: self.destroy() # 销毁窗口 self.isLogin = self.passwd.get()
def setUp(self): """ create initial instances on which all test will be performed :return: """ self.account_balance = 15000 self.person = Person(self.account_balance) ATM.currency_numbers = (THOUSANDS, FIVE_HUNDREDS, HUNDREDS) self.atm = ATM() self.atm_balance = self.atm.total_amount
def test_availability_of_notes(self): """ test if right combination of notes are present to serve the request :return: """ ATM.currency_numbers = (THOUSANDS, FIVE_HUNDREDS, 3) self.atm = ATM() withdraw_amount = 400 self.person.dispense(withdraw_amount, self.atm) self.assertAccountBalanceUnchanged()
def test_s3_liquidate(self): teller = ATM(s3_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) assets = [f for f in teller.liquidate()] # remove files teller.default() assert len(assets) == 2
def test_s3_statement(self): teller = ATM(s3_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) # get statement statement = teller.statement() # remove files teller.default() assert len(statement) == 2
def test_s3_interval(self): teller = ATM(s3_cache_dir, interval=10) # remove cache directory teller.default() r = teller.get_cache(url) r = teller.get_cache(url) time.sleep(10) r = teller.get_cache(url) statement = teller.statement() # remove cache directory teller.default() # test assert len(statement) == 2
def test_local_default(self): teller = ATM(local_cache_dir) r = teller.get_cache(url) r = teller.get_cache(url2) statement1 = teller.statement() # now delete teller.default() # statement again statement2 = teller.statement() # remove cache directory shutil.rmtree(local_cache_dir) assert len(statement1) == 2 and len(statement2) == 0
def testEfetuarSaque80Reais(self): atm = ATM() mensagem = atm.efetuarSaque(80) padrao = "Entregar 1 nota(s) de R$ 50,00 e 1 nota(s) de R$ 20,00 e 1 nota(s) de R$ 10,00" self.assertEquals(mensagem, padrao)
def testObterMaiorNotaPossivel30(self): atm = ATM() nota = atm.obterMaiorNotaPossivel(30) self.assertEqual(nota, 20)
def testValorVazio(self): atm = ATM() with self.assertRaises(ValorInvalidoException) : atm.efetuarSaque(None)
def testValorNaoEhPossivel(self): atm = ATM() with self.assertRaises(ValorInvalidoException) : atm.efetuarSaque(35)
def testNotaRetornadaIgual200(self): atm = ATM() notas = atm.contarNotas(200) self.assertListEqual(notas, [100, 100])
def testNotaRetornadaIgual80(self): atm = ATM() notas = atm.contarNotas(80) self.assertListEqual(notas, [50, 20, 10])
def testObterMaiorNotaPossivel200(self): atm = ATM() nota = atm.obterMaiorNotaPossivel(200) self.assertEqual(nota, 100)
def testObterMaiorNotaPossivel60(self): atm = ATM() nota = atm.obterMaiorNotaPossivel(60) self.assertEqual(nota, 50)
import sys from atm import ATM if __name__ == '__main__': try: valor = sys.argv[1] atm = ATM() print atm.efetuarSaque(int(valor)) except: import sys print sys.exc_info()[1]