Esempio n. 1
0
def test_add_option():
    m = Menu()
    o1 = MenuOption(Menu("m1"))
    m.add_option(o1)
    assert m.options == (o1, )
    o2 = MenuOption(Menu("m2"))
    m.add_option(o2)
    assert m.options == (o1, o2)
Esempio n. 2
0
def test_evaluate_default():
    next_menu = Menu("Test Next Menu")
    eval_fn = lambda i: i == "token"
    action_fn = lambda i: "Test Fn"
    m = Menu("Test Main Menu",
             default=MenuOption(next_menu, evaluate=eval_fn, action=action_fn))
    m.add_option(MenuOption(Menu("m1")))

    action_result, menu_result = m.evaluate("test token")

    assert action_result == "Test Fn"
    assert menu_result == next_menu
Esempio n. 3
0
 def __init__(self,
              title="Menu",
              instr=("Please select from the following options:", ),
              default=None):
     self._title = title
     self._instr = instr
     self._options = []
     self._default = default if default is not None else MenuOption(self)
Esempio n. 4
0
def test_token():
    o = MenuOption(None, token="q")
    assert o.token == "q"
Esempio n. 5
0
def test_str():
    o = MenuOption(None, "token", "Test Description")
    assert str(o) == "[token]: Test Description"
Esempio n. 6
0
def test_hidden():
    o = MenuOption(None, hidden=True)
    assert o.hidden == True
Esempio n. 7
0
def test_next_menu():
    o = MenuOption("Test Object")
    assert o.next_menu == "Test Object"
Esempio n. 8
0
def test_action():
    fn = lambda i: "Test"
    o = MenuOption(None, action=fn)
    assert o.action == fn
Esempio n. 9
0
def test_evaluate():
    fn = lambda i: "Test"
    o = MenuOption(None, evaluate=fn)
    assert o.evaluate == fn
Esempio n. 10
0
def test_desc():
    o = MenuOption(None, desc="Test Description")
    assert o.desc == "Test Description"
Esempio n. 11
0
 def __init__(self):
     self.menu = MenuModel(MenuOption("New Game", States.PLAY),
                           MenuOption("Continue", States.CONTINUE),
                           MenuOption("Exit", States.EXIT))
     self.play = PlayModel()
Esempio n. 12
0
def test_add_options_tuple():
    m = Menu()
    otuple = (MenuOption(Menu("m1")), MenuOption(Menu("m2")))
    m.add_options(otuple)
    assert m.options == otuple
Esempio n. 13
0
def test_add_options_list():
    m = Menu()
    olist = [MenuOption(Menu("m1")), MenuOption(Menu("m2"))]
    m.add_options(olist)
    assert m.options == tuple(olist)