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)
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
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)
def test_token(): o = MenuOption(None, token="q") assert o.token == "q"
def test_str(): o = MenuOption(None, "token", "Test Description") assert str(o) == "[token]: Test Description"
def test_hidden(): o = MenuOption(None, hidden=True) assert o.hidden == True
def test_next_menu(): o = MenuOption("Test Object") assert o.next_menu == "Test Object"
def test_action(): fn = lambda i: "Test" o = MenuOption(None, action=fn) assert o.action == fn
def test_evaluate(): fn = lambda i: "Test" o = MenuOption(None, evaluate=fn) assert o.evaluate == fn
def test_desc(): o = MenuOption(None, desc="Test Description") assert o.desc == "Test Description"
def __init__(self): self.menu = MenuModel(MenuOption("New Game", States.PLAY), MenuOption("Continue", States.CONTINUE), MenuOption("Exit", States.EXIT)) self.play = PlayModel()
def test_add_options_tuple(): m = Menu() otuple = (MenuOption(Menu("m1")), MenuOption(Menu("m2"))) m.add_options(otuple) assert m.options == otuple
def test_add_options_list(): m = Menu() olist = [MenuOption(Menu("m1")), MenuOption(Menu("m2"))] m.add_options(olist) assert m.options == tuple(olist)