How to use execute_commands method in Kiwi

Best Python code snippet using Kiwi_python

test_general.py

Source:test_general.py Github

copy

Full Screen

...4from classes.person import MAX_LUCK5from main import CHARACTER, main6from world.items import Items, antidote7from world.rooms import Rooms8def execute_commands(commands: 'list[str]'):9 main(test_mode=True, user_commands=commands)10def test_savepoints():11 execute_commands(commands=[12 "import savepoint",13 "create savepoint",14 ])15class Test:16 def setup_method(self, _method):17 CHARACTER.inventory.clear()18 CHARACTER.inventory.max_items = 519class TestMovement(Test):20 def test_unlock_front_door(self):21 Rooms.FRONT_YARD.value.locked = True22 CHARACTER.room = Rooms.CORRIDOR.value23 CHARACTER.inventory.add_item(Items.KEY_HOME.value)24 execute_commands(commands=[25 f"use {Items.KEY_HOME.value.name}"26 ])27 assert Rooms.FRONT_YARD.value.locked is False28 assert Items.KEY_HOME.value not in CHARACTER.inventory29 execute_commands(commands=[30 f"go {Rooms.FRONT_YARD.value.name}"31 ])32 assert CHARACTER.room == Rooms.FRONT_YARD.value33 Rooms.FRONT_YARD.value.locked = True34 def test_cant_go_to_locked_room(self):35 CHARACTER.room = Rooms.CORRIDOR.value36 execute_commands(commands=[37 f"go {Rooms.FRONT_YARD.value.name}"38 ])39 assert CHARACTER.room == Rooms.CORRIDOR.value40 assert Rooms.FRONT_YARD.value.locked is True41 def test_unlock_motel_one(self):42 from world.rooms import KILLS_TO_OPEN_MOTEL_ONE43 Rooms.MOTEL_ONE.value.locked = True44 Rooms.NEWMAN_ROW.value.npc = None45 Rooms.MONTANA_AVENUE.value.npc = None46 CHARACTER.room = Rooms.MONTANA_AVENUE.value47 CHARACTER.kills = KILLS_TO_OPEN_MOTEL_ONE48 execute_commands(commands=[49 f"go {Rooms.NEWMAN_ROW.value.name}"50 ])51 assert Rooms.MOTEL_ONE.value.locked is False52 execute_commands(commands=[53 f"go {Rooms.MOTEL_ONE.value.name}"54 ])55 assert CHARACTER.room == Rooms.MOTEL_ONE.value56 def test_update_respawn_point(self):57 CHARACTER.room = Rooms.CORRIDOR.value58 CHARACTER.respawn_point = Rooms.BEDROOM.value59 Rooms.FRONT_YARD.value.visited = False60 Rooms.FRONT_YARD.value.locked = False61 execute_commands(commands=[62 f"go {Rooms.FRONT_YARD.value.name}"63 ])64 assert CHARACTER.respawn_point == Rooms.FRONT_YARD.value65class TestInventory(Test):66 def test_max_inventory(self):67 CHARACTER.inventory.max_items = 268 assert CHARACTER.inventory.add_item(Items.KNIFE.value)69 assert CHARACTER.inventory.add_item(Items.COIN.value)70 assert not CHARACTER.inventory.add_item(Items.BULLET_CARTRIDGE.value)71 def test_take_item(self, items_to_take: int = 3):72 Rooms.CORRIDOR.value.loot = Inventory({73 Items.COIN.value: items_to_take74 })75 CHARACTER.room = Rooms.CORRIDOR.value76 execute_commands(commands=[77 f"take {Items.COIN.value.name}"78 ])79 assert Items.COIN.value in CHARACTER.inventory80 assert CHARACTER.inventory[Items.COIN.value] == items_to_take81 def test_drop_item(self, items_to_drop: int = 2):82 CHARACTER.inventory.add_item(Items.COIN.value, items_to_drop)83 execute_commands(commands=[84 f"drop {Items.COIN.value.name}"85 ])86 assert Items.COIN.value not in CHARACTER.inventory87 assert Items.COIN.value in CHARACTER.room.loot88 assert CHARACTER.room.loot[Items.COIN.value] == items_to_drop89 def test_buy_item(self, item_to_buy: Item = Items.HEALING_POTION.value):90 CHARACTER.room = Rooms.GARAGE.value91 CHARACTER.inventory.add_item(92 Items.COIN.value, Rooms.GARAGE.value.items_to_buy[item_to_buy])93 execute_commands(commands=[94 f"buy {item_to_buy.name}"95 ])96 assert CHARACTER.inventory[item_to_buy] == 197 assert Items.COIN.value not in CHARACTER.inventory98 def test_buy_multiple_items(self, item_to_buy: Item = Items.HEALING_POTION.value, amount: int = 5):99 CHARACTER.room = Rooms.GARAGE.value100 CHARACTER.inventory.add_item(101 Items.COIN.value, amount*Rooms.GARAGE.value.items_to_buy[item_to_buy])102 execute_commands(commands=[103 f"buy {item_to_buy.name} {amount}"104 ])105 assert item_to_buy in CHARACTER.inventory106 assert CHARACTER.inventory[item_to_buy] == amount107 assert Items.COIN.value not in CHARACTER.inventory108 def test_sell_item(self, item_to_sell: Item = Items.MAP_HOME.value):109 CHARACTER.room = Rooms.GARAGE.value110 CHARACTER.room.items_to_sell[item_to_sell] = 4111 CHARACTER.inventory.add_item(item_to_sell)112 execute_commands(commands=[113 f"sell {item_to_sell.name}"114 ])115 print(CHARACTER.room.items_to_sell[item_to_sell])116 assert item_to_sell not in CHARACTER.inventory117 assert CHARACTER.inventory[Items.COIN.value] == CHARACTER.room.items_to_sell[item_to_sell]118 def test_equip_melee_weapon(self):119 CHARACTER.melee_weapon = Items.REMOTE.value120 CHARACTER.inventory.add_item(Items.KNIFE.value)121 execute_commands(commands=[122 f"equip {Items.KNIFE.value.name}"123 ])124 assert CHARACTER.melee_weapon == Items.KNIFE.value125 assert Items.KNIFE.value not in CHARACTER.inventory126 assert Items.REMOTE.value in CHARACTER.inventory127 def test_equip_ranged_weapon(self):128 CHARACTER.ranged_weapon = None129 CHARACTER.inventory.add_item(Items.PISTOL.value)130 execute_commands(commands=[131 f"equip {Items.PISTOL.value.name}"132 ])133 assert CHARACTER.ranged_weapon == Items.PISTOL.value134 assert len(CHARACTER.inventory) == 0135class TestItems(Test):136 def test_use_on_pickup(self):137 CHARACTER.room = Rooms.GARAGE.value138 CHARACTER.inventory.add_item(Items.COIN.value, 100)139 CHARACTER.armor = 0140 execute_commands(commands=[141 f"buy {Items.ARMOR.value.name}"142 ])143 assert CHARACTER.armor == 1144 def test_holy_scepter(self):145 CHARACTER.room.loot.add_item(Items.HOLY_SCEPTER.value)146 CHARACTER.armor = 0147 execute_commands(commands=[148 f"take {Items.HOLY_SCEPTER.value.name}"149 ])150 assert CHARACTER.armor == 40151 def test_antidote(self):152 CHARACTER.room = Rooms.MONTANA_AVENUE.value153 CHARACTER.room.npc = None154 Rooms.CATHETRAL.value.npc = NPC(name="Dummy")155 CHARACTER.inventory.add_item(Items.ANTIDOTE.value)156 CHARACTER.cures = 0157 execute_commands(commands=[158 f"go {Rooms.CATHETRAL.value.name}",159 f"use {Items.ANTIDOTE.value.name}"160 ])161 assert Rooms.CATHETRAL.value.npc is None162 assert Items.ANTIDOTE.value not in CHARACTER.inventory163 assert CHARACTER.cures == 1164 def test_max_1_antidote_in_inventory(self):165 CHARACTER.room.loot = Inventory({166 Items.ANTIDOTE.value: 1167 })168 CHARACTER.inventory.add_item(Items.ANTIDOTE.value)169 execute_commands(commands=[170 f"take {Items.ANTIDOTE.value.name}"171 ])172 assert CHARACTER.inventory[Items.ANTIDOTE.value] == 1173 def test_view_map(self):174 CHARACTER.inventory.add_item(Items.MAP_STREET_FULL.value)175 execute_commands(commands=[176 f"view {Items.MAP_STREET_FULL.value.name}"177 ])178class TestFighting(Test):179 def test_fight(self):180 Rooms.KITCHEN.value.npc = NPC("dummy", health=1, base_damage=3)181 CHARACTER.room = Rooms.LOUNGE.value182 execute_commands(commands=[183 f"go {Rooms.KITCHEN.value.name}",184 "attack melee",185 ])186 assert CHARACTER.room.npc is None187 def test_npc_loot_drops_in_room_loot_if_inventory_full(self):188 CHARACTER.inventory.max_items = 1189 CHARACTER.inventory.add_item(Items.COIN.value)190 CHARACTER.melee_weapon = Items.KNIFE.value191 CHARACTER.health = CHARACTER.max_health192 CHARACTER.luck = MAX_LUCK+1193 CHARACTER.room = Rooms.LOUNGE.value194 Rooms.KITCHEN.value.loot = Inventory()195 Rooms.KITCHEN.value.npc = NPC(196 "dummy",197 health=1,198 base_damage=3,199 loot=Inventory({200 Items.ARMOR.value: 1201 }))202 execute_commands(commands=[203 f"go {Rooms.KITCHEN.value.name}",204 "attack melee"205 ])206 assert Items.ARMOR.value not in CHARACTER.inventory207 assert Items.ARMOR.value in Rooms.KITCHEN.value.loot208 def test_ammunition_decrease_after_fight(self):209 Rooms.KITCHEN.value.npc = NPC("dummy", health=1, base_damage=1)210 CHARACTER.health = CHARACTER.max_health211 CHARACTER.luck = MAX_LUCK+1212 CHARACTER.room = Rooms.LOUNGE.value213 CHARACTER.ranged_weapon = Items.PISTOL.value214 CHARACTER.ranged_weapon.ammunition = 1215 execute_commands(commands=[216 f"go {Rooms.KITCHEN.value.name}",217 "attack ranged",218 ])219 assert CHARACTER.ranged_weapon.ammunition == 0...

Full Screen

Full Screen

execute.py

Source:execute.py Github

copy

Full Screen

...30 lines=cfg["training"]["lines"]31 bin_dir=cfg["learning"]["bin_dir"]32 lm=cfg["learning"]["lm"]33 if os.path.isdir("./data-"+cfg["training"]["sl"]+"-"+cfg["training"]["tl"])==False:34 execute_commands(["mkdir data-{0}-{1}".format(sl,tl)])35 #Tag Corpus36 execute_commands("cat {0}.{1}.{2} | head -n {5} | apertium -d {4} {2}-{3}-tagger | apertium-pretransfer".format(corpus,pair,sl,tl,data,lines).split('|'),"data-{2}-{3}/{0}.tagged.{2}".format(corpus,pair,sl,tl,data,lines))37 execute_commands("cat {0}.{1}.{3} | head -n {5} | apertium -d {4} {3}-{2}-tagger | apertium-pretransfer".format(corpus,pair,sl,tl,data,lines).split('|'),"data-{2}-{3}/{0}.tagged.{3}".format(corpus,pair,sl,tl,data,lines))38 execute_commands("seq 1 {3}".format(corpus,sl,tl,lines).split('|'),"data-{1}-{2}/{0}.lines".format(corpus,sl,tl,lines))39 execute_commands("paste data-{1}-{2}/{0}.lines data-{1}-{2}/{0}.tagged.{1} data-{1}-{2}/{0}.tagged.{2} | grep '<' | cut -f1".format(corpus,sl,tl).split('|'),"data-{1}-{2}/{0}.lines.new".format(corpus,sl,tl))40 execute_commands("paste data-{1}-{2}/{0}.lines data-{1}-{2}/{0}.tagged.{1} data-{1}-{2}/{0}.tagged.{2} | grep '<' | cut -f2".format(corpus,sl,tl).split('|'),"data-{1}-{2}/{0}.tagged.{1}.new".format(corpus,sl,tl))41 execute_commands("paste data-{1}-{2}/{0}.lines data-{1}-{2}/{0}.tagged.{1} data-{1}-{2}/{0}.tagged.{2} | grep '<' | cut -f3".format(corpus,sl,tl).split('|'),"data-{1}-{2}/{0}.tagged.{2}.new".format(corpus,sl,tl))42 execute_commands("mv data-{1}-{2}/{0}.lines.new data-{1}-{2}/{0}.lines".format(corpus,sl,tl).split('|'))43 execute_commands("cat data-{1}-{2}/{0}.tagged.{1}.new | sed 's/ /~/g' | sed 's/\$[^\^]*/$ /g'".format(corpus,sl,tl).split('|'),"data-{1}-{2}/{0}.tagged.{1}".format(corpus,sl,tl))44 execute_commands("cat data-{1}-{2}/{0}.tagged.{2}.new | sed 's/ /~/g' | sed 's/\$[^\^]*/$ /g'".format(corpus,sl,tl).split('|'),"data-{1}-{2}/{0}.tagged.{2}".format(corpus,sl,tl))45 files_to_delete=glob.glob("data-{0}-{1}/*.new".format(sl,tl))46 for i in files_to_delete: os.remove(i)47 #Clean Corpus48 execute_commands("perl {3}/clean-corpus-n.perl data-{1}-{2}/{0}.tagged {1} {2} data-{1}-{2}/{0}.tag-clean 1 40".format(corpus,sl,tl,mosesdecoder).split('|'))49 #Align50 os.system("export PYTHONIOENCODING=utf-8")51 execute_commands("perl {3}/train-model.perl -external-bin-dir {4} -corpus data-{1}-{2}/{0}.tag-clean -f {2} -e {1} -alignment grow-diag-final-and -reordering msd-bidirectional-fe -lm 0:5:{5}:0 -mgiza".format(corpus,sl,tl,mosesdecoder,bin_dir,lm).split('|'),1,1)52 #Extract53 execute_commands("zcat giza.{1}-{2}/{1}-{2}.A3.final.gz | {3}/giza-to-moses.awk".format(corpus,sl,tl,scripts).split('|'),"data-{1}-{2}/{0}.phrasetable.{1}-{2}".format(corpus,sl,tl))54 #Trim Tags55 execute_commands("cat data-{1}-{2}/{0}.phrasetable.{1}-{2} | sed 's/ ||| /\t/g' | cut -f 1 | sed 's/~/ /g' | {4}/process-tagger-output {3}/$TL-$SL.autobil.bin -p -t".format(corpus,sl,tl,data,scripts).split(" | "),"tmp1")56 execute_commands("cat data-{1}-{2}/{0}.phrasetable.{1}-{2} | sed 's/ ||| /\t/g' | cut -f 2 | sed 's/~/ /g' | {4}/process-tagger-output {3}/$TL-$SL.autobil.bin -p -t".format(corpus,sl,tl,data,scripts).split(" | "),"tmp2")57 execute_commands("cat data-{1}-{2}/{0}.phrasetable.{1}-{2} | sed 's/ ||| /\t/g' | cut -f 3".format(corpus,sl,tl).split(" | "),"tmp3")58 execute_commands("cat data-{1}-{2}/{0}.phrasetable.{1}-{2} | sed 's/ ||| /\t/g' | cut -f 2 | sed 's/~/ /g' | {4}/process-tagger-output {3}/$TL-$SL.autobil.bin -b -t".format(corpus,sl,tl,data,scripts).split(" | "),"data-{2}-{3}/{0}.clean-biltrans.{1}".format(corpus,pair,sl,tl))59 execute_commands("paste tmp1 tmp2 tmp3 | sed 's/\t/ ||| /g'".split(" | "),"data-{1}-{2}/{0}.phrasetable.{1}-{2}".format(corpus,sl,tl))60 execute_commands("rm tmp1 tmp2 tmp3".split('|'))61 #Sentences62 execute_commands("python3 {4}/extract-sentences.py data-{2}-{3}/{0}.phrasetable.{2}-{3} data-{2}-{3}/{0}.clean-biltrans.{1}".format(corpus,pair,sl,tl,scripts).split('|'),"data-{1}-{2}/{0}.candidates.{1}-{2}".format(corpus,sl,tl),"/dev/null")63 #Frequency Lexicon64 execute_commands("python {3}/extract-freq-lexicon.py data-{1}-{2}/{0}.candidates.{1}-{2}".format(corpus,sl,tl,scripts).split('|'),"data-{1}-{2}/{0}.lex.{1}-{2}".format(corpus,sl,tl),"/dev/null")65def execute_commands(commands,stdout_arg=1,stderr_arg=2):66 """67 1) Executes piped commands. 68 2) Also takes arguments as to where to print the stdout and the stderr of the commands executed. 69 """70 list_of_commands=[]71 for i in range(len(commands)):72 stdin=073 stdout=subprocess.PIPE74 stderr=275 command=shlex.split(commands[i].strip())76 if i!=0:77 stdin=list_of_commands[i-1].stdout78 if i==(len(commands)-1):79 if type(stdout_arg)==str: stdout=open(stdout_arg,"w")...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import typer2import json3from src.parser import parse_commit, add_author_to_commands_and_environments, get_all_changelist4app = typer.Typer()5@app.command(name="commit-list")6def get_commit_list(dir: str = '.', since: str | None = None, until: str = 'HEAD'):7 list = get_commits(dir=dir, since=since, until=until)8 typer.echo(json.dumps(list))9@app.command(name="changelog")10def get_changelog(dir: str = '.', since: str | None = None, until: str = 'HEAD'):11 commits = get_commits(dir=dir, since=since, until=until)12 changelist = get_all_changelist(commits)13 changelog = {}14 for change in changelist:15 groups = change['group'] if 'group' in change and change['group'] is not None else ['other']16 type = change['type'] if 'type' in change and change['type'] is not None else 'unknown'17 for group in groups:18 if group not in changelog:19 changelog[group] = {}20 if type not in changelog[group]:21 changelog[group][type] = {22 "all_commits": [],23 "execute_commands": [],24 "added_environments": [],25 "changed_environments": []26 }27 changelog[group][type]['all_commits'] = [*changelog[group][type]['all_commits'], change['metadata']['title'] + change['metadata']['message']]28 changelog[group][type]['execute_commands'] = [*changelog[group][type]['execute_commands'], *change['execute_commands']]29 changelog[group][type]['added_environments'] = [*changelog[group][type]['added_environments'], *change['added_environments']]30 changelog[group][type]['changed_environments'] = [*changelog[group][type]['changed_environments'], *change['changed_environments']]31 typer.echo(json.dumps(changelog))32@app.command(name='deployment-note')33def get_deployment_note(dir: str = '.', since: str | None = None, until: str = 'HEAD'):34 commits = get_commits(dir=dir, since=since, until=until)35 changelog = get_all_changelist(commits)36 execute_commands = []37 added_environments = []38 changed_environments = []39 all_commits = []40 for change in changelog:41 execute_commands = [*execute_commands, *add_author_to_commands_and_environments(42 change['execute_commands'], change['metadata']43 )]44 added_environments = [*added_environments, *add_author_to_commands_and_environments(45 change['added_environments'], change['metadata']46 )]47 changed_environments = [*changed_environments, *add_author_to_commands_and_environments(48 change['changed_environments'], change['metadata']49 )]50 all_commits.append(51 change['metadata']['commit']52 )53 response = {54 "all_commits": all_commits,55 "execute_commands": execute_commands,56 "added_environments": added_environments,57 "changed_environments": changed_environments58 }59 typer.echo(json.dumps(response))60from src.helper import get_commits61if __name__ == '__main__':62 app()...

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