def test_get_unregistered_command(self): value_list = ["missing", "path"] command_menu = opendir_dl.CommandMenu() with self.assertRaises(ValueError) as context: command_menu.get(value_list) expected_error = "No command registered with the path '{}'.".format( value_list) self.assertEqual(str(context.exception), expected_error)
def test_no_default_set(self): command_menu = opendir_dl.CommandMenu() target_command_ref = command_menu.get([]) self.assertEqual(target_command_ref, command_menu.raise_no_default) with self.assertRaises(ValueError) as context: target_command_ref() expected_error = "No default action was set for this command." self.assertEqual(str(context.exception), expected_error)
def test_register_decorator(self): command_menu = opendir_dl.CommandMenu() @command_menu.register("foo") def foo(): return "foo" self.assertEqual(command_menu.commands.keys(), ["foo"]) target_command_ref = command_menu.get(["foo"]) self.assertEqual(target_command_ref(), "foo")
def test_get_command(self): command_menu = opendir_dl.CommandMenu() command_menu.register_list(["help", "tier2"], help) target_command_ref = command_menu.get(["help", "tier2"]) self.assertEqual(target_command_ref, help)
def test_register_list(self): command_menu = opendir_dl.CommandMenu() command_menu.register_list(['help'], help) self.assertTrue(command_menu.commands, {"help": help})
def test_register_list_not_list(self): command_menu = opendir_dl.CommandMenu() with self.assertRaises(TypeError) as context: command_menu.register_list("this object is not a list", help) expected_error = "Value for command_list should be of type 'list'." self.assertEqual(str(context.exception), expected_error)
def test_register_string_command(self): command_menu = opendir_dl.CommandMenu() command_menu.register_string('help', help) self.assertTrue(command_menu.commands, {"help": help})
def test_register_string_default(self): command_menu = opendir_dl.CommandMenu() command_menu.register_string("help", None) self.assertEqual(command_menu.get(["help"]), None) command_menu.register_string("help", help) self.assertEqual(command_menu.get(["help"]), help)
def test_default_set(self): command_menu = opendir_dl.CommandMenu() command_menu.set_default(help) self.assertEqual(command_menu.default, help)