How to use is_command_valid method in autotest

Best Python code snippet using autotest_python

test_maze.py

Source:test_maze.py Github

copy

Full Screen

...130 self.assertFalse(self.maze.is_itinerary_clear("S2"))131 self.assertFalse(self.maze.is_itinerary_clear("2"))132 self.assertFalse(self.maze.is_itinerary_clear("N2"))133 self.assertFalse(self.maze.is_itinerary_clear("E3"))134 def test_is_command_valid(self):135 self.assertFalse(self.maze.is_command_valid(""))136 self.assertFalse(self.maze.is_command_valid("A"))137 self.assertFalse(self.maze.is_command_valid("9"))138 self.assertTrue(self.maze.is_command_valid("N"))139 self.assertFalse(self.maze.is_command_valid("NN"))140 self.assertFalse(self.maze.is_command_valid("N/"))141 self.assertFalse(self.maze.is_command_valid("N-10"))142 self.assertFalse(self.maze.is_command_valid("S1"))143 self.assertFalse(self.maze.is_command_valid("W2"))144 self.assertFalse(self.maze.is_command_valid("E8"))145 self.assertTrue(self.maze.is_command_valid("Q"))146 self.assertFalse(self.maze.is_command_valid("Q1"))147 self.assertFalse(self.maze.is_command_valid("M"))148 self.assertFalse(self.maze.is_command_valid("MM"))149 self.assertFalse(self.maze.is_command_valid("M9"))150 self.assertFalse(self.maze.is_command_valid("M."))151 self.assertTrue(self.maze.is_command_valid("MN"))152 def test_move(self):153 self.maze.move("N1")154 self.assertEqual(self.maze.map, test_maps_1N)155 self.maze.move("S1")156 self.assertEqual(self.maze.map, test_maps)157 self.maze.move("E1")158 self.assertEqual(self.maze.map, test_maps_1E)159 self.maze.move("W1")160 self.assertEqual(self.maze.map, test_maps)161 def test_put_wall(self):162 self.maze.put_door("PW")163 self.assertEqual(self.maze.clean_map, clean_test_maps_door_W)164 self.maze.put_wall("MW")165 self.assertEqual(self.maze.clean_map, clean_test_maps)...

Full Screen

Full Screen

Command_Parser.py

Source:Command_Parser.py Github

copy

Full Screen

...6 user_input = user_input.lower().split()7 if len(user_input) == 0: # Empty strings are always invalid commands.8 return Constants.INVALID_COMMAND_GIVEN_STRING9 # Check to see if the first word is a proper command.10 if not is_command_valid(user_input[0], Constants.VALID_COMMANDS):11 return Constants.INVALID_COMMAND_GIVEN_STRING12 # If a command is one word, it shouldn't have a target.13 if len(user_input) == 1:14 return parse_untargetable_command(user_input, player)15 return parse_targetable_command(user_input, player)16# Handles single-word commands with no target, such as 'help' or 'inventory'.17def parse_untargetable_command(user_input, player):18 command = user_input[0]19 if command in Constants.DIRECTIONS[0]:20 return Commands.parse_move_command(user_input, player)21 if command in Constants.HELP:22 return Commands.parse_help_command()23 if command in Constants.LOOK:24 return Commands.parse_look_command(player)25 if command in Constants.QUIT:26 return Commands.parse_quit_command()27 if command in Constants.INVENTORY:28 return Commands.parse_inventory_command(player)29 # If the command is in the targeted commands like 'examine' or 'give', tell the player this.30 if is_command_valid(user_input, Constants.SINGLE_TARGET_COMMANDS +31 Constants.DOUBLE_TARGET_COMMANDS):32 return Constants.IMPROPERLY_TARGETED_COMMAND33 return Constants.INVALID_COMMAND_GIVEN_STRING34# Parse a command with one or more targets, like "examine ball", or "give ball jay".35def parse_targetable_command(user_input, player):36 command = user_input[0]37 # This should not occur - one-word commands should always go to parse_untargetable_command.38 if len(user_input) < 2:39 return Constants.IMPROPERLY_PARSED_COMMAND40 # Parse a command with only one target, like 'get <item>'41 if is_command_valid(command, Constants.SINGLE_TARGET_COMMANDS):42 return parse_single_target_command(user_input, player)43 # Parse a command with two targets, like 'give <person> <item>'.44 if is_command_valid(command, Constants.DOUBLE_TARGET_COMMANDS):45 return parse_double_target_command(user_input, player)46 return Constants.INVALID_COMMAND_GIVEN_STRING47def parse_single_target_command(user_input, player):48 command = user_input[0]49 if command in Constants.EXAMINE:50 return Commands.parse_examine_command(user_input, player)51 if command in Constants.TAKE:52 return Commands.parse_take_command(user_input, player)53 if command in Constants.TALK:54 return Commands.parse_talk_command(user_input, player)55 return Constants.INVALID_COMMAND_GIVEN_STRING56def parse_double_target_command(user_input, player):57 command = user_input[0]58 if command in Constants.GIVE:59 return Commands.parse_give_command(user_input, player)60 return Constants.INVALID_COMMAND_GIVEN_STRING61# Searches all valid commands. Returns True if the user command is present, else returns False.62def is_command_valid(user_input, allowable_commands):63 # Flatten the list of allowable commands, since many allowable commands are a list64 # of allowable commands, like ['h', 'help', 'hint'] that return the same command.65 flat_allowable_commands = []66 for sublist in allowable_commands:67 for item in sublist:68 flat_allowable_commands.append(item)69 for command in flat_allowable_commands:70 if command in [user_input, user_input[0]]: # TODO: Fix hack?71 return True...

Full Screen

Full Screen

commands_handler.py

Source:commands_handler.py Github

copy

Full Screen

1from services.pipocoin_commands import command_list2def execute_command_stack(command_stack, origin):3 if is_command_valid(command_stack):4 command = command_list[command_stack.pop(0)]5 message = command(origin, command_stack)6 else:7 message = "Invalid command."8 return message9def is_command_valid(command_stack):10 if command_stack and command_list[command_stack[0]]:11 return True12 else:...

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