예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
    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")
예제 #4
0
 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)
예제 #5
0
 def test_register_list(self):
     command_menu = opendir_dl.CommandMenu()
     command_menu.register_list(['help'], help)
     self.assertTrue(command_menu.commands, {"help": help})
예제 #6
0
 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)
예제 #7
0
 def test_register_string_command(self):
     command_menu = opendir_dl.CommandMenu()
     command_menu.register_string('help', help)
     self.assertTrue(command_menu.commands, {"help": help})
예제 #8
0
 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)
예제 #9
0
 def test_default_set(self):
     command_menu = opendir_dl.CommandMenu()
     command_menu.set_default(help)
     self.assertEqual(command_menu.default, help)