示例#1
0
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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
    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)
示例#5
0
 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
示例#6
0
 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
示例#7
0
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()
示例#8
0
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