Exemple #1
0
def test_input_is_empty(mocked_cli):
    with pytest.raises(IllegalArgumentException):
        input_str = ""
        CommandParser.parse_input(input_str)
        mocked_cli.has_calls(
            "IllegalArgumentException: Please enter the module you want to execute"
        )
 def __print_main_help_information(self):
     self.__output_service.print_line(
         "These are the possible interactions:")
     for command in CommandParser.get_valid_commands():
         self.__output_service.print_line(command)
     self.__output_service.print_line(
         "for more information type in the command and -h or --help.")
def test_valid_label_remove_mode():
    input_string = "label remove algo1"
    expected = ["algo1"]
    command = CommandParser.parse_input(input_string)
    assert isinstance(command, LabelCommand)
    assert command.mode == LabelMode.REMOVE
    assert command.config == expected
Exemple #4
0
 def __get_command(self) -> Command:
     input_string = self.__view.read_input(
         "Which module do you want to execute?")
     try:
         command = CommandParser.parse_input(input_string)
     except IllegalArgumentException as e:
         self.__output_service.print_error(e)
         command = self.__get_command()
     return command
def test_valid_input_with_flag():
    input_string: str = "classify -p path -s -n network"
    command: Command = CommandParser.parse_input(input_string)
    assert isinstance(command, ClassifyCommand)
    expected: Dict[Key, str] = {
        Key.PATH: "path",
        Key.SOLVE: "",
        Key.NETWORK: "network"
    }
    assert dicts_equal(command.arguments, expected) is True
Exemple #6
0
def test_valid_label_mode():
    input_string = "label -n name --path path -s saving_path"
    expected = {
        Key.NAME: "name",
        Key.PATH: "path",
        Key.SAVING_PATH: "saving_path",
    }
    command = CommandParser.parse_input(input_string)
    assert isinstance(command, LabelCommand)
    assert dicts_equal(command.arguments, expected) is True
Exemple #7
0
def test_input_calls_with_two_spaces():
    input_str = "label  -n name -p path -s saving_path"
    expected = {
        Key.PATH: "path",
        Key.NAME: "name",
        Key.SAVING_PATH: "saving_path",
    }
    command = CommandParser.parse_input(input_str)
    assert isinstance(command, LabelCommand)
    assert dicts_equal(command.arguments, expected) is True
def test_valid_input_returns_command():
    input_string: str = "collect --name name --amount amount -p path --size size"
    expected = {
        Key.NAME: "name",
        Key.AMOUNT: "amount",
        Key.PATH: "path",
        Key.SIZE: "size"
    }
    command: Command = CommandParser.parse_input(input_string)
    assert isinstance(command, CollectCommand)
    assert dicts_equal(command.arguments, expected) is True
def test_valid_collector_input():
    input_string: str = "collect --amount amount -n name -s size -p path"
    command: Command = CommandParser.parse_input(input_string)
    assert isinstance(command, CollectCommand)
    expected: Dict[Key, str] = {
        Key.AMOUNT: "amount",
        Key.NAME: "name",
        Key.SIZE: "size",
        Key.PATH: "path"
    }
    assert dicts_equal(command.arguments, expected) is True
def test_valid_label_add_mode():
    input_string = "label add algo1 algo2 algo3"
    expected = [
        "algo1",
        "algo2",
        "algo3",
    ]
    command = CommandParser.parse_input(input_string)
    assert isinstance(command, LabelCommand)
    assert command.mode == LabelMode.ADD
    assert command.config == expected
def test_valid_input_with_arguments():
    input_string: str = "train -p path -n name -t train -s savingPath"
    command: Command = CommandParser.parse_input(input_string)
    assert isinstance(command, TrainCommand)
    expected: Dict[Key, str] = {
        Key.PATH: "path",
        Key.NAME: "name",
        Key.TRAIN: "train",
        Key.SAVING_PATH: "savingPath"
    }
    assert dicts_equal(command.arguments, expected) is True
def test_collector_with_missing_optional_args_adds_default():
    input_string = "collect -n name"
    size = Configurations.get_config_with_key(Module.COLLECT, Key.SIZE)
    amount = Configurations.get_config_with_key(Module.COLLECT, Key.AMOUNT)
    path = Configurations.get_config_with_key(Module.COLLECT, Key.PATH)
    expected = {
        Key.NAME: "name",
        Key.SIZE: size,
        Key.AMOUNT: amount,
        Key.PATH: path
    }
    command = CommandParser.parse_input(input_string)
    assert isinstance(command, CollectCommand)
    assert dicts_equal(command.arguments, expected) is True
def test_input_help_prints_help_info(mocked_cli, mocked_input):
    user_input = [
        "help",
        "quit",
    ]
    expected = [call("These are the possible interactions:")]
    expected += [call(info) for info in CommandParser.get_valid_commands()]
    expected += [
        call("for more information type in the command and -h or --help."),
        call("Finished")
    ]
    mocked_input.side_effect = user_input
    Controller().start_interaction()
    mocked_cli.print_line.asser_has_calls(expected)
def test_classify_command_with_missing_optional_arg_adds_default():
    input_str = "train -p path -n network"
    train = Configurations.get_config_with_key(Module.TRAIN, Key.TRAIN)
    saving_path = Configurations.get_config_with_key(Module.TRAIN,
                                                     Key.SAVING_PATH)
    expected = {
        Key.PATH: "path",
        Key.NAME: "network",
        Key.TRAIN: train,
        Key.SAVING_PATH: saving_path,
        Key.EXISTING_NETWORK: None,
    }
    command = CommandParser.parse_input(input_str)
    assert isinstance(command, TrainCommand)
    assert dicts_equal(command.arguments, expected) is True
def test_fails_when_entering_invalid_module():
    input_string = "generate -s size -a amount"
    with pytest.raises(IllegalArgumentException):
        CommandParser.parse_input(input_string)
def test_quit_with_arguments_throws_error():
    input_string = "quit -n name --density density"
    with pytest.raises(IllegalArgumentException):
        CommandParser.parse_input(input_string)
def test_invalid_mode_throws_exception():
    input_string: str = "label -n name -p path"
    with pytest.raises(IllegalArgumentException):
        CommandParser.parse_input(input_string)