def parse_input(input_string: str) -> Command: arg_list = input_string.split() if not arg_list: raise IllegalArgumentException( "Please enter enter the module you want to execute") mode: str = arg_list.pop(0) if mode in CommandParser.__valid_commands: command_class = CommandParser.__valid_commands[mode] else: raise IllegalArgumentException("%s is not a valid command" % mode) command: Command = command_class() command.set_args(arg_list) return command
def get_int_value(self, key: Key) -> Optional[int]: result: int = None if key in self.arguments: try: result = int(self.arguments.get(key)) except ValueError: raise IllegalArgumentException( self.arguments.get(key) + " is not a integer") return result
def get_float_value(self, key: Key) -> Optional[float]: result: float = None if key in self.arguments: try: result = float(self.arguments.get(key)) except ValueError: raise IllegalArgumentException( self.arguments.get(key) + " is not a float") return result
def __print_prediction(matrix_file, network): key = list(matrix_file.keys())[0] if not Classifier.__check_regularity(key, matrix_file): raise IllegalArgumentException("The matrix is not regular") matrix = np.expand_dims(np.array(matrix_file[key], dtype=np.float64), axis=3) model = Classifier.__load_network(network) predictions = list(np.argmax(model.predict(matrix), axis=1)) Classifier.__print(predictions)
def __get_key(self, next_key: str) -> Key: key: Key = None if next_key.startswith("--"): key = self.__get_arguments_key(next_key[2:]) elif next_key.startswith("-"): key = self.__get_arguments_key(next_key[1:]) if key is None: raise IllegalArgumentException("%s is not a valid argument." % next_key) return key
def test_wrong_float_format_prints_error_message(mocked_input, mocked_print): user_input = ["train --train 0,72 -n name -p path", "quit"] expected_calls = [ call( IllegalArgumentException("").get_type() + ": 0,72 is not a float"), call("Finished") ] mocked_input.side_effect = user_input Controller().start_interaction() mocked_print.assert_has_calls(expected_calls)
def test_wrong_integer_format_prints_error_message(mocked_input, mocked_print): user_input = ["collect -n name -a 50.000", "quit"] expected_calls = [ call( IllegalArgumentException("").get_type() + ": 50.000 is not a integer"), call("Finished") ] mocked_input.side_effect = user_input Controller().start_interaction() mocked_print.assert_has_calls(expected_calls)
def test_print_error(mocked_cli): error = IllegalArgumentException("Error") output_service = CLIOutputService(mocked_cli) output_service.print_error(error) mocked_cli.assert_has_calls( [call.print(error.get_type() + ": " + "Error")])