How to use handle_list method in avocado

Best Python code snippet using avocado_python

test_L2L3LearningCommand.py

Source:test_L2L3LearningCommand.py Github

copy

Full Screen

1from StcIntPythonPL import *2import spirent.methodology.utils.tag_utils as tag_utils3import spirent.methodology.L2L3LearningCommand as learningCmd4from mock import MagicMock, patch5def test_validate(stc):6 return7def test_validate_handle_types(stc):8 ctor = CScriptableCreator()9 stc_sys = CStcSystem.Instance()10 project = stc_sys.GetObject("Project")11 handle_list = []12 # Empty handle list is valid (BLL will use project)13 assert learningCmd.validate_handle_types(handle_list, True, False) == ''14 port = ctor.Create("Port", project)15 handle_list = [port.GetObjectHandle()]16 assert learningCmd.validate_handle_types(handle_list, True, False) == ''17 assert learningCmd.validate_handle_types(handle_list, False, True) == ''18 assert learningCmd.validate_handle_types(handle_list, True, True) == ''19 stream = ctor.Create("StreamBlock", project)20 handle_list = [stream.GetObjectHandle()]21 assert learningCmd.validate_handle_types(handle_list, True, False) == ''22 assert learningCmd.validate_handle_types(handle_list, False, True) == ''23 assert learningCmd.validate_handle_types(handle_list, True, True) == ''24 host = ctor.Create("Host", project)25 handle_list = [host.GetObjectHandle()]26 assert learningCmd.validate_handle_types(handle_list, True, False) == \27 "Invalid handle type: host. L2 learning command only " + \28 "allows handles of type Port and StreamBlock"29 assert learningCmd.validate_handle_types(handle_list, False, True) == ''30 assert learningCmd.validate_handle_types(handle_list, True, True) == ''31 router = ctor.Create("Router", project)32 handle_list = [router.GetObjectHandle()]33 assert learningCmd.validate_handle_types(handle_list, True, False) == \34 "Invalid handle type: router. L2 learning command only " + \35 "allows handles of type Port and StreamBlock"36 assert learningCmd.validate_handle_types(handle_list, False, True) == ''37 assert learningCmd.validate_handle_types(handle_list, True, True) == ''38 emulated_device = ctor.Create("EmulatedDevice", project)39 handle_list = [emulated_device.GetObjectHandle()]40 assert learningCmd.validate_handle_types(handle_list, True, False) == \41 "Invalid handle type: emulateddevice. L2 learning command only " + \42 "allows handles of type Port and StreamBlock"43 assert learningCmd.validate_handle_types(handle_list, False, True) == ''44 assert learningCmd.validate_handle_types(handle_list, True, True) == ''45 invalid = ctor.Create("BgpRouterConfig", emulated_device)46 handle_list = [invalid.GetObjectHandle()]47 assert learningCmd.validate_handle_types(handle_list, True, False) == \48 "Invalid handle type: bgprouterconfig. L2 learning command only " + \49 "allows handles of type Port and StreamBlock"50 assert learningCmd.validate_handle_types(handle_list, False, True) == \51 "Invalid handle type: bgprouterconfig. Learning command only allows handles " + \52 "of type Port, StreamBlock, Host, Router, and EmulatedDevice"53 assert learningCmd.validate_handle_types(handle_list, True, True) == \54 "Invalid handle type: bgprouterconfig. Learning command only allows handles " + \55 "of type Port, StreamBlock, Host, Router, and EmulatedDevice"56 return57def test_get_valid_handles(stc):58 ctor = CScriptableCreator()59 stc_sys = CStcSystem.Instance()60 project = stc_sys.GetObject("Project")61 port = ctor.Create("Port", project)62 rx_port = ctor.Create("Port", project)63 stream_block = ctor.Create("StreamBlock", port)64 stream_block.AddObject(rx_port, RelationType("ExpectedRx"))65 tag_utils.add_tag_to_object(stream_block, "ttStreamBlock")66 em_device = ctor.Create("EmulatedDevice", project)67 em_device.AddObject(port, RelationType("AffiliationPort"))68 tag_utils.add_tag_to_object(em_device, "ttEmulatedDevice")69 proto_mix = ctor.Create("StmProtocolMix", project)70 template_config = ctor.Create("StmTemplateConfig", proto_mix)71 template_config.AddObject(stream_block, RelationType("GeneratedObject"))72 tag_utils.add_tag_to_object(template_config, "ttTemplateConfig")73 bgp_config = ctor.Create("BgpRouterConfig", em_device)74 tag_utils.add_tag_to_object(bgp_config, "ttBgpRouterConfig")75 # Empty handle list76 handle_list = []77 l2_handles, l3_handles = learningCmd.get_valid_handles(handle_list, [])78 assert l2_handles == []79 assert l3_handles == []80 # Port valid for L2 and L381 handle_list = [port.GetObjectHandle()]82 l2_handles, l3_handles = learningCmd.get_valid_handles(handle_list, [])83 assert l2_handles == handle_list84 assert l3_handles == handle_list85 # EmulatedDevice valid for L3 only86 handle_list = [em_device.GetObjectHandle()]87 l2_handles, l3_handles = learningCmd.get_valid_handles(handle_list, [])88 assert l2_handles == []89 assert l3_handles == handle_list90 # BgpRouterConfig not valid for L2 or L391 handle_list = [bgp_config.GetObjectHandle()]92 l2_handles, l3_handles = learningCmd.get_valid_handles(handle_list, [])93 assert l2_handles == []94 assert l3_handles == []95 # Valid L2L3 tagged object96 tag_name_list = ['ttStreamBlock']97 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)98 assert l2_handles == [stream_block.GetObjectHandle()]99 assert l3_handles == [stream_block.GetObjectHandle()]100 # Valid L2L3 tagged object and empty tag101 tag_name_list = ['ttStreamBlock', 'ttBlah']102 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)103 assert l2_handles == [stream_block.GetObjectHandle()]104 assert l3_handles == [stream_block.GetObjectHandle()]105 # Valid L3 tagged object106 tag_name_list = ['ttEmulatedDevice']107 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)108 assert l2_handles == []109 assert l3_handles == [em_device.GetObjectHandle()]110 # Valid L3 tagged object and valid L2L3 tagged object111 tag_name_list = ['ttStreamBlock', 'ttEmulatedDevice']112 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)113 assert l2_handles == [stream_block.GetObjectHandle()]114 assert l3_handles == [stream_block.GetObjectHandle(), em_device.GetObjectHandle()]115 # Shouldn't ever happen because of validate_handle_types being called116 # but testing anyway117 tag_name_list = ['ttBgpRouterConfig']118 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)119 assert l2_handles == []120 assert l3_handles == []121 # Valid template config tagged object122 tag_name_list = ['ttTemplateConfig']123 l2_handles, l3_handles = learningCmd.get_valid_handles([], tag_name_list)124 assert len(l2_handles) == 1125 assert l2_handles == [stream_block.GetObjectHandle()]126 assert len(l3_handles) == 1127 assert l3_handles == [stream_block.GetObjectHandle()]128 # Valid protocolmix object129 tag_name_list = ['ttTemplateConfig']130 l2_handles, l3_handles = learningCmd.get_valid_handles([proto_mix.GetObjectHandle()], [])131 assert len(l2_handles) == 1132 assert l2_handles == [stream_block.GetObjectHandle()]133 assert len(l3_handles) == 1134 assert l3_handles == [stream_block.GetObjectHandle()]135 return136def test_run(stc):137 sequencer = CStcSystem.Instance().GetObject("Sequencer")138 ctor = CScriptableCreator()139 cmd = ctor.Create("spirent.methodology.L2L3LearningCommand", sequencer)140 gtc_p = patch("spirent.methodology.L2L3LearningCommand.get_this_cmd",141 new=MagicMock(return_value=cmd))142 gtc_p.start()143 stc_sys = CStcSystem.Instance()144 project = stc_sys.GetObject("Project")145 port = ctor.Create("Port", project)146 handle_list = [port.GetObjectHandle()]147 rx_port = ctor.Create("Port", project)148 stream_block = ctor.Create("StreamBlock", port)149 stream_block.AddObject(rx_port, RelationType("ExpectedRx"))150 tag_utils.add_tag_to_object(stream_block, "ttStreamBlock")151 em_device = ctor.Create("EmulatedDevice", project)152 em_device.AddObject(port, RelationType("AffiliationPort"))153 tag_utils.add_tag_to_object(em_device, "ttEmulatedDevice")154 invalid = ctor.Create("BgpRouterConfig", em_device)155 # L2Learning156 assert learningCmd.run(handle_list, [], True, False,157 "TX_RX", True, True, False)158 # L3Learning159 assert learningCmd.run([], ["ttStreamBlock"], False, True,160 "TX_RX", False, False, False)161 # L2L3Learning162 assert learningCmd.run(handle_list, ["ttStreamBlock"], True, True,163 "TX_RX", True, True, False)164 # L2Learning with invalid handle type and valid tag165 assert not learningCmd.run([em_device.GetObjectHandle()], ["ttStreamBlock"], True, False,166 "TX_RX", True, False, False)167 assert "Invalid handle type: emulateddevice. L2 learning command " + \168 "only allows handles of type Port and StreamBlock" in cmd.Get('Status')169 # L2Learning with invalid handle type and valid handle170 assert not learningCmd.run([em_device.GetObjectHandle(), port.GetObjectHandle()],171 ["ttStreamBlock"], True, False, "TX_RX", True, False, False)172 assert "Invalid handle type: emulateddevice. L2 learning command " + \173 "only allows handles of type Port and StreamBlock" in cmd.Get('Status')174 # L2L3Learning with invalid handle type and valid handle175 assert not learningCmd.run([invalid.GetObjectHandle(), port.GetObjectHandle()],176 ["ttStreamBlock"], True, True, "TX_RX", True, False, False)177 assert "Invalid handle type: bgprouterconfig. Learning command " + \178 "only allows handles of type Port, StreamBlock, Host, Router, " + \179 "and EmulatedDevice" in cmd.Get('Status')180 # Empty ObjectList and TagNameList181 assert learningCmd.run([], [], True, True,182 "TX_RX", True, True, False)183 # L2L3Learning with only valid handle for L3184 assert learningCmd.run([em_device.GetObjectHandle()], [], True, True,185 "TX_RX", True, False, False)186 # L2L3Learning with only valid tag for L3187 assert learningCmd.run([], ["ttEmulatedDevice"], True, True,188 "TX_RX", True, True, False)189 # L2Learning with only valid tag for L3190 assert learningCmd.run([], ["ttEmulatedDevice"], True, False,191 "TX_RX", True, True, False)192 gtc_p.stop()193 return194# Validate that if the BLL command fails, the so does the STAK command195def test_command_fail(stc):196 ctor = CScriptableCreator()197 stc_sys = CStcSystem.Instance()198 project = stc_sys.GetObject("Project")199 port = ctor.Create("Port", project)200 handle_list = [port.GetObjectHandle()]201 cmd = ctor.CreateCommand("spirent.methodology.L2L3LearningCommand")202 gtc_p = patch("spirent.methodology.L2L3LearningCommand.get_this_cmd",203 new=MagicMock(return_value=cmd))204 gtc_p.start()205 # Mock the function to return the command that's in a failed state206 l2StartCmd = ctor.CreateCommand("L2LearningStartCommand")207 l2StartCmd.Set('State', 'FAILED')208 l2start_p = patch("spirent.methodology.L2L3LearningCommand.l2_learning_start",209 new=MagicMock(return_value=l2StartCmd))210 l2start_p.start()211 # Ensure the STAK command fails when the BLL command fails212 assert not learningCmd.run(handle_list, [], True, False,213 "TX_RX", True, False, False)214 assert "L2LearningStartCommand did not pass" in cmd.Get('Status')215 gtc_p.stop()216 l2start_p.stop()217 return218# Validate that if VerifyArp enabled and the ArpNdVerifyResolvedCommand fails,219# the stak command also fails220def test_command_verify_arp(stc):221 ctor = CScriptableCreator()222 stc_sys = CStcSystem.Instance()223 project = stc_sys.GetObject("Project")224 port = ctor.Create("Port", project)225 handle_list = [port.GetObjectHandle()]226 cmd = ctor.CreateCommand("spirent.methodology.L2L3LearningCommand")227 gtc_p = patch("spirent.methodology.L2L3LearningCommand.get_this_cmd",228 new=MagicMock(return_value=cmd))229 gtc_p.start()230 verify_cmd = ctor.CreateCommand("ArpNdVerifyResolvedCommand")231 verify_cmd.Set('PassFailState', 'FAILED')232 verify_cmd.Set('State', 'COMPLETED')233 verify_p = patch("spirent.methodology.L2L3LearningCommand.verify_arp",234 new=MagicMock(return_value=verify_cmd))235 verify_p.start()236 # VerifyArp is True237 assert not learningCmd.run(handle_list, [], False, True,238 "TX_RX", True, False, True)239 assert "ArpNdVerifyResolvedCommand did not pass" in cmd.Get("Status")240 # VerifyArp is False241 assert learningCmd.run(handle_list, [], False, True,242 "TX_RX", True, False, False)243 gtc_p.stop()244 verify_p.stop()245 return246# Validate that the BLL commands params are being set correctly247def test_command_params(stc):248 ctor = CScriptableCreator()249 stc_sys = CStcSystem.Instance()250 project = stc_sys.GetObject("Project")251 port = ctor.Create("Port", project)252 handle_list = [port.GetObjectHandle()]253 rx_port = ctor.Create("Port", project)254 stream_block = ctor.Create("StreamBlock", port)255 stream_block.AddObject(rx_port, RelationType("ExpectedRx"))256 tag_utils.add_tag_to_object(stream_block, "ttStreamBlock")257 # Validate L2LearningStartCommand params258 cmd = learningCmd.l2_learning_start(handle_list, "RX_ONLY")259 assert cmd.GetCollection("HandleList") == handle_list260 assert cmd.Get("L2LearningOption") == "RX_ONLY"261 cmd.MarkDelete()262 # Validate L2LearningStopCommand params263 cmd = learningCmd.l2_learning_stop(handle_list)264 assert cmd.GetCollection("HandleList") == handle_list265 cmd.MarkDelete()266 # Validate ArpNdStartCommand params267 cmd = learningCmd.l3_learning_start(handle_list, False, True)268 assert cmd.GetCollection("HandleList") == handle_list269 assert not cmd.Get("WaitForArpToFinish")270 assert cmd.Get("ForceArp")271 cmd.MarkDelete()272 # Validate ArpNdStopCommand params273 cmd = learningCmd.l3_learning_stop(handle_list)274 assert cmd.GetCollection("HandleList") == handle_list275 cmd.MarkDelete()276 # Validate ArpNdVerifyResolvedCommand params277 cmd = learningCmd.verify_arp(handle_list)278 assert cmd.GetCollection("HandleList") == handle_list279 cmd.MarkDelete()...

Full Screen

Full Screen

test_find_matlab.py

Source:test_find_matlab.py Github

copy

Full Screen

...20 handle_list.cache_file.unlink(missing_ok=True)21 yield None22 handle_list.cache_file.unlink(missing_ok=True)23@pytest.fixture(scope="module")24def handle_list(request):25 with TemporaryDirectory() as temp_dir:26 cache_file = Path(temp_dir) / "cache_file.yaml"27 handle_list = MatlabHandleList(cache_file)28 yield handle_list29class TestFindMatlab:30 def test_get_matlab_installs(self):31 install_list = get_matlab_installs()32 if len(install_list) == 0:33 pytest.skip("No Matlab installations found.")34 # Check that what is returned are all folder paths35 assert all([s.is_dir() and s.exists() for s in install_list])36 # Check that there is a MATLAB executable in the correct sub-directory relative to the returned folder path37 assert all(38 [Path(s, "bin", MatlabHandle.get_matlab_exe_name()).exists for s in install_list]...

Full Screen

Full Screen

ngram.py

Source:ngram.py Github

copy

Full Screen

...3from collections import Counter4from tqdm import trange5from nltk.lm import Lidstone6from nltk.lm.preprocessing import padded_everygram_pipeline7def generate_handle_list():8 """9 生成需要使用ngram处理的emoji列表10 :return: emoji列表11 """12 # 加载需要的数据13 data_test = load_test()14 data_emoji = load_emoji_4_columns()15 data_emoji_key = []16 for i in range(len(data_emoji)):17 data_emoji_key.append(data_emoji[i][0])18 tmp = []19 for i in range(len(data_test)):20 sample_emoji = data_test[i][0].split('\t')[1]21 for j in range(len(emoji.emoji_list(sample_emoji))):22 tmp.append(emoji.emoji_list(sample_emoji)[j]['emoji'])23 # 通过在测试集中统计emoji出现情况,进行过滤24 Counter_tmp = Counter(tmp)25 tmp = dict(Counter_tmp)26 # 测试集里所有出现次数大于10的emoji27 handle_list = []28 for j in range(len(list(tmp.keys()))):29 if list(tmp.keys())[j] in data_emoji_key:30 if len(data_emoji[data_emoji_key.index(list(tmp.keys())[j])][1].split(',')) > 1:31 if tmp[list(tmp.keys())[j]] >= 10:32 handle_list.append(list(tmp.keys())[j])33 # 过滤emoji候选翻译出现集中(不需要使用ngram)的情况34 handle_list.remove('😓')35 handle_list.remove('🔫')36 handle_list.remove('🍬')37 handle_list.remove('🎂')38 handle_list.remove('👓')39 handle_list.remove('🤡')40 handle_list.remove('🚉')41 handle_list.remove('🐩')42 handle_list.remove('🏥')43 handle_list.remove('🎧')44 handle_list.remove('🍚')45 handle_list.remove('👸🏻')46 handle_list.remove('🆚')47 handle_list.remove('🈵')48 handle_list.remove('🩲')49 handle_list.remove('💵')50 handle_list.remove('👋')51 handle_list.remove('👍')52 handle_list.remove('👌')53 handle_list.remove('🍅')54 handle_list.remove('👇')55 handle_list.remove('🌺')56 handle_list.remove('😣')57 handle_list.remove('🚶')58 handle_list.remove('🕳')59 handle_list.remove('😠')60 handle_list.remove('💧')61 handle_list.remove('🚄')62 # 加上🧄、📡、🎩、🙌🏻、🧪、😀、😉、🦄、🎓、🚭、👨‍🦲、🔋63 handle_list.append('🧄')64 handle_list.append('📡')65 handle_list.append('🎩')66 handle_list.append('🙌🏻')67 handle_list.append('🧪')68 handle_list.append('😀')69 handle_list.append('😉')70 handle_list.append('🦄')71 handle_list.append('🎓')72 handle_list.append('🚭')73 handle_list.append('🔋')74 handle_list.append('👨‍🦲')75 handle_list.append('🗡')76 handle_list.append('🎥')77 # 增加的尝试092678 handle_list.append('👴🏻')79 return handle_list80def generate_ngram_data(special_emoji):81 """82 生成对于某个emoji训练ngram模型需要的数据83 :param special_emoji: 指定的某个emoji84 :return: 对应的训练集数据85 """86 data_train = load_train()87 data_ngram_data = []88 for i in range(len(data_train)):89 sample_emoji = data_train[i][2]90 if len(emoji.emoji_list(sample_emoji)) == 1:91 if emoji.emoji_list(sample_emoji)[0]['emoji'] == special_emoji:92 data_ngram_data.append([data_train[i][2], data_train[i][5]])93 # 针对只占一位的标准emoji生成供语言模型训练的数据集,除emoji部分为其余按字分割94 train = []95 for j in range(len(data_ngram_data)):96 sample_emoji = data_ngram_data[j][0]97 sample_new = sample_emoji.split(special_emoji)98 translate = data_ngram_data[j][1][emoji.emoji_list(sample_emoji)[0]['match_start']:data_ngram_data[j][1].find(sample_new[1])]99 left, right = [], []100 for i in range(len(sample_new[0])):101 left.append(sample_new[0][i])102 for i in range(len(sample_new[1])):103 right.append(sample_new[1][i])104 sentence = left + [translate] + right105 train.append(sentence)106 return train107def generate_ngram(special_emoji):108 """109 生成3gram语言模型,使用数据平滑的方法110 :param special_emoji: 特定的需要生成ngram的emoji111 :return: 该emoji的基于训练集的3gram语言模型112 """113 train_d = generate_ngram_data(special_emoji)114 ngram_order = 3115 train_data, vocab_data = padded_everygram_pipeline(ngram_order, train_d)116 lm = Lidstone(0.2, ngram_order)117 lm.fit(train_data, vocab_data)118 return lm119def generate_lm_list(handle_list):120 """121 生成handle_list中所有emoji的3gram语言模型122 :param handle_list: 待处理emoji列表123 :return: 语言模型列表124 """125 lm_list = []126 print('--------------------generate_lm_list--------------------')127 for i in trange(len(handle_list)):128 lm_list.append(generate_ngram(handle_list[i]))129 return lm_list130if __name__ == '__main__':131 handle_list = generate_handle_list()132 print(handle_list[0])...

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