How to use process_input method in autotest

Best Python code snippet using autotest_python

test_menus.py

Source:test_menus.py Github

copy

Full Screen

...20class MenusTest(unittest.TestCase):21 def check_neutral(self, menu, pause=False):22 for action in [Action.MOVE_LEFT, Action.MOVE_RIGHT, Action.TOGGLE_INVENTORY, Action.PICK_PUT] + \23 ([Action.TOGGLE_PAUSE] if not pause else []):24 self.assertEqual(menu.process_input(action), menu.menu_state)25 self.assertEqual(menu.selected_option, 0)26 def test_simple_menu(self):27 n_options = 2028 menu_state = "MENU_STATE"29 class DummyMenu(SimpleMenu):30 def __init__(self):31 super().__init__([(f'Option {i}', i) for i in range(n_options)], "title", menu_state)32 def process_select(self):33 return self.options[self.selected_option][1]34 menu = DummyMenu()35 self.assertEqual(menu.selected_option, 0)36 self.check_neutral(menu)37 for i in range(1, n_options * 3):38 self.assertEqual(menu.process_input(Action.MOVE_DOWN), menu_state)39 self.assertEqual(menu.selected_option, i % n_options)40 self.assertEqual(menu.process_input(Action.SELECT), i % n_options)41 self.assertEqual(menu.process_select(), i % n_options)42 menu.open()43 self.assertEqual(menu.selected_option, 0)44 for i in range(n_options * 3 - 1, -1, -1):45 self.assertEqual(menu.process_input(Action.MOVE_UP), menu_state)46 self.assertEqual(menu.selected_option, i % n_options)47 self.assertEqual(menu.process_input(Action.SELECT), i % n_options)48 self.assertEqual(menu.process_select(), i % n_options)49 def test_err(self):50 state = "Next"51 msg = ErrorMsg(state)52 self.check_neutral(msg)53 for action in [Action.MOVE_DOWN, Action.MOVE_UP]:54 self.assertEqual(msg.process_input(action), msg.menu_state)55 self.assertEqual(msg.selected_option, 0)56 self.assertEqual(msg.process_input(Action.SELECT), state)57 def test_lvl_select(self):58 n_levels = 559 class DummyLoader:60 number_of_levels = n_levels61 current_level = 062 loader = DummyLoader()63 menu = LvlSelectMenu(loader)64 self.check_neutral(menu)65 for i in range(n_levels):66 self.assertEqual(menu.process_input(Action.SELECT), State.LEVEL)67 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.LEVEL_SELECTION)68 self.assertEqual(loader.current_level, i)69 self.assertEqual(menu.process_input(Action.SELECT), State.MAIN_MENU)70 def test_main_menu(self):71 menu = MainMenu()72 self.check_neutral(menu)73 self.assertEqual(menu.process_input(Action.SELECT), State.LEVEL)74 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.MAIN_MENU)75 self.assertEqual(menu.process_input(Action.SELECT), State.DUNGEON)76 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.MAIN_MENU)77 self.assertEqual(menu.process_input(Action.SELECT), State.LEVEL_SELECTION)78 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.MAIN_MENU)79 self.assertEqual(menu.process_input(Action.SELECT), State.LOAD)80 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.MAIN_MENU)81 self.assertEqual(menu.process_input(Action.SELECT), State.EXIT)82 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.MAIN_MENU)83 def test_pause_menu(self):84 menu = PauseMenu()85 self.check_neutral(menu, True)86 self.assertEqual(menu.process_input(Action.SELECT), State.LEVEL)87 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.PAUSE_MENU)88 self.assertEqual(menu.process_input(Action.SELECT), State.SAVE)89 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.PAUSE_MENU)90 self.assertEqual(menu.process_input(Action.SELECT), State.SWITCH_VISION)91 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.PAUSE_MENU)92 self.assertEqual(menu.process_input(Action.SELECT), State.MAIN_MENU)93 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.PAUSE_MENU)94 self.assertEqual(menu.process_input(Action.TOGGLE_PAUSE), State.LEVEL)95 def test_inventory(self):96 player = PlayerCharacter(0, 0)97 cwd = os.path.realpath(__file__)98 path = Path(cwd)99 levels_dir = str(path.parent.absolute()) + os.sep + 'resources' + os.sep100 loader = LevelLoader()101 level = loader.load_from_file(levels_dir + 'level_1.lvl', player)102 n_items = 10103 menu = InventoryMenu(player, level)104 random.seed(0)105 for _ in range(n_items):106 player.inventory.add_item(107 InventoryItem(stats=Stats(0, random.randint(-5, 5), random.randint(-5, 5), 0), can_be_equipped=True))108 class DummyEntity(ActingEntity):109 def update(self, mediator):110 pass111 _ITEM_TO_ENTITY_FUNC[InventoryItem] = lambda x, y: DummyEntity(x, y, False, None)112 stats_player = deepcopy(player.stats)113 self.assertEqual(menu.selected_option, 0)114 for action in [Action.MOVE_LEFT, Action.MOVE_RIGHT]:115 self.assertEqual(menu.process_input(action), menu.menu_state)116 self.assertEqual(menu.selected_option, 0)117 for i in range(1, n_items * 3):118 self.assertEqual(menu.process_input(Action.MOVE_DOWN), State.INVENTORY)119 self.assertEqual(menu.selected_option, i % n_items)120 self.assertEqual(menu.process_input(Action.SELECT), State.INVENTORY)121 self.assertEqual(player.stats, stats_player + player.inventory.items[i % n_items].stats)122 self.assertEqual(menu.process_input(Action.SELECT), State.INVENTORY)123 self.assertEqual(player.stats, stats_player)124 menu.open()125 self.assertEqual(menu.selected_option, 0)126 for i in range(n_items * 3 - 1, -1, -1):127 self.assertEqual(menu.process_input(Action.MOVE_UP), State.INVENTORY)128 self.assertEqual(menu.selected_option, i % n_items)129 self.assertEqual(menu.process_input(Action.SELECT), State.INVENTORY)130 self.assertEqual(player.stats, stats_player + player.inventory.items[i % n_items].stats)131 self.assertEqual(menu.process_input(Action.SELECT), State.INVENTORY)132 self.assertEqual(player.stats, stats_player)133 for i in range(1, n_items + 1):134 self.assertEqual(menu.process_input(Action.PICK_PUT), State.INVENTORY)135 self.assertEqual(len(player.inventory.items), n_items - i)136 self.assertEqual(len(level.acting_entities), i + 1)137 for ent in level.acting_entities:138 self.assertEqual((player.x, player.y), (ent.x, ent.y))139if __name__ == '__main__':...

Full Screen

Full Screen

test_shell.py

Source:test_shell.py Github

copy

Full Screen

...21 1 3 1822 > echo 123 | wc23 1 1 324 """25 command_result = self.shell.process_input('echo "Hello, world!"')26 self.assertEqual(command_result.get_output(), 27 'Hello, world!{}'.format(os.linesep))28 self.assertEqual(command_result.get_return_code(), 0)29 # This `cd` is necessary for finding `example.txt` file.30 command_result = self.shell.process_input('cd {}'.format(BASE_DIR))31 command_result = self.shell.process_input('FILE=example.txt')32 self.shell.apply_command_result(command_result)33 self.assertEqual(command_result.get_output(), '')34 self.assertEqual(command_result.get_return_code(), 0)35 command_result = self.shell.process_input('cat $FILE')36 self.assertEqual(command_result.get_output(), 'Some example text\n')37 self.assertEqual(command_result.get_return_code(), 0)38 command_result = self.shell.process_input('cat $FILE | wc')39 self.assertEqual(command_result.get_output(), '1 3 18')40 self.assertEqual(command_result.get_return_code(), 0)41 command_result = self.shell.process_input('echo 123 | wc')42 exp_length = 3 + len(os.linesep)43 self.assertEqual(command_result.get_output(), '1 1 {}'.format(exp_length))44 self.assertEqual(command_result.get_return_code(), 0)45 def test_subst_exit(self):46 """Test that string expansion works for substituting commands.47 """48 command_result = self.shell.process_input('x=exit')49 self.shell.apply_command_result(command_result)50 self.assertRaises(exceptions.ExitException,51 self.shell.process_input, '$x')52 def test_cat_wc(self):53 """A simple piped command: cd; cat smth | wc54 """55 command_result = self.shell.process_input('cd {}'.format(BASE_DIR))56 command_result = self.shell.process_input('cat wc_file.txt | wc')57 self.assertEqual(command_result.get_output(), '2 6 24')58 def test_cd_pwd(self):59 """A simple script execution: cd; pwd.60 """61 command_result = self.shell.process_input('cd {}'.format(BASE_DIR))62 command_result = self.shell.process_input('pwd')63 self.assertEqual(command_result.get_output(), BASE_DIR)64 def test_repeatable_commands(self):65 """A `long` session with a user should not fail.66 """67 for i in range(1000):68 command_result = self.shell.process_input('echo 1=1')...

Full Screen

Full Screen

test_Game.py

Source:test_Game.py Github

copy

Full Screen

...91011def test_Game_inputs():12 game = Game()13 game.process_input(UserInput.ARROW_LEFT)14 game.process_input(UserInput.ARROW_RIGHT)15 game.process_input(UserInput.ENTER)16 game.process_input(UserInput.ENTER)17 game.process_input(UserInput.ARROW_RIGHT)18 game.process_input(UserInput.ENTER)19 game.process_input(UserInput.ENTER)20 game.process_input(UserInput.ARROW_RIGHT)21 game.process_input(UserInput.ENTER)22 game.process_input(UserInput.ENTER)23 game.process_input(UserInput.ARROW_RIGHT)24 assert(game._is_match_ongoing())2526 game.process_input(UserInput.ENTER)27 assert not(game._is_match_ongoing())2829 game.process_input(UserInput.ENTER)30 assert not(game._is_match_ongoing())3132 game.process_input(UserInput.KEY_R) ...

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