How to use list_cmd method in molecule

Best Python code snippet using molecule_python

test_cmd_list.py

Source:test_cmd_list.py Github

copy

Full Screen

1# Copyright (C) 2022 Intel Corporation2# SPDX-License-Identifier: Apache-2.03from multiprocessing import context4import pytest5from kit.commands.list_cmd import list_components, RepoProperties, _SEP_SPACES6def test_get_repo_properties_max_width(mocker):7 """Arrange"""8 exp_comps = ["1234567", "123", "12345678"]9 exp_inst1 = ["123"]10 exp_inst2 = ["1", "1234567890123456"]11 exp_inst3 = ["123456"]12 mock_list_dirs = mocker.patch("kit.commands.list_cmd.list_dirs")13 mock_list_dirs.side_effect = [exp_comps, exp_inst1, exp_inst2, exp_inst3]14 exp_repo_structure = {15 exp_comps[0]: exp_inst1,16 exp_comps[1]: exp_inst2,17 exp_comps[2]: exp_inst3,18 }19 exp_width_comp = 8 + _SEP_SPACES20 exp_width_inst = 16 + _SEP_SPACES21 """Act"""22 act_props = RepoProperties("")23 """Assert"""24 assert act_props.structure == exp_repo_structure25 assert act_props.width_comp == exp_width_comp26 assert act_props.width_inst == exp_width_inst27def test_get_repo_properties_without_instances(mocker):28 """Arrange"""29 exp_comps = ["12345678901234567890"]30 exp_inst1 = []31 mock_list_dirs = mocker.patch("kit.commands.list_cmd.list_dirs")32 mock_list_dirs.side_effect = [exp_comps, exp_inst1]33 exp_repo_structure = {exp_comps[0]: exp_inst1}34 exp_width_comp = 20 + _SEP_SPACES35 exp_width_inst = 0 + _SEP_SPACES36 """Act"""37 act_props = RepoProperties("")38 """Assert"""39 assert act_props.structure == exp_repo_structure40 assert act_props.width_comp == exp_width_comp41 assert act_props.width_inst == exp_width_inst42def test_get_repo_properties_without_components(mocker):43 """Arrange"""44 exp_comps = []45 exp_inst1 = []46 mock_list_dirs = mocker.patch("kit.commands.list_cmd.list_dirs")47 mock_list_dirs.side_effect = [exp_comps, exp_inst1]48 exp_repo_structure = {}49 exp_width_comp = 0 + _SEP_SPACES50 exp_width_inst = 0 + _SEP_SPACES51 """Act"""52 act_props = RepoProperties("")53 """Assert"""54 assert act_props.structure == exp_repo_structure55 assert act_props.width_comp == exp_width_comp56 assert act_props.width_inst == exp_width_inst57def test_list_components_several_correct_items(58 mocker, args, tree_directory, all_actions_success59):60 """Arrange"""61 """list_cmd_dirs function is called several times, first62 it returns the libraries, then the version of each one"""63 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=tree_directory)64 """load function returns success as status of the all the actions"""65 mock_load = mocker.patch(66 "kit.commands.list_cmd.load", return_value=all_actions_success67 )68 mock_print = mocker.patch("kit.commands.list_cmd.print")69 """Act"""70 list_components(args)71 """Assert"""72 assert 8 == mock_walk.call_count73 assert 8 == mock_load.call_count74 assert 9 == mock_print.call_count75def test_list_components_incorrect_fetch(76 mocker, args, lib_directory, fetch_failure, name_version_lib77):78 """Arrange"""79 """list_dirs function is called two times, first80 it returns a library and then its version"""81 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=lib_directory)82 """load function returns failure as status of fetch"""83 mock_load = mocker.patch("kit.commands.list_cmd.load", return_value=fetch_failure)84 """print functions reports the failure for fetch"""85 mock_print = mocker.patch("kit.commands.list_cmd.print")86 exp_lib, exp_version = name_version_lib87 arg1, arg2, arg3, arg4 = get_print_args(exp_lib, exp_version, fetch_failure)88 """Act"""89 list_components(args)90 """Assert"""91 assert 2 == mock_walk.call_count92 assert 1 == mock_load.call_count93 assert 2 == mock_print.call_count94 mock_print.assert_called_with(arg1, arg2, arg3, arg4)95def test_list_components_incorrect_build(96 mocker, args, lib_directory, build_failure, name_version_lib97):98 """Arrange"""99 """list_dirs function is called two times, first100 it returns a library and then its version"""101 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=lib_directory)102 """load function returns failure as status of build"""103 mock_load = mocker.patch("kit.commands.list_cmd.load", return_value=build_failure)104 """print functions reports the failure for build"""105 mock_print = mocker.patch("kit.commands.list_cmd.print")106 exp_lib, exp_version = name_version_lib107 arg1, arg2, arg3, arg4 = get_print_args(exp_lib, exp_version, build_failure)108 """Act"""109 list_components(args)110 """Assert"""111 assert 2 == mock_walk.call_count112 assert 1 == mock_load.call_count113 assert 2 == mock_print.call_count114 mock_print.assert_called_with(arg1, arg2, arg3, arg4)115def test_list_components_incorrect_install(116 mocker, args, lib_directory, install_failure, name_version_lib117):118 """Arrange"""119 """list_dirs function is called two times, first120 it returns a library and then its version"""121 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=lib_directory)122 """load function returns failure as status of install"""123 mock_load = mocker.patch("kit.commands.list_cmd.load", return_value=install_failure)124 """print functions reports the failure for install"""125 mock_print = mocker.patch("kit.commands.list_cmd.print")126 exp_lib, exp_version = name_version_lib127 arg1, arg2, arg3, arg4 = get_print_args(exp_lib, exp_version, install_failure)128 """Act"""129 list_components(args)130 """Assert"""131 assert 2 == mock_walk.call_count132 assert 1 == mock_load.call_count133 assert 2 == mock_print.call_count134 mock_print.assert_called_with(arg1, arg2, arg3, arg4)135def test_list_components_without_version(mocker, without_version_directory, args):136 """Arrange"""137 """list_dirs function is called two times, first138 it returns a library and then it tries its version"""139 mock_walk = mocker.patch(140 "kit.commands.list_cmd.walk", side_effect=without_version_directory141 )142 mock_load = mocker.patch("kit.commands.list_cmd.load")143 mock_print = mocker.patch("kit.commands.list_cmd.print")144 """Act"""145 list_components(args)146 """Assert"""147 assert 2 == mock_walk.call_count148 assert 1 == mock_print.call_count149 mock_load.assert_not_called()150def test_list_components_without_libraries(mocker, args, without_lib_directory):151 """Arrange"""152 """list_dirs function is called once but153 there are not libraries"""154 mock_walk = mocker.patch(155 "kit.commands.list_cmd.walk", side_effect=without_lib_directory156 )157 mock_load = mocker.patch("kit.commands.list_cmd.load")158 mock_print = mocker.patch("kit.commands.list_cmd.print")159 """Act"""160 list_components(args)161 """Assert"""162 assert 1 == mock_walk.call_count163 assert 1 == mock_print.call_count164 mock_load.assert_not_called()165def test_list_components_StopIteration_exception(mocker, args):166 """Arrange"""167 """list_dirs function triggers a StopIteration exception168 and returns an empty list"""169 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=StopIteration)170 mock_load = mocker.patch("kit.commands.list_cmd.load")171 mock_print = mocker.patch("kit.commands.list_cmd.print")172 """Act"""173 list_components(args)174 """Assert"""175 assert 1 == mock_walk.call_count176 assert 1 == mock_print.call_count177 mock_load.assert_not_called()178def test_list_components_FileNotFoundError_exception(179 mocker, args, lib_directory, name_version_lib180):181 """Arrange"""182 """list_dirs function is called two times, first183 it returns the library then its version"""184 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=lib_directory)185 """ load triggers an FileNotFoundError exception"""186 mock_load = mocker.patch(187 "kit.commands.list_cmd.load", side_effect=FileNotFoundError188 )189 """print functions reports the exception"""190 mock_print = mocker.patch("kit.commands.list_cmd.print")191 exp_lib, exp_version = name_version_lib192 info_filepath = f"{args.config.repo_location}/{exp_lib}/{exp_version}/hekit.info"193 arg1, arg2, arg3, arg4, arg5 = util_print_file_error_args(194 exp_lib, exp_version, info_filepath195 )196 """Act"""197 list_components(args)198 """Assert"""199 assert 2 == mock_walk.call_count200 assert 1 == mock_load.call_count201 assert 2 == mock_print.call_count202 mock_print.assert_called_with(arg1, arg2, arg3, arg4, arg5)203def test_list_components_KeyError_exception(204 mocker, args, lib_directory, name_version_lib205):206 """Arrange"""207 """list_dirs function is called two times, first208 it returns a library and then its version"""209 mock_walk = mocker.patch("kit.commands.list_cmd.walk", side_effect=lib_directory)210 """load function triggers a KeyError exception"""211 mock_load = mocker.patch("kit.commands.list_cmd.load", side_effect=KeyError)212 """print functions reports the exception"""213 mock_print = mocker.patch("kit.commands.list_cmd.print")214 exp_lib, exp_version = name_version_lib215 arg1, arg2, arg3, arg4, arg5 = util_print_key_error_args(exp_lib, exp_version, "")216 """Act"""217 list_components(args)218 """Assert"""219 mock_walk.assert_called()220 assert 2 == mock_walk.call_count221 assert 1 == mock_load.call_count222 assert 2 == mock_print.call_count223 mock_print.assert_called_with(arg1, arg2, arg3, arg4, arg5)224"""Utilities used by the tests"""225class MockArgs:226 class Config:227 def __init__(self):228 self.repo_location = "test"229 def __init__(self):230 self.config = MockArgs.Config()231@pytest.fixture232def args():233 return MockArgs()234@pytest.fixture235def tree_directory():236 return [237 iter(238 [("", ["test1", "test2", "test3", "test4", "test5", "test6", "test7"], [])]239 ),240 iter([("", ["v3.1.0"], [])]),241 iter([("", ["v2.2.1"], [])]),242 iter([("", ["1.2.1", "1.2.3"], [])]),243 iter([("", ["11.5.1"], [])]),244 iter([("", ["v1.11.6"], [])]),245 iter([("", ["v3.7.2"], [])]),246 iter([("", ["v1.4.5"], [])]),247 ]248@pytest.fixture249def name_version_lib():250 return "hexl", "v3.1.0"251@pytest.fixture252def lib_directory(name_version_lib):253 exp_lib, exp_version = name_version_lib254 return [iter([("", [exp_lib], [])]), iter([("", [exp_version], [])])]255@pytest.fixture256def without_version_directory(name_version_lib):257 exp_lib, _ = name_version_lib258 return [iter([("", [exp_lib], [])]), iter([("", [], [])])]259@pytest.fixture260def without_lib_directory():261 return [iter([("", [], [])])]262@pytest.fixture263def all_actions_success():264 return {"status": {"fetch": "success", "build": "success", "install": "success"}}265@pytest.fixture266def fetch_failure():267 return {"status": {"fetch": "failure", "build": "success", "install": "success"}}268@pytest.fixture269def build_failure():270 return {"status": {"fetch": "success", "build": "failure", "install": "success"}}271@pytest.fixture272def install_failure():273 return {"status": {"fetch": "success", "build": "success", "install": "failure"}}274def get_width_and_header(comp_name, comp_inst, separation_spaces=_SEP_SPACES):275 width = 10276 width_comp = len(comp_name) + separation_spaces277 width_inst = len(comp_inst) + separation_spaces278 return width, f"{comp_name:{width_comp}} {comp_inst:{width_inst}}"279def get_print_args(comp_name, comp_inst, info_file):280 width, column1 = get_width_and_header(comp_name, comp_inst)281 column2 = f"{info_file['status']['fetch']:{width}}"282 column3 = f"{info_file['status']['build']:{width}}"283 column4 = f"{info_file['status']['install']:{width}}"284 return column1, column2, column3, column4285def util_print_file_error_args(comp_name, comp_inst, info_filepath):286 width, column1 = get_width_and_header(comp_name, comp_inst)287 columns234 = f"{'unknown':{width}}"288 column5 = f"file '{info_filepath}' not found"289 return column1, columns234, columns234, columns234, column5290def util_print_key_error_args(comp_name, comp_inst, emsg):291 width, column1 = get_width_and_header(comp_name, comp_inst)292 columns234 = f"{'unknown':{width}}"293 column5 = f"key {emsg} not found"...

Full Screen

Full Screen

03_큐함수구현하기.py

Source:03_큐함수구현하기.py Github

copy

Full Screen

1'''2import sys3def Input_Data():4 readl = sys.stdin.readline5 N = int(readl())6 A = list(map(int, readl().split()))7 return N, A8def Push(d):9 global queue, wp, rp10# 여기서부터 작성11 if wp >= 5: return 012 queue[wp] = d13 wp += 114 return 115def Pop():16 global queue, wp, rp17# 여기서부터 작성18 if wp == rp: return 019 ret = queue[rp]20 rp += 121 return rp22def Solve():23 for i in range(N):24 if A[i] > 0:25 r = Push(A[i])26 if r == 0: print(-1, end=' ')27 else:28 r = Pop()29 if r == 0: print(-1, end=' ')30 else: print(r, end=' ')31queue = [0]*532wp = 033rp = 034# 입력받는 부분35N, A = Input_Data()36# 여기서부터 작성37Solve()38'''39import sys40from collections import deque41def Input_Data():42 readl = sys.stdin.readline43 N = int(readl())44 list_cmd = [list(map(int,readl().split())) for _ in range(N)]45 return N, list_cmd46def Process():47 #collection사용시48 q = deque()49 for n in range(N):50 if list_cmd[n][0] == 1:51 q.append(list_cmd[n][1])52 elif list_cmd[n][0] == 0:53 if len(q) == 0:54 print("E")55 else:56 d = q.popleft()57 print(d)58 elif list_cmd[n][0] == 2:59 print(len(q))60 '''61 q = []62 for n in range(N):63 if list_cmd[n][0] == 1:64 q.append(list_cmd[n][1])65 elif list_cmd[n][0] == 0:66 if len(q) == 0:67 print("E")68 else:69 d = q.pop(0)70 print(d)71 elif list_cmd[n][0] == 2:72 print(len(q))73 '''74N, list_cmd = Input_Data()...

Full Screen

Full Screen

01.py

Source:01.py Github

copy

Full Screen

1'''2import sys3def Input_Data():4 readl = sys.stdin.readline5 N = int(readl())6 A = list(map(int, readl().split()))7 return N, A8def Push(d):9 global stack, sp10 # 여기서부터 구현11 # Full?12 if sp == 0: return -113 sp -= 114 stack[sp] = d15 return sp16def Pop():17 global stack, sp18 # 여기서부터 구현19 # Empty?20 if sp == 4 : return -121 ret = stack[sp]22 sp += 123 return ret24def Solve():25 for i in range(N):26 if A[i] > 0:27 r = Push(A[i])28 if r == -1: print(-1, end=' ')29 else:30 r = Pop()31 if r == -1: print(-1, end=' ')32 else: print(r, end=' ')33stack = [0]*434sp = 435N, A = Input_Data()36Solve()37'''38import sys39def Input_Data():40 readl = sys.stdin.readline41 N = int(readl())42 list_cmd = [list(map(int,readl().split())) for _ in range(N)]43 return N, list_cmd44def Process():45 stack = []46 for n in range(N):47 if list_cmd[n][0] == 1:48 stack.append(list_cmd[n][1])49 elif list_cmd[n][0] == 0:50 if len(stack) == 0:51 print("E")52 else:53 print(stack.pop(-1))54 elif list_cmd[n][0] == 2:55 print(len(stack))56N, list_cmd = Input_Data()...

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