How to use show_message method in tempest

Best Python code snippet using tempest_python

credit_card.py

Source:credit_card.py Github

copy

Full Screen

...29 if shop_cassify_id == "0":30 exitflag = True31 continue32 if int(shop_cassify_id) not in range(1, 6):33 common.show_message("请选择正确的商品类型编号!", "ERROR")34 continue35 elif shop_cassify_id == "4":36 # 查看购物车37 shopping.Shopping.print_goods_list(shoppobj.shopping_cart)38 common.show_message("当前购物车共有 {0} 件商品,合计 {1} 元 !".format(len(shoppobj.shopping_cart),39 shoppobj.shopping_cost), "INFORMATION")40 continue41 elif shop_cassify_id == "5":42 # 购物结算43 dealresult = shoppobj.payfor_shopcart(userobj)44 if dealresult == errorcode.NO_ERROR:45 common.show_message("支付完成!", "INFORMATION")46 else:47 # 获取用户选择的商品类型编号48 shoppobj.goods_classify_id = shop_cassify_id49 # 获得商品类型编号对应的商品列表50 goods_list = shoppobj.get_goods_list_by_typeid()51 if not goods_list:52 common.show_message("未找到商品信息!", "NOTICE")53 continue54 # 开始选择商品,添加到购物车55 choose_goods_flag = True56 while choose_goods_flag:57 # 显示指定商品分类下的所有商品列表(Shopping类静态方法)58 shopping.Shopping.print_goods_list(goods_list)59 goods_id = raw_input("选择商品编号,加入购物车(q返回上一级): ").strip().lower()60 if not goods_id: continue61 # 返回上一级62 if goods_id == "q":63 choose_goods_flag = False64 continue65 else:66 # 将选择商品加入购物车67 result = shoppobj.add_shopping_card(goods_id)68 if result:69 # 添加成功,显示购物车所有商品信息70 shopping.Shopping.print_goods_list(shoppobj.shopping_cart)71 common.show_message("已将商品加入购物车!", "INFORMATION")72 # 是否继续添加73 nextflag = False74 while not nextflag:75 donext = raw_input("继续购物(y) or 返回上一级(q):").strip().lower()76 if donext == "y":77 break78 elif donext == "q":79 choose_goods_flag = False80 break81 else:82 continue83 else:84 # 添加购物车失败85 common.show_message("添加购物车失败,请检查输入商品编号是否正确!", "ERROR")86 continue87def user_login(userobj, today, weekoftoday):88 """89 主菜单的2号菜单登录系统模块90 :param userobj: 当前用户对象91 :param today: 菜单显示的日期92 :param weekoftoday: 菜单显示的星期93 :return:94 """95 quitflag = False96 while not quitflag:97 if userobj.islogin:98 # 如果用户已经登录,菜单功能2为个人中心,调用另一个菜单模板 index_user_center99 print(templates.index_user_center.format(userobj.name, today, common.numtochr(weekoftoday)))100 _chooseflag = False101 while not _chooseflag:102 _choose = raw_input("选择功能:")103 if _choose not in ("1", "2", "3", "4", "5", "6"):104 common.show_message("选择正确的功能编号!", "ERROR")105 continue106 else:107 _chooseflag = True108 # 返回上级菜单109 if _choose == "6":110 quitflag = True111 else:112 # 根据用户按键开始处理,从 template 模块查找各按键对应的模块,通过反射来执行113 func_dict = templates.user_center_func114 modulepy = __import__(func_dict[_choose]["module"])115 # 1,2,5号键为users类方法,116 if _choose in ('1', '2', '5'):117 modulesobj = getattr(modulepy, "users")118 classobj = getattr(modulesobj, "Users")119 func = getattr(classobj, func_dict[_choose]["func"])120 else:121 # 3,4为 report 模块的方法122 modulesobj = getattr(modulepy, "report")123 func = getattr(modulesobj, func_dict[_choose]["func"])124 func(userobj)125 else:126 # 用户未登录,调用 Users类的登录模块127 userobj.login()128 quitflag = True129def card_center(userobj):130 if userobj.islogin:131 # 重新load一下数据132 userobj.db_load()133 cardno = userobj.bindcard134 # 获得信用卡对象135 card = CreditCard(cardno)136 else:137 # 未登录信用卡138 input_flag = False139 while not input_flag:140 cardno = unicode(raw_input("请输入信用卡卡号: ").strip().lower())141 if cardno.isnumeric():142 card = CreditCard(cardno)143 if card.card_is_exists:144 pwd = raw_input("请输入密码:")145 if common.encrypt(pwd) == card.password:146 common.show_message("登录成功", "NOTICE")147 input_flag = True148 continue149 else:150 common.show_message("卡号不存在,请重新输入!", "ERROR")151 continue152 else:153 common.show_message("卡号无效!", "ERROR")154 continue155 show_template = templates.index_ATM156 quitflag = False157 while not quitflag:158 print(show_template.format(cardno=card.cardno))159 _choose = common.input_msg("请选择功能: ", ("1", "2", "3", "4", "5"))160 # 返回161 if _choose == "5":162 quitflag = True163 continue164 # 查看信用卡信息165 if _choose == "1":166 common.show_message(templates.card_info.format(cardno=card.cardno,167 owner=card.owner,168 total=card.credit_total,169 balance=card.credit_balance,170 status="正常" if card.frozenstatus == 0 else "冻结"171 ), "NOTICE")172 # 提现173 if _choose == "2":174 if card.frozenstatus == 1:175 common.show_message("卡已冻结,请联系客服!", "ERROR")176 else:177 common.show_message("信用卡提现将收取 {0}% 的手续费!".format(settings.FETCH_MONEY_RATE * 100), "NOTICE")178 quitflag = False179 while not quitflag:180 cost = common.input_msg("请输入要提现的金额(q返回):")181 cost = unicode(cost)182 if cost.isnumeric(): # Python isnumeric() 方法检测字符串是否只由数字组成。这种方法是只针对unicode对象183 cardpasswd = common.input_msg("请输入信用卡密码:")184 # 执行提现操作185 exe_result = card.fetch_money(float(cost), cardpasswd)186 if exe_result == errorcode.NO_ERROR:187 common.show_message("已完成提现!", "NOTICE")188 if exe_result == errorcode.BALANCE_NOT_ENOUGHT:189 common.show_message("信用卡可透支余额不足!", "ERROR")190 if exe_result == errorcode.CARD_PASS_ERROR:191 common.show_message("信用卡密码错误!", "ERROR")192 elif cost == "q":193 quitflag = True194 continue195 else:196 common.show_message("输入错误!", "ERROR")197 # 转账198 if _choose == "3":199 if card.frozenstatus == 1:200 common.show_message("此卡已冻结,请联系客服!", "ERROR")201 else:202 common.show_message("信用卡转账将收取 {0}% 的手续费!".format(settings.FETCH_MONEY_RATE * 100), "NOTICE")203 quitflag = False204 while not quitflag:205 trans_cardno = unicode(common.input_msg("请输入要转账的卡号(q返回):"))206 if trans_cardno.isnumeric():207 # 生成一个卡对象, 验证卡号是否存在208 trans_cardobj = CreditCard(trans_cardno)209 # 卡号不存在返回主菜单210 if not trans_cardobj.card_is_exists:211 common.show_message("卡号不存在,请确认!", "ERROR")212 quitflag = True213 continue214 else:215 # 卡号存在216 trans_cost = unicode(common.input_msg("请输入要转账的金额: "))217 # 如果输入的均为数字218 if trans_cost.isnumeric():219 comfirm = common.input_msg("确定要给卡号 {0} 转入人民币 {1} 元吗(y/n)?".format(trans_cardobj.cardno,220 trans_cost),221 ("y", "n"))222 if comfirm == "y":223 cardpasswd = common.input_msg("请输入信用卡密码:")224 # 执行转账操作225 exe_result = card.translate_money(float(trans_cost), cardpasswd, trans_cardobj)226 if exe_result == errorcode.NO_ERROR:227 common.show_message("转账完成!", "NOTICE")228 if exe_result == errorcode.BALANCE_NOT_ENOUGHT:229 common.show_message("信用卡可透支余额不足!", "ERROR")230 if exe_result == errorcode.CARD_PASS_ERROR:231 common.show_message("信用卡密码错误!", "ERROR")232 else:233 common.show_message("输入错误!", "ERROR")234 elif trans_cardno == "q":235 quitflag = True236 continue237 else:238 common.show_message("输入错误!", "ERROR")239 # 还款240 if _choose == "4":241 # 更新一下对账单信息242 card.recreate_statement()243 quitflag = False244 while not quitflag:245 # 获取对账单所有列表246 interest_list = card.load_statement_list()247 # 获取还未还款的记录并显示248 message_info = report.print_statement_list(card.cardno, interest_list)249 # 如果有要还款的记录250 if len(message_info) > 0:251 common.show_message(message_info, "NOTICE")252 # 输入要还款的单号253 serino_list = list()254 for order in interest_list:255 serino_list.append(list(order.keys())[0])256 serino_list.append("q")257 pay_serno = common.input_msg("请选择还款的16位账单号(q退出):", tuple(serino_list))258 if pay_serno == "q":259 quitflag = True260 continue261 else:262 for i in range(len(interest_list)):263 for k, details in interest_list[i].items():264 if k == pay_serno:265 # 显示指定单号的相信对账单信息266 common.show_message(report.print_statement_detail(card.cardno,267 pay_serno,268 details),269 "NOTICE")270 pay_fee = common.input_msg("请输入还款金额:")271 if pay_fee.isnumeric():272 # 更新已还款金额 = 现在还的金额 + 已经还的金额273 total_payed = details["payed"] + float(pay_fee)274 interest_list[i][pay_serno]["payed"] = total_payed275 # 全还了吗?需要还款数 = 消费总费用 + 利息276 need_pay = details["total"] + details["interest"]277 if total_payed >= need_pay:278 # 还款数大于等于需要还款数,则更新已还款字段信息279 interest_list[i][pay_serno]["isfinished"] = 1280 else:281 # 没全部还款282 common.show_message("您尚未全部还款,请在还款日前尽快还款!", "NOTICE")283 # 将还款后的信息写入数据库更新284 dbapi.write_statement_list(card.cardno, interest_list)285 # 还款成功286 common.show_message("还款成功", "NOTICE")287 # 是否继续288 iscontinue = common.input_msg("继续还款吗(y/n)?", ("y", "n"))289 if iscontinue == "n":290 quitflag = True291 else:292 common.show_message("输入数据不正确,请重新输入!", "ERROR")293 else:294 common.show_message("无账单信息!", "NOTICE")295 quitflag = True296def get_users():297 """298 显示用户的信息,用户新建、删除、解锁用户时显示用户基本信息299 :return:300 """301 username = common.input_msg("请输入用户名:")302 # 创建一个用户实例303 _deluser = Users()304 _deluser.username = username305 # 如果用户名存在,load用户信息成功306 if _deluser.load_user_info():307 # 先显示一下用户的信息308 common.show_message(templates.user_info.format(username=_deluser.username,309 name=_deluser.name,310 mobile=_deluser.mobile,311 role=_deluser.role,312 isdel="否" if _deluser.isdel == 0 else "是",313 islocked="否" if _deluser.islocked == 0 else "是",314 bindcard=_deluser.bindcard)315 , "NOTICE")316 return _deluser317 else:318 common.show_message("用户名不存在!", "ERROR")319 return False320def fill_card_info():321 """322 填充信用卡资料信息323 :return: 返回一个信用卡对象324 """325 retry_flag = False326 while not retry_flag:327 cardno = common.input_msg("请输入卡号:")328 cardobj = CreditCard(cardno)329 if cardobj.card_is_exists:330 common.show_message("卡号已存在,请重新输入卡号", "ERROR")331 continue332 else:333 retry_flag = True334 continue335 cardobj.password = common.input_msg("请输入密码:")336 cardobj.credit_total = common.input_msg("信用额度(default:{0}):".format(cardobj.credit_total))337 cardobj.credit_balance = cardobj.credit_total338 cardobj.owner = common.input_msg("所有者:")339 return cardobj340def manager(userobj):341 """342 主菜单后台管理模块343 :param userobj: 当前登录用户对象344 :return:345 """346 if userobj.islogin:347 if userobj.role == "admin":348 quit_flag = False349 while not quit_flag:350 _show_template = templates.index_admin351 print(_show_template.format(username=userobj.name))352 _choose = input("选择操作功能: ").strip().lower()353 # 创建新用户354 if _choose == "1":355 _newuser = Users()356 # 调用初始化用户函数创建新用户357 _newuser.init_user_info()358 # 删除用户359 if _choose == "2":360 _user = get_users()361 if _user:362 confirm = common.input_msg("确定要删除此用户吗(y/n)?", ("y", "n"))363 if confirm == "y":364 _user.del_user()365 common.show_message("用户删除成功!", "NOTICE")366 # 解锁用户367 if _choose == "3":368 _user = get_users()369 if _user:370 confirm = common.input_msg("确认解锁吗(y/n)?", ("y", "n"))371 if confirm == "y":372 _user.unlock_user()373 common.show_message("用户解锁成功!", "NOTICE")374 # 发行信用卡375 if _choose == "4":376 newcard = fill_card_info()377 newcard.create_card()378 common.show_message("发卡成功!", "NOTICE")379 # 冻结信用卡380 if _choose == "5":381 cardno = common.input_msg("输入卡号:")382 card = CreditCard(cardno)383 if not card.card_is_exists:384 common.show_message("卡号不存在", "ERROR")385 else:386 # 调用模板显示卡信息387 common.show_message(templates.card_info.format(cardno=card.cardno,388 owner=card.owner,389 total=card.credit_total,390 balance=card.credit_balance,391 status="正常" if card.frozenstatus == 0 else "冻结"392 ), "INFORMATION")393 confirm = common.input_msg("确认要冻结此卡吗(y/n)?", ("y", "n"))394 if confirm == "y":395 card.frozenstatus = 1396 card.update_card()397 common.show_message("此卡已冻结!", "NOTICE")398 # 退出399 if _choose == "0":400 quit_flag = True401 else:402 # 不是 admin 角色无权限403 common.show_message("权限不够!", "ERROR")404 else:405 common.show_message("请先登录系统!", "NOTICE")406 userobj.login()407if __name__ == "__main__":408 today = datetime.now().strftime("%Y-%m-%d")409 weekoftoday = date.weekday(datetime.now())410 curruser = Users()411 # 初始化对账单412 report.create_statement_main()413 # -------- 开始主程序 -------------------414 exitflag = False415 while not exitflag:416 # 如果用户登录了,显示登录的界面; 未登录显示未登录的界面417 if not curruser.islogin:418 print(templates.index_default_menu.format("", today, common.numtochr(weekoftoday)))419 else:...

Full Screen

Full Screen

test_messageview.py

Source:test_messageview.py Github

copy

Full Screen

...30 usertypes.MessageLevel.error])31@pytest.mark.flaky # on macOS32def test_single_message(qtbot, view, level):33 with qtbot.wait_exposed(view, timeout=5000):34 view.show_message(level, 'test')35 assert view._messages[0].isVisible()36def test_message_hiding(qtbot, view):37 """Messages should be hidden after the timer times out."""38 with qtbot.wait_signal(view._clear_timer.timeout):39 view.show_message(usertypes.MessageLevel.info, 'test')40 assert not view._messages41def test_size_hint(view):42 """The message height should increase with more messages."""43 view.show_message(usertypes.MessageLevel.info, 'test1')44 height1 = view.sizeHint().height()45 assert height1 > 046 view.show_message(usertypes.MessageLevel.info, 'test2')47 height2 = view.sizeHint().height()48 assert height2 == height1 * 249def test_word_wrap(view, qtbot):50 """A long message should be wrapped."""51 with qtbot.wait_signal(view._clear_timer.timeout):52 view.show_message(usertypes.MessageLevel.info, 'short')53 height1 = view.sizeHint().height()54 assert height1 > 055 text = ("Athene, the bright-eyed goddess, answered him at once: Father of "56 "us all, Son of Cronos, Highest King, clearly that man deserved to be "57 "destroyed: so let all be destroyed who act as he did. But my heart aches "58 "for Odysseus, wise but ill fated, who suffers far from his friends on an "59 "island deep in the sea.")60 view.show_message(usertypes.MessageLevel.info, text)61 height2 = view.sizeHint().height()62 assert height2 > height163 assert view._messages[0].wordWrap()64def test_show_message_twice(view):65 """Show the same message twice -> only one should be shown."""66 view.show_message(usertypes.MessageLevel.info, 'test')67 view.show_message(usertypes.MessageLevel.info, 'test')68 assert len(view._messages) == 169def test_show_message_twice_after_first_disappears(qtbot, view):70 """Show the same message twice after the first is gone."""71 with qtbot.wait_signal(view._clear_timer.timeout):72 view.show_message(usertypes.MessageLevel.info, 'test')73 # Just a sanity check74 assert not view._messages75 view.show_message(usertypes.MessageLevel.info, 'test')76 assert len(view._messages) == 177def test_changing_timer_with_messages_shown(qtbot, view, config_stub):78 """When we change messages.timeout, the timer should be restarted."""79 config_stub.val.messages.timeout = 900000 # 15s80 view.show_message(usertypes.MessageLevel.info, 'test')81 with qtbot.wait_signal(view._clear_timer.timeout):82 config_stub.val.messages.timeout = 10083@pytest.mark.parametrize('count, expected', [(1, 100), (3, 300),84 (5, 500), (7, 500)])85def test_show_multiple_messages_longer(view, count, expected):86 """When there are multiple messages, messages should be shown longer.87 There is an upper maximum to avoid messages never disappearing.88 """89 for message_number in range(1, count+1):90 view.show_message(usertypes.MessageLevel.info,91 'test ' + str(message_number))92 assert view._clear_timer.interval() == expected93@pytest.mark.parametrize('replace1, replace2, length', [94 (None, None, 2), # Two stacked messages95 ('testid', 'testid', 1), # Two replaceable messages96 (None, 'testid', 2), # Stacked and replaceable97 ('testid', None, 2), # Replaceable and stacked98 ('testid1', 'testid2', 2), # Different IDs99])100def test_replaced_messages(view, replace1, replace2, length):101 """Show two stack=False messages which should replace each other."""102 view.show_message(usertypes.MessageLevel.info, 'test', replace=replace1)103 view.show_message(usertypes.MessageLevel.info, 'test 2', replace=replace2)104 assert len(view._messages) == length105def test_replacing_different_severity(view):106 view.show_message(usertypes.MessageLevel.info, 'test', replace='testid')107 with pytest.raises(AssertionError):108 view.show_message(usertypes.MessageLevel.error, 'test 2', replace='testid')109def test_replacing_changed_text(view):110 view.show_message(usertypes.MessageLevel.info, 'test', replace='testid')111 view.show_message(usertypes.MessageLevel.info, 'test 2')112 view.show_message(usertypes.MessageLevel.info, 'test 3', replace='testid')113 assert len(view._messages) == 2114 assert view._messages[0].text() == 'test 3'115 assert view._messages[1].text() == 'test 2'116def test_replacing_geometry(qtbot, view):117 view.show_message(usertypes.MessageLevel.info, 'test', replace='testid')118 with qtbot.wait_signal(view.update_geometry):119 view.show_message(usertypes.MessageLevel.info, 'test 2', replace='testid')120@pytest.mark.parametrize('button, count', [121 (Qt.LeftButton, 0),122 (Qt.MiddleButton, 0),123 (Qt.RightButton, 0),124 (Qt.BackButton, 2),125])126def test_click_messages(qtbot, view, button, count):127 """Messages should disappear when we click on them."""128 view.show_message(usertypes.MessageLevel.info, 'test mouse click')129 view.show_message(usertypes.MessageLevel.info, 'test mouse click 2')130 qtbot.mousePress(view, button)...

Full Screen

Full Screen

Arduino.py

Source:Arduino.py Github

copy

Full Screen

...20 arduino.port = '/dev/ttyUSB0' # para linux21def connect():22 result = False23 if arduino.is_open:24 terminal_messages.show_message('success', 'conexion exitosa.')25 result = {'option':'connect', 'value' : 'conexion exitosa.'}26 terminal_messages.show_message('info', 'abriendo conexion con arduino...')27 arduino.open()28 time.sleep(2)29 if arduino.is_open:30 terminal_messages.show_message('success', 'conexion exitosa.')31 result = {'option':'connect', 'value' : 'conexion exitosa.'}32 else:33 terminal_messages.show_message('error', 'conexion fallida.')34 result = {'option':'connect', 'value' : 'conexion fallida.'}35def disconnect():36 result = False37 terminal_messages.show_message('info', 'cerrando conexion con arduino...')38 if arduino.is_open:39 arduino.close()40 terminal_messages.show_message('success', 'conexion cerrada.')41 result = {'option':'disconnect', 'value' : 'conexion cerrada.'}42 else:43 result = {'option':'disconnect', 'value' : 'conexion cerrada.'}44 return result45def receive_data():46 if arduino.is_open:47 result = arduino.read(100)48 message = 'resultado : {}'.format(result)49 terminal_messages.show_message('debug', message)50 if not result:51 terminal_messages.show_message('error', 'no se recibio lectura.')52 else:53 message = 'mensaje recibido "{}"'.format(result)54 terminal_messages.show_message('success', message)55def read_line():56 if arduino.is_open:57 result = arduino.readline()58 message = 'resultado : {}'.format(result)59 terminal_messages.show_message('debug', message)60 if not result:61 terminal_messages.show_message('error', 'no se recibio lectura.')62 else:63 message = 'mensaje recibido "{}"'.format(result)64 terminal_messages.show_message('success', message)65def send_data(data):66 if arduino.is_open:67 message = 'enviando data "{}" a arduino...'.format(data)68 terminal_messages.show_message('info', message)69 arduino.write(data.encode())70''' recibe la orden para enviar a arduino y devuelve json con la respuesta '''71def send_order(data):72 result = False73 if arduino.is_open:74 message = 'enviando orden "{}" a arduino...'.format(data)75 terminal_messages.show_message('info', message)76 arduino.write(data.encode())77 time.sleep(1)78 result = arduino.readline()79 if not result or result == b'\r\n':80 terminal_messages.show_message('error', 'respuesta arduino vacia.')81 return {'option':'error', 'value':'respuesta arduino vacia.'}82 result = result.decode('utf-8').strip('\n')83 result = result.replace('\'','"')84 result = json.loads(result)85 else:86 result = {'option':'error', 'value' : 'se ha perdido la conexion con arduino'}87 terminal_messages.show_message('info', result)88 return result89def status():90 result = False91 if arduino.is_open:92 result = {'option':'status', 'value' : 'conectado'}93 else:94 result = {'option':'status', 'value' : 'desconectado'}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful