class TestCase(unittest.TestCase): def setUp(self): self.menu = Menu() self.menu.add("1", "foo") self.menu.add("2", "bar") def test_menu_1(self): setinput("1") result = self.menu.show() self.assertEqual("1", result) def test_menu_2(self): setinput("1") result = self.menu.show(returns="desc") self.assertEqual("foo", result) def test_menu_3(self): setinput("2") result = self.menu.show(returns="desc") self.assertEqual("bar", result) def test_menu_4(self): """Check for regression of fix from `0.4.1`.""" m1 = Menu() m1.add("1", "foo") m1.add("2", "bar") m2 = Menu() m2.add("a", "AAA") m2.add("b", "BBB") m2.add("c", "CCC") self.assertEqual(len(m1.entries), 2) self.assertEqual(len(m2.entries), 3)
def test_menu_3(test): """Check for enum_menu() functionality.""" menu = Menu() menu.add("s", "skip") items = ["foo", "bar"] menu = enum_menu(items, menu=menu) setinput("1") with test.assertRaises(EOFError): menu.show() setinput("s") result = menu.show(returns="desc") test.assertEqual("skip", result) setinput("2") result = menu.show(returns="desc") test.assertEqual("foo", result) setinput("3") result = menu.show(returns="desc") test.assertEqual("bar", result)
def test_menu_4(test): """Check for regression of fix from `0.4.1`.""" m1 = Menu() m1.add("1", "foo") m1.add("2", "bar") m2 = Menu() m2.add("a", "AAA") m2.add("b", "BBB") m2.add("c", "CCC") test.assertEqual(len(m1.entries), 2) test.assertEqual(len(m2.entries), 3)
def setUp(test): menu = Menu(returns="func") menu.add("a", "Add", lambda x,y: x+y, [1,2]) menu.add("s", "Sub", lambda x,y: x-y, [1,2]) test.menu = menu
def setUp(test): menu = Menu(returns="func") menu.add("a", "Add", lambda x, y: x + y, [1, 2]) menu.add("s", "Sub", lambda x, y: x - y, [1, 2]) test.menu = menu
import sys from qprompt import Menu, echo menu = Menu() menu.add("f", "foo", lambda: echo("foo selected!")) menu.add("b", "bar", lambda: echo("bar selected!")) arg = None for arg in sys.argv[1:]: menu.run(arg) if None == arg: menu.show()
from qprompt import Menu def foo(): print("foo") def bar(): print("bar") menu = Menu() menu.add("f", "foo", foo) menu.add("b", "bar", bar) menu.add("q", "quit") while "q" != menu.show(): pass