Exemplo n.º 1
0
    def run(self):
        """Get input from user, run the condition functions and call setter callback at the end.

        Repeat asking user for input to the time when all the acceptance conditions will be satisfied.
        """
        screen = GetInputScreen(self._user_prompt)
        if self._conditions:
            for c in self._conditions:
                screen.add_acceptance_condition(c, self._report_func)

        screen.no_separator = self._no_separator

        ScreenHandler.push_screen_modal(screen)
        return screen.value
Exemplo n.º 2
0
    def run(self):
        """Get input from user, run the condition functions and call setter callback at the end.

        Repeat asking user for input to the time when all the acceptance conditions will be satisfied.
        """
        screen = GetInputScreen(self._user_prompt)
        if self._conditions:
            for c in self._conditions:
                screen.add_acceptance_condition(c, self._report_func)

        screen.no_separator = self._no_separator

        ScreenHandler.push_screen_modal(screen)
        return screen.value
    def test_gettext_with_condition_and_use_arg(self, stdout_mock, stdin_mock):
        prompt = "Type input"
        user_input = "y"
        stdin_mock.return_value = user_input

        screen = GetInputScreen(message=prompt)
        screen.add_acceptance_condition(self.acceptance_condition_test, "y")

        self.schedule_screen_and_run(screen)

        expected_msg = "%s: " % prompt
        expected_output = self.create_output_with_separators([expected_msg
                                                              ]).rstrip("\n")

        self.assertEqual(expected_output, stdout_mock.getvalue())
        self.assertTrue(self.args_used)
    def test_gettext_with_condition(self, stdout_mock, stdin_mock):
        prompt = "Type input"
        wrong_input = "wrong"
        condition = lambda x, _: x != wrong_input
        stdin_mock.side_effect = self.input_generator()

        screen = GetInputScreen(message=prompt)
        screen.add_acceptance_condition(condition)

        self.schedule_screen_and_run(screen)

        expected_output = self.create_output_with_separators(
            ["%s: %s: " % (prompt, prompt)]).rstrip("\n")

        self.assertEqual(expected_output, stdout_mock.getvalue())
        self.assertTrue(self.correct_input)
Exemplo n.º 5
0
    def input(self, args, key):

        if key == "1":
            kvm_name_input = GetInputScreen("Enter KVM Name")
            ScreenHandler.push_screen_modal(kvm_name_input)
            kvm_name_value = kvm_name_input.value
            args.update({"vm_name": kvm_name_value})
            return InputState.PROCESSED_AND_REDRAW

        if key == "2":
            kvm_hostname_input = GetInputScreen("Enter KVM Hostname")
            ScreenHandler.push_screen_modal(kvm_hostname_input)
            kvm_hostname_value = kvm_hostname_input.value
            args.update({"vm_hostname": kvm_hostname_value})
            return InputState.PROCESSED_AND_REDRAW

        return key
    def test_gettext(self, stdout_mock, stdin_mock):
        prompt = "Type input"
        input_text = "user input"
        screen = GetInputScreen(message=prompt)
        stdin_mock.return_value = input_text

        self.schedule_screen_and_run(screen)

        expected_output = self.create_output_with_separators(["%s: " % prompt
                                                              ]).rstrip('\n')

        self.assertEqual(expected_output, stdout_mock.getvalue())
        self.assertEqual(screen.value, input_text)