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_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 browse_menu(): def github(): auxly.open("https://github.com/jeffrimko/PopPage") def pypi(): auxly.open("https://pypi.org/project/PopPage/") def travis(): auxly.open("https://travis-ci.org/jeffrimko/PopPage") Menu(github, pypi, travis).main(header="Browse")
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 browse_menu(): def github(): auxly.open("https://github.com/jeffrimko/qprompt") def pypi(): auxly.open("https://pypi.org/project/qprompt/") def docs(): auxly.open("https://qprompt.readthedocs.io/") def travis(): auxly.open("https://travis-ci.org/jeffrimko/Qprompt") Menu(github, pypi, docs, travis).main(header="Browse")
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)
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_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)
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)
import sys import os import os.path as op import auxly from qprompt import Menu, alert, _guess_name, _guess_desc ##==============================================================# ## SECTION: Global Definitions # ##==============================================================# __version__ = "0.2.1" #: The main build menu. _MENU = Menu() #: Menu names that are reserved. RESV_NAMES = ["q"] #: Default script name with extension. SCRIPTNAME = "_Build.py" #: Regex used to find alternative script names. ALTSCRIPTREGEX = "_[A-Z][A-z0-9_-]*\.py$" #: Line that must be found in a file for it to be an alternative script. ALTDECLARATION = "# -*- ubuild -*-" ##==============================================================# ## SECTION: Function Definitions #
def setUp(test): test.menu = Menu() test.menu.add("1", "foo") test.menu.add("2", "bar")
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(self): self.menu = Menu() self.menu.add("1", "foo") self.menu.add("2", "bar")
def setUp(test): global TOTAL TOTAL = 0 test.menu = Menu(inc, dec)
def setUp(self): global TOTAL TOTAL = 0 self.menu = Menu(inc, dec)
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
def docs_menu(): Menu(readme_excerpt, all_docs, open_docs).main(header="Docs")
def package_menu(): Menu(install_package_locally, upload_to_pypi).main(header="Package")
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()