How to use leave_Call method in hypothesis

Best Python code snippet using hypothesis

wxpython.py

Source:wxpython.py Github

copy

Full Screen

...67 value=matchers.Name(value="wx"), attr=matchers.Name(value="FlexGridSizer")68 ),69 args=[matchers.DoNotCare(), matchers.DoNotCare()],70 )71 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:72 if matchers.matches(updated_node, self.matcher):73 return updated_node.with_changes(74 args=[*updated_node.args, cst.Arg(value=cst.Integer(value="0"))]75 )76 return updated_node77class MenuAppendCommand(VisitorBasedCodemodCommand):78 DESCRIPTION: str = "Migrate to wx.MenuAppend() method and update keywords"79 args_map = {"help": "helpString", "text": "item"}80 args_matchers_map = {81 matchers.Arg(keyword=matchers.Name(value=value)): renamed82 for value, renamed in args_map.items()83 }84 call_matcher = matchers.Call(85 func=matchers.Attribute(attr=matchers.Name(value="Append")),86 args=matchers.MatchIfTrue(87 lambda args: bool(88 set(arg.keyword.value for arg in args if arg and arg.keyword).intersection(89 MenuAppendCommand.args_map.keys()90 )91 )92 ),93 )94 deprecated_call_matcher = matchers.Call(95 func=matchers.Attribute(attr=matchers.Name(value="AppendItem")),96 args=[matchers.DoNotCare()],97 )98 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:99 # Migrate form deprecated method AppendItem()100 if matchers.matches(updated_node, self.deprecated_call_matcher):101 updated_node = updated_node.with_changes(102 func=updated_node.func.with_changes(attr=cst.Name(value="Append"))103 )104 # Update keywords105 if matchers.matches(updated_node, self.call_matcher):106 updated_node_args = list(updated_node.args)107 for arg_matcher, renamed in self.args_matchers_map.items():108 for i, node_arg in enumerate(updated_node.args):109 if matchers.matches(node_arg, arg_matcher):110 updated_node_args[i] = node_arg.with_changes(111 keyword=cst.Name(value=renamed)112 )113 updated_node = updated_node.with_changes(args=updated_node_args)114 return updated_node115class ToolbarAddToolCommand(VisitorBasedCodemodCommand):116 DESCRIPTION: str = "Transforms wx.Toolbar.DoAddTool method into AddTool"117 args_map = {"id": "toolId"}118 args_matchers_map = {119 matchers.Arg(keyword=matchers.Name(value=value)): renamed120 for value, renamed in args_map.items()121 }122 call_matcher = matchers.Call(123 func=matchers.Attribute(attr=matchers.Name(value="DoAddTool")),124 args=matchers.MatchIfTrue(125 lambda args: bool(126 set(arg.keyword.value for arg in args if arg and arg.keyword).intersection(127 ToolbarAddToolCommand.args_map.keys()128 )129 )130 ),131 )132 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:133 if matchers.matches(updated_node, self.call_matcher):134 # Update method's call135 updated_node = updated_node.with_changes(136 func=updated_node.func.with_changes(attr=cst.Name(value="AddTool"))137 )138 # Transform keywords139 updated_node_args = list(updated_node.args)140 for arg_matcher, renamed in self.args_matchers_map.items():141 for i, node_arg in enumerate(updated_node.args):142 if matchers.matches(node_arg, arg_matcher):143 updated_node_args[i] = node_arg.with_changes(144 keyword=cst.Name(value=renamed)145 )146 updated_node = updated_node.with_changes(args=updated_node_args)147 return updated_node148class SizerAddCommand(VisitorBasedCodemodCommand):149 DESCRIPTION: str = "Transforms wx.Sizer.AddWindow method into Add"150 matcher = matchers.Call(func=matchers.Attribute(attr=matchers.Name(value="AddWindow")))151 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:152 if matchers.matches(updated_node, self.matcher):153 return updated_node.with_changes(154 func=updated_node.func.with_changes(attr=cst.Name(value="Add"))155 )156 return updated_node157class ListCtrlInsertColumnCommand(VisitorBasedCodemodCommand):158 DESCRIPTION: str = "Transforms wx.ListCtrl.InsertColumnInfo method into InsertColumn"159 matcher = matchers.Call(func=matchers.Attribute(attr=matchers.Name(value="InsertColumnInfo")))160 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:161 if matchers.matches(updated_node, self.matcher):162 return updated_node.with_changes(163 func=updated_node.func.with_changes(attr=cst.Name(value="InsertColumn"))164 )165 return updated_node166class DeprecationWarningsCommand(VisitorBasedCodemodCommand):167 DESCRIPTION: str = "Rename deprecated methods"168 deprecated_symbols_map: List[Tuple[str, Union[str, Tuple[str, str]]]] = [169 ("BitmapFromImage", "Bitmap"),170 ("ImageFromStream", "Image"),171 ("EmptyIcon", "Icon"),172 ("DateTimeFromDMY", ("DateTime", "FromDMY")),173 ]174 matchers_short_map = {175 (value, matchers.Call(func=matchers.Name(value=value)), renamed)176 for value, renamed in deprecated_symbols_map177 }178 matchers_full_map = {179 (180 matchers.Call(181 func=matchers.Attribute(182 value=matchers.Name(value="wx"), attr=matchers.Name(value=value)183 )184 ),185 renamed,186 )187 for value, renamed in deprecated_symbols_map188 }189 def __init__(self, context: CodemodContext):190 super().__init__(context)191 self.wx_imports: Set[str] = set()192 def visit_Module(self, node: cst.Module) -> None:193 # Collect current list of imports194 gatherer = GatherImportsVisitor(self.context)195 node.visit(gatherer)196 # Store list of symbols imported from wx package197 self.wx_imports = gatherer.object_mapping.get("wx", set())198 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:199 # Matches calls with symbols without the wx prefix200 for symbol, matcher, renamed in self.matchers_short_map:201 if symbol in self.wx_imports and matchers.matches(updated_node, matcher):202 # Remove the symbol's import203 RemoveImportsVisitor.remove_unused_import_by_node(self.context, original_node)204 # Add import of top level wx package205 AddImportsVisitor.add_needed_import(self.context, "wx")206 # Return updated node207 if isinstance(renamed, tuple):208 return updated_node.with_changes(209 func=cst.Attribute(210 value=cst.Attribute(211 value=cst.Name(value="wx"), attr=cst.Name(value=renamed[0])212 ),213 attr=cst.Name(value=renamed[1]),214 )215 )216 return updated_node.with_changes(217 func=cst.Attribute(value=cst.Name(value="wx"), attr=cst.Name(value=renamed))218 )219 # Matches full calls like wx.MySymbol220 for matcher, renamed in self.matchers_full_map:221 if matchers.matches(updated_node, matcher):222 if isinstance(renamed, tuple):223 return updated_node.with_changes(224 func=cst.Attribute(225 value=cst.Attribute(226 value=cst.Name(value="wx"), attr=cst.Name(value=renamed[0])227 ),228 attr=cst.Name(value=renamed[1]),229 )230 )231 return updated_node.with_changes(232 func=updated_node.func.with_changes(attr=cst.Name(value=renamed))233 )234 # Returns updated node235 return updated_node236class MakeModalCommand(VisitorBasedCodemodCommand):237 DESCRIPTION: str = "Replace built-in method MAkeModal with helper"238 method_matcher = matchers.FunctionDef(239 name=matchers.Name(value="MakeModal"),240 params=matchers.Parameters(241 params=[matchers.Param(name=matchers.Name(value="self")), matchers.ZeroOrMore()]242 ),243 )244 call_matcher = matchers.Call(245 func=matchers.Attribute(246 value=matchers.Name(value="self"), attr=matchers.Name(value="MakeModal")247 )248 )249 method_cst = cst.parse_statement(250 textwrap.dedent(251 """252 def MakeModal(self, modal=True):253 if modal and not hasattr(self, '_disabler'):254 self._disabler = wx.WindowDisabler(self)255 if not modal and hasattr(self, '_disabler'):256 del self._disabler257 """258 )259 )260 def __init__(self, context: CodemodContext):261 super().__init__(context)262 self.stack: List[cst.ClassDef] = []263 def visit_ClassDef(self, node: cst.ClassDef) -> None:264 self.stack.append(node)265 def leave_ClassDef(266 self, original_node: cst.ClassDef, updated_node: cst.ClassDef267 ) -> cst.ClassDef:268 return self.stack.pop()269 def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:270 if matchers.matches(updated_node, self.call_matcher):271 # Search for MakeModal() method272 current_class = self.stack[-1]273 has_make_modal_method = False274 for method in current_class.body.body:275 if matchers.matches(method, self.method_matcher):276 has_make_modal_method = True277 # If not, add it to the current class278 if not has_make_modal_method:279 current_class = current_class.with_changes(280 body=current_class.body.with_changes(281 body=[*current_class.body.body, self.method_cst]282 )283 )...

Full Screen

Full Screen

vcstarter.py

Source:vcstarter.py Github

copy

Full Screen

1import json2import os3from json.decoder import JSONDecodeError4from aiohttp import web5from aiohttp.http_websocket import WSMsgType6from pyUltroid import Var, vcbot, udB7from telethon import TelegramClient8from telethon.tl.functions.channels import GetFullChannelRequest9from telethon.tl.functions.phone import (10 GetGroupCallRequest,11 JoinGroupCallRequest,12 LeaveGroupCallRequest,13)14from telethon.tl.types import DataJSON15LOG_CHANNEL = int(udB.get("LOG_CHANNEL"))16if vcbot is not None:17 bot = TelegramClient("ultroid_vc", Var.API_ID, Var.API_HASH).start(bot_token=udB.get("BOT_TOKEN"))18 async def get_entity(chat):19 try:20 return await vcbot.get_input_entity(chat["id"])21 except ValueError:22 if "username" in chat:23 return await vcbot.get_entity(chat["username"])24 raise25 async def join_call(data):26 try:27 chat = await get_entity(data["chat"])28 except ValueError:29 name = (await vcbot.get_me()).first_name30 return await bot.send_message(31 data["chat"]["id"], f"Please add `{name}`` in this group."32 )33 except Exception as ex:34 return await bot.send_message(data["chat"]["id"], "`" + str(ex) + "`")35 try:36 full_chat = await vcbot(GetFullChannelRequest(chat))37 except ValueError:38 stree = (await vcbot.get_me()).first_name39 return await bot.send_message(40 data["chat"]["id"], f"`Please add {stree} in this group.`"41 )42 except Exception as ex:43 return await bot.send_message(data["chat"]["id"], "`" + str(ex) + "`")44 try:45 call = await vcbot(GetGroupCallRequest(full_chat.full_chat.call))46 except BaseException:47 call = None48 if not call:49 return await bot.send_message(50 data["chat"]["id"],51 "`I can't access voice chat.`",52 )53 try:54 result = await vcbot(55 JoinGroupCallRequest(56 call=call.call,57 muted=False,58 join_as="me",59 params=DataJSON(60 data=json.dumps(61 {62 "ufrag": data["ufrag"],63 "pwd": data["pwd"],64 "fingerprints": [65 {66 "hash": data["hash"],67 "setup": data["setup"],68 "fingerprint": data["fingerprint"],69 },70 ],71 "ssrc": data["source"],72 },73 ),74 ),75 ),76 )77 await bot.send_message(78 LOG_CHANNEL,79 f"`Joined Voice Chat in {(await bot.get_entity(data['chat']['id'])).title}`",80 )81 except Exception as ex:82 return await bot.send_message(data["chat"]["id"], "`" + str(ex) + "`")83 transport = json.loads(result.updates[0].call.params.data)["transport"]84 return {85 "_": "get_join",86 "data": {87 "chat_id": data["chat"]["id"],88 "transport": {89 "ufrag": transport["ufrag"],90 "pwd": transport["pwd"],91 "fingerprints": transport["fingerprints"],92 "candidates": transport["candidates"],93 },94 },95 }96 async def leave_call(data):97 try:98 full_chat = await vcbot(99 GetFullChannelRequest(100 data["chat"]["id"],101 )102 )103 except Exception as ex:104 return await bot.send_message(105 data["chat"]["id"],106 "Exception in GetFullChannelRequest ```" + str(ex) + "```",107 )108 try:109 call = full_chat.full_chat.call110 except BaseException:111 call = None112 try:113 await vcbot(114 LeaveGroupCallRequest(115 call=call,116 source=data["source"],117 ),118 )119 await bot.send_message(120 LOG_CHANNEL,121 f"Left Voice Chat in `{data['chat']['title']}`",122 )123 except Exception as ex:124 return await bot.send_message(125 data["chat"]["id"],126 "Exception in LeaveGroupCallRequest: `" + str(ex) + "`",127 )128 return {"_": "left_vc", "data": {"chat_id": data["chat"]["id"]}}129 async def websocket_handler(request):130 ws = web.WebSocketResponse()131 await ws.prepare(request)132 async for msg in ws:133 if msg.type == WSMsgType.TEXT:134 try:135 data = json.loads(msg.data)136 except JSONDecodeError:137 await ws.close()138 break139 response = None140 if data["_"] == "join":141 response = await join_call(data["data"])142 if data["_"] == "leave":143 await bot.send_message(144 LOG_CHANNEL,145 f"Received **Leave Request** In `{data['data']['chat']['title']}`",146 )147 await bot.send_message(148 data["data"]["chat"]["id"],149 f"Received **Leave Request** In `{data['data']['chat']['title']}`",150 )151 response = await leave_call(data["data"])152 if response is not None:153 await ws.send_json(response)154 return ws155 def main():156 app = web.Application()157 app.router.add_route("GET", "/", websocket_handler)158 web.run_app(app, port=os.environ.get("PORT", 6969))159 vcbot.start()...

Full Screen

Full Screen

test_transaction_batch.py

Source:test_transaction_batch.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright 2018 ICON Foundation3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15import unittest16from iconservice.base.exception import DatabaseException17from iconservice.database.batch import BlockBatch, TransactionBatch, TransactionBatchValue, BlockBatchValue18class TestTransactionBatch(unittest.TestCase):19 def test_enter_call(self):20 tx_batch = TransactionBatch()21 call_count: int = tx_batch.call_count22 self.assertEqual(1, call_count)23 tx_batch.enter_call()24 self.assertEqual(call_count + 1, tx_batch.call_count)25 tx_batch[b'key'] = TransactionBatchValue(b'value', True)26 self.assertEqual(TransactionBatchValue(b'value', True), tx_batch[b'key'])27 tx_batch.leave_call()28 self.assertEqual(call_count, tx_batch.call_count)29 self.assertEqual(TransactionBatchValue(b'value', True), tx_batch[b'key'])30 tx_batch.enter_call()31 self.assertEqual(call_count + 1, tx_batch.call_count)32 tx_batch[b'id'] = TransactionBatchValue(b'hello', True)33 self.assertEqual(TransactionBatchValue(b'hello', True), tx_batch[b'id'])34 self.assertEqual(TransactionBatchValue(b'value', True), tx_batch[b'key'])35 tx_batch.revert_call()36 self.assertEqual(None, tx_batch[b'id'])37 self.assertEqual(TransactionBatchValue(b'value', True), tx_batch[b'key'])38 self.assertEqual(call_count + 1, tx_batch.call_count)39 tx_batch.leave_call()40 self.assertEqual(None, tx_batch[b'id'])41 self.assertEqual(TransactionBatchValue(b'value', True), tx_batch[b'key'])42 self.assertEqual(call_count, tx_batch.call_count)43 def test_iter(self):44 tx_batch = TransactionBatch()45 tx_batch[b'key0'] = TransactionBatchValue(b'value0', True)46 tx_batch.enter_call()47 tx_batch[b'key1'] = TransactionBatchValue(b'value1', True)48 keys = []49 for key in tx_batch:50 keys.append(key)51 self.assertEqual(b'key0', keys[0])52 self.assertEqual(b'key1', keys[1])53 def test_set_item(self):54 tx_batch = TransactionBatch()55 init_call_count = tx_batch.call_count56 self.assertEqual(0, len(tx_batch))57 self.assertEqual(1, init_call_count)58 tx_batch[b'key0'] = TransactionBatchValue(b'value0', True)59 self.assertEqual(1, len(tx_batch))60 tx_batch.enter_call()61 tx_batch[b'key1'] = TransactionBatchValue(b'value1', True)62 self.assertEqual(2, len(tx_batch))63 self.assertEqual(init_call_count + 1, tx_batch.call_count)64 tx_batch.enter_call()65 tx_batch[b'key0'] = TransactionBatchValue(None, True)66 tx_batch[b'key1'] = TransactionBatchValue(b'key1', True)67 tx_batch[b'key2'] = TransactionBatchValue(b'value2', True)68 self.assertEqual(5, len(tx_batch))69 self.assertEqual(init_call_count + 2, tx_batch.call_count)70 tx_batch.leave_call()71 self.assertEqual(4, len(tx_batch))72 self.assertEqual(TransactionBatchValue(b'key1', True), tx_batch[b'key1'])73 self.assertEqual(init_call_count + 1, tx_batch.call_count)74 tx_batch.leave_call()75 self.assertEqual(3, len(tx_batch))76 self.assertEqual(TransactionBatchValue(None, True), tx_batch[b'key0'])77 self.assertEqual(TransactionBatchValue(b'key1', True), tx_batch[b'key1'])78 self.assertEqual(TransactionBatchValue(b'value2', True), tx_batch[b'key2'])79 self.assertEqual(init_call_count, tx_batch.call_count)80 def test_delitem(self):81 tx_batch = TransactionBatch()82 tx_batch[b'key0'] = TransactionBatchValue(b'value0', True)83 with self.assertRaises(DatabaseException):84 del tx_batch[b'key0']85 def test_contains(self):86 tx_batch = TransactionBatch()87 init_call_count = tx_batch.call_count88 self.assertEqual(0, len(tx_batch))89 self.assertEqual(1, init_call_count)90 tx_batch[b'key0'] = TransactionBatchValue(b'value0', True)91 self.assertEqual(1, len(tx_batch))92 tx_batch.enter_call()93 tx_batch[b'key1'] = TransactionBatchValue(b'value1', True)94 self.assertEqual(2, len(tx_batch))95 self.assertEqual(init_call_count + 1, tx_batch.call_count)96 tx_batch.enter_call()97 tx_batch[b'key0'] = TransactionBatchValue(None, True)98 tx_batch[b'key1'] = TransactionBatchValue(b'key1', True)99 tx_batch[b'key2'] = TransactionBatchValue(b'value2', True)100 self.assertEqual(5, len(tx_batch))101 self.assertEqual(init_call_count + 2, tx_batch.call_count)102 keys = [b'key0', b'key1', b'key2']103 for key in keys:104 self.assertTrue(key in tx_batch)105 keys = [b'key3', b'key4']106 for key in keys:107 self.assertFalse(key in tx_batch)108 tx_batch = TransactionBatch()109 self.assertFalse(b'key' in tx_batch)110 def test_iterable(self):111 tx_batch = TransactionBatch()112 init_call_count = tx_batch.call_count113 self.assertEqual(0, len(tx_batch))114 self.assertEqual(1, init_call_count)115 tx_batch[b'key0'] = TransactionBatchValue(b'value0', True)116 self.assertEqual(1, len(tx_batch))117 block_batch = BlockBatch()118 block_batch.update(tx_batch)...

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 hypothesis 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