def test_currently_active_menu(self): menu1 = ConsoleMenu("menu1", "test_currently_active_menu_1") menu2 = ConsoleMenu("menu2", "test_currently_active_menu_2") menu3 = ConsoleMenu("menu3", "test_currently_active_menu_3") self.assertIsNone(ConsoleMenu.currently_active_menu) menu1.start() menu1.wait_for_start(10) self.assertIs(ConsoleMenu.currently_active_menu, menu1) menu2.start() menu2.wait_for_start(10) self.assertIs(ConsoleMenu.currently_active_menu, menu2) menu3.start() menu3.wait_for_start(10) self.assertIs(ConsoleMenu.currently_active_menu, menu3) menu3.join(timeout=5) menu2.join(timeout=5) menu1.join(timeout=5)
def test_action(self): root_menu = ConsoleMenu("root_menu", "test_action") submenu1 = ConsoleMenu("submenu1", "test_action") submenu2 = ConsoleMenu("submenu2", "test_action") submenu_item_1 = SubmenuItem("submenu_item_1", submenu1, menu=root_menu) submenu_item_2 = SubmenuItem("submenu_item_2", submenu2, menu=root_menu) root_menu.append_item(submenu_item_1) root_menu.append_item(submenu_item_2) root_menu.start() root_menu.wait_for_start(timeout=10) self.assertIs(ConsoleMenu.currently_active_menu, root_menu) submenu_item_1.action() submenu1.wait_for_start(timeout=10) self.assertIs(ConsoleMenu.currently_active_menu, submenu1) ConsoleMenu.currently_active_menu.exit() submenu1.join(timeout=10) self.assertIs(ConsoleMenu.currently_active_menu, root_menu) submenu_item_2.action() submenu2.wait_for_start(timeout=10) self.assertIs(ConsoleMenu.currently_active_menu, submenu2)
class TestSampleMenu(BaseTestCase): def setUp(self): super(TestSampleMenu, self).setUp() self.menu = ConsoleMenu("self.menu", "TestSampleMenu") self.item1 = MenuItem("self.item1", self.menu) self.item2 = MenuItem("self.item2", self.menu) self.menu.append_item(self.item1) self.menu.append_item(self.item2) self.menu.start() self.menu.wait_for_start(timeout=10) def tearDown(self): super(TestSampleMenu, self).tearDown() self.menu.exit() self.menu.join(timeout=10) def test_go_down(self): self.menu.go_down() self.assertEqual(self.menu.current_option, 1) self.assertIs(self.menu.current_item, self.item2) self.menu.go_down() self.assertEqual(self.menu.current_option, 2) self.assertEqual(self.menu.current_item, self.menu.exit_item) self.menu.go_down() self.assertEqual(self.menu.current_option, 0) self.assertIs(self.menu.current_item, self.item1) def test_go_up(self): self.menu.go_up() self.assertEqual(self.menu.current_option, 2) self.assertIs(self.menu.current_item, self.menu.exit_item) self.menu.go_up() self.assertEqual(self.menu.current_option, 1) self.assertEqual(self.menu.current_item, self.item2) self.menu.go_up() self.assertEqual(self.menu.current_option, 0) self.assertIs(self.menu.current_item, self.item1) def test_go_to(self): self.menu.go_to(1) self.assertEqual(self.menu.current_option, 1) self.assertEqual(self.menu.current_item, self.item2) def test_select(self): self.menu.select() self.assertEqual(self.menu.selected_option, 0) self.assertIs(self.menu.selected_item, self.item1) self.menu.go_down() self.menu.select() self.assertEqual(self.menu.selected_option, 1) self.assertIs(self.menu.selected_item, self.item2) self.menu.go_down() self.menu.select() self.assertEqual(self.menu.selected_option, 2) self.assertIs(self.menu.selected_item, self.menu.exit_item) self.menu.join(timeout=10) self.assertFalse(self.menu.is_alive()) def test_exit(self): self.assertTrue(self.menu.is_alive()) self.menu.exit() self.menu.join(timeout=10) self.assertFalse(self.menu.is_alive())