Example #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)
Example #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)
Example #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)
Example #4
0
    def test_menu_1(test):
        """Check for menu enum() functionality."""
        menu = Menu()
        menu.enum("foo")
        menu.enum("bar")

        setinput("1")
        result = menu.show()
        test.assertEqual("1", result)

        setinput("1")
        result = menu.show(returns="desc")
        test.assertEqual("foo", result)

        setinput("2")
        result = menu.show(returns="desc")
        test.assertEqual("bar", result)

        setinput("3\n2")
        result = menu.show(returns="desc")
        test.assertEqual("bar", result)
Example #5
0
    def test_menu_1(test):
        """Check for menu enum() functionality."""
        menu = Menu()
        menu.enum("foo")
        menu.enum("bar")

        setinput("1")
        result = menu.show()
        test.assertEqual("1", result)

        setinput("1")
        result = menu.show(returns="desc")
        test.assertEqual("foo", result)

        setinput("2")
        result = menu.show(returns="desc")
        test.assertEqual("bar", result)

        setinput("3\n2")
        result = menu.show(returns="desc")
        test.assertEqual("bar", result)
Example #6
0
class TestCase(unittest.TestCase):
    def setUp(self):
        global TOTAL
        TOTAL = 0
        self.menu = Menu(inc, dec)

    def test_menu_1(self):
        global TOTAL
        setinput("i")
        result = self.menu.show()
        self.assertEqual(1, TOTAL)

    def test_menu_2(self):
        global TOTAL
        setinput("d")
        result = self.menu.show()
        self.assertEqual(-1, TOTAL)

    def test_menu_3(self):
        global TOTAL
        setinput("i\ni\nd\ni\n")
        result = self.menu.main(loop=True)
        self.assertEqual(2, TOTAL)
Example #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()
Example #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