def test_to_string(self): expected = "CommandMethod('test_method', 'Some method', 0 parameters)" command_method = CommandMethod(test_method, "Some method") self.assertEqual(expected, repr(command_method)) self.assertEqual(expected, str(command_method)) self.assertEqual(expected, command_method.__str__()) self.assertEqual(expected, command_method.__repr__()) self.assertEqual(expected, f"{command_method}") self.assertEqual(expected, "{}".format(command_method))
def test_method_usage(self): command_method = CommandMethod( implementation=test_method, documentation="Test method documentation.", parameters=None, return_value=None) output = command_method.usage("test_module") result = read_doc_opt(output) self.assertEqual(result, output)
def test_help(self, arg1, arg2): params = [CommandParam(name=arg1, index=0)] commands = [ CommandMethod(implementation=example_method, parameters=params) ] command_module = CommandModule(name=arg2, command_list=commands) output = command_module.usage() self.assertTrue(arg1 in output) self.assertTrue(arg2 in output)
def test_module_usage(self): params = [ CommandParam(name="arg1", index=0, documentation="The first arg.", annotation=str, default_args=None) ] commands = [ CommandMethod(implementation=test_method, documentation="Henlo fren", parameters=params, return_value=CommandReturn()) ] command_module = CommandModule( name="test_module", documentation="Test module documentation.", version="1.0.0", command_list=commands) output = command_module.usage() result = read_doc_opt(output) self.assertEqual(result, output)
def test_incorrect_return_type(self, any_obj): with self.assertRaises(TypeError) as err: # noinspection PyTypeChecker _ = CommandMethod(implementation=test_method, return_value=any_obj) self.assertTrue("must be a CommandReturn" in str(err.exception))
def test_parameters_not_list(self, any_obj): with self.assertRaises(TypeError) as err: # noinspection PyTypeChecker _ = CommandMethod(implementation=test_method, parameters=any_obj) self.assertTrue("must be a list" in str(err.exception))
def invalid(): # noinspection PyTypeChecker _ = CommandMethod(implementation=non)
def test_not_callable(self, any_obj): with self.assertRaises(TypeError) as err: _ = CommandMethod(implementation=any_obj) self.assertTrue("must be callable" in str(err.exception))