def test_concurrent_input_without_check(self, input_mock, output_mock):
        input_mock.side_effect = self._wait_for_concurrent_call

        h = InputHandler()
        h2 = InputHandler()
        h.set_callback(self._test_callback)
        h2.set_callback(self._test_callback2)
        h2.skip_concurrency_check = True
        h.skip_concurrency_check = True

        h.get_input(Prompt(message="ABC"))
        self._thread_event_wait_for_inner.wait()
        h2.get_input(Prompt(message="ABC"))
        self._thread_event_wait_for_outer.set()

        h.wait_on_input()
        h2.wait_on_input()

        self.assertFalse(self._callback_called)
        self.assertFalse(h.input_successful())

        self.assertTrue(self._callback_called2)
        self.assertTrue(h2.input_successful())
        self.assertEqual(self._callback_input2, "thread 0")
        self.assertEqual(h2.value, "thread 0")
    def test_concurrent_input_with_source(self, input_mock, output_mock):
        input_mock.side_effect = self._wait_for_concurrent_call
        source1 = Mock()
        source2 = Mock()

        h = InputHandler(source=source1)
        h2 = InputHandler(source=source2)
        h.set_callback(self._test_callback)
        h2.set_callback(self._test_callback2)

        with self.assertRaisesRegex(
                KeyError, r'.*Input handler:.*InputHandler object'
                r'.*Input requester:.*Mock'
                r'.*Input handler:.*InputHandler object'
                r'.*Input requester:.*Mock.*'):
            h.get_input(Prompt(message="ABC"))
            self._thread_event_wait_for_inner.wait()
            h2.get_input(Prompt(message="ABC"))

        self.assertFalse(self._callback_called)
        self.assertEqual(self._callback_input, "")
        self.assertEqual(h.value, None)

        self.assertFalse(self._callback_called2)
        self.assertEqual(self._callback_input2, "")
        self.assertEqual(h2.value, None)
예제 #3
0
    def test_help_option(self):
        # help option
        p = Prompt()
        p.add_help_option()
        self._check_default_option(p, Prompt.HELP, Prompt.HELP_DESCRIPTION)

        # test add with description
        p = Prompt()
        p.add_help_option("Other help")
        self._check_default_option(p, Prompt.HELP, "Other help")

        # change existing description
        p.add_help_option("New help")
        self._check_default_option(p, Prompt.HELP, "New help")
예제 #4
0
    def test_refresh_option(self):
        # refresh option
        p = Prompt()
        p.add_refresh_option()
        self._check_default_option(p, Prompt.REFRESH, Prompt.REFRESH_DESCRIPTION)

        # test add with description
        p = Prompt()
        p.add_refresh_option("Other refresh")
        self._check_default_option(p, Prompt.REFRESH, "Other refresh")

        # change existing description
        p.add_refresh_option("New refresh")
        self._check_default_option(p, Prompt.REFRESH, "New refresh")
예제 #5
0
    def test_quit_option(self):
        # quit option
        p = Prompt()
        p.add_quit_option()
        self._check_default_option(p, Prompt.QUIT, Prompt.QUIT_DESCRIPTION)

        # test add with description
        p = Prompt()
        p.add_quit_option("Other quit")
        self._check_default_option(p, Prompt.QUIT, "Other quit")

        # change existing description
        p.add_quit_option("New quit")
        self._check_default_option(p, Prompt.QUIT, "New quit")
예제 #6
0
    def test_continue_option(self):
        # continue option
        p = Prompt()
        p.add_continue_option()
        self._check_default_option(p, Prompt.CONTINUE, Prompt.CONTINUE_DESCRIPTION)

        # test add with description
        p = Prompt()
        p.add_continue_option("Other continue")
        self._check_default_option(p, Prompt.CONTINUE, "Other continue")

        # change existing description
        p.add_continue_option("New continue")
        self._check_default_option(p, Prompt.CONTINUE, "New continue")
예제 #7
0
 def prompt(self, args=None):
     return Prompt(_("Please respond '%(yes)s' or '%(no)s'") % {
         # TRANSLATORS: 'yes' as positive reply
         "yes": C_('TUI|Spoke Navigation', 'yes'),
         # TRANSLATORS: 'no' as negative reply
         "no": C_('TUI|Spoke Navigation', 'no')
     })
예제 #8
0
 def prompt(self, args=None):
     """ Override the default TUI prompt."""
     return Prompt(
              _("Please make your selection from the above list.\n"
                "Press '%(continue)s' to continue after you have made your selection") % {
                  # TRANSLATORS:'c' to continue
                  'continue': C_('TUI|Root Selection', 'c'),
                })
    def test_async_input(self, input_mock, output_mock):
        input_mock.return_value = 'a'

        h = InputHandler()
        h.get_input(Prompt(message="ABC"))
        h.wait_on_input()

        self.assertEqual(h.value, 'a')
예제 #10
0
 def prompt(self, args=None):
     """ Override the default TUI prompt."""
     if self._rescue.automated:
         if self._rescue.mount:
             self._mount_root()
         self._show_result_and_prompt_for_shell()
         return None
     return Prompt()
예제 #11
0
    def prompt(self, args=None):
        # the title is enough, no custom prompt is needed
        if self._value is None:  # first run or nothing entered
            return Prompt(
                _("Enter an NTP server address and press %s") % Prompt.ENTER)

        # an NTP server address has been entered
        self._add_ntp_server(self._value)

        self.close()
    def test_input_received(self, input_mock, output_mock):
        input_mock.return_value = 'a'

        h = InputHandler()

        self.assertFalse(h.input_received())

        h.get_input(Prompt(message="ABC"))
        h.wait_on_input()

        self.assertTrue(h.input_received())
예제 #13
0
 def prompt(self, args=None):
     """ Override the default TUI prompt."""
     if self._rescue.automated:
         if self._rescue.reboot and self._rescue.status == RescueModeStatus.ROOT_NOT_FOUND:
             delay = 5
         else:
             delay = 0
             self._rescue.run_shell()
         self._rescue.finish(delay=delay)
         return None
     return Prompt(_("Please press %s to get a shell") % Prompt.ENTER)
    def test_input_callback(self, input_mock, output_mock):
        input_value = 'abc'
        input_mock.return_value = input_value

        h = InputHandler()
        h.set_callback(self._test_callback)
        h.get_input(Prompt(message="ABC"))
        h.wait_on_input()

        self.assertTrue(self._callback_called)
        self.assertEqual(self._callback_input, input_value)
        self.assertEqual(h.value, input_value)
예제 #15
0
    def prompt(self, args=None):
        """Return the text to be shown as prompt or handle the prompt and return None.

        :param args: optional argument passed from switch_screen calls
        :type args: anything
        :return: returns an instance of Prompt with text to be shown next to the prompt
                 for input or None to skip further input processing
        :rtype: Prompt instance|None
        """
        prompt = Prompt()
        prompt.add_refresh_option()
        prompt.add_continue_option()
        prompt.add_quit_option()
        return prompt
예제 #16
0
    def test_prompt_message(self):
        p = Prompt()

        self.assertEqual(p.message, Prompt.DEFAULT_MESSAGE)

        p.set_message("Brand new message")
        self.assertEqual(p.message, "Brand new message")

        p.set_message(u"Žluťoučký kůň")
        self.assertEqual(p.message, u"Žluťoučký kůň")

        p2 = Prompt("Default prompt text")
        self.assertEqual(p2.message, "Default prompt text")
예제 #17
0
    def prompt(self, args=None):
        """
        The prompt method that is called by the main loop to get the prompt
        for this screen.

        :see: simpleline.render.prompt.Prompt

        :param args: optional argument that can be passed to App.switch_screen*
                     methods
        :type args: anything
        :return: text that should be used in the prompt for the input
        :rtype: instance of simpleline.render.prompt.Prompt or None
        """

        return Prompt(_("Enter a new text or leave empty to use the old one"))
예제 #18
0
    def _print_widget(self, widget):
        """Prints a widget with user interaction (when needed).

        Could be longer than the screen height.

        :param widget: widget to print
        :type widget: Widget instance
        """
        # TODO: Work even for lower screen_height than 4
        pos = 0
        lines = widget.get_lines()
        num_lines = len(lines)

        if num_lines == 0:
            return

        prompt_height = 2
        real_screen_height = self._screen_height - prompt_height

        if num_lines < real_screen_height:
            # widget plus prompt are shorter than screen height, just print the widget
            print("\n".join(lines))
            return

        # long widget, print it in steps and prompt user to continue
        last_line = num_lines - 1
        while pos <= last_line:
            if pos + real_screen_height > last_line:
                # enough space to print the rest of the widget plus regular
                # prompt (2 lines)
                for line in lines[pos:]:
                    print(line)
                pos += self._screen_height - 1
            else:
                # print part with a prompt to continue
                for line in lines[pos:(pos + real_screen_height)]:
                    print(line)
                custom_prompt = Prompt(
                    _("\nPress %s to continue") % Prompt.ENTER)
                self._ask_user_input_blocking(custom_prompt)
                pos += real_screen_height
예제 #19
0
    def prompt(self, args=None):
        entry = args
        if not entry:
            return None

        if entry.aux == self.PASSWORD:
            pw = self.get_user_input(_("%s: ") % entry.title, hidden=True)
            confirm = self.get_user_input(_("%s (confirm): ") % entry.title,
                                          hidden=True)

            if (pw and not confirm) or (confirm and not pw):
                print(
                    _("You must enter your root password and confirm it by typing"
                      " it a second time to continue."))
                return None
            if pw != confirm:
                print(_(PASSWORD_CONFIRM_ERROR_TUI))
                return None

            # If an empty password was provided, unset the value
            if not pw:
                self.value = ""
                return None

            pw_score, _status_text, pw_quality, error_message = validatePassword(
                pw, user=None, minlen=self.policy.minlen)

            # if the score is equal to 0 and we have an error message set
            if not pw_score and error_message:
                print(error_message)
                return None

            if pw_quality < self.policy.minquality:
                if self.policy.strict:
                    done_msg = ""
                else:
                    done_msg = _("\nWould you like to use it anyway?")

                if error_message:
                    error = _(PASSWORD_WEAK_WITH_ERROR
                              ) % error_message + " " + done_msg
                else:
                    error = _(PASSWORD_WEAK) % done_msg

                if not self.policy.strict:
                    question_window = YesNoDialog(error)
                    ScreenHandler.push_screen_modal(question_window)
                    if not question_window.answer:
                        return None
                else:
                    print(error)
                    return None

            if any(char not in PW_ASCII_CHARS for char in pw):
                print(
                    _("You have provided a password containing non-ASCII characters.\n"
                      "You may not be able to switch between keyboard layouts to login.\n"
                      ))

            self.value = cryptPassword(pw)
            return None
        else:
            return Prompt(
                _("Enter a new value for '%(title)s' and press %(enter)s") % {
                    # TRANSLATORS: 'title' as a title of the entry
                    "title": entry.title,
                    # TRANSLATORS: 'enter' as the key ENTER
                    "enter": Prompt.ENTER
                })
예제 #20
0
    def test_add_options(self):
        p = Prompt()

        # add new option
        p.add_option("R", "refresh")
        self.assertTrue("R" in p.options)
        self.assertEqual(p.options["R"], "refresh")

        # add option over the existing option should trigger warning message
        with self.assertLogs("simpleline", level="WARNING"):
            p.add_option("R", "another refresh")

        # update existing option
        p.update_option("R", "new refresh option")
        self.assertEqual(p.options["R"], "new refresh option")

        # update non existing option should trigger warning
        with self.assertLogs("simpleline", level="WARNING"):
            p.update_option("N", "non existing option")

        p = Prompt()
        p.add_option("N", "new option")
        # remove option
        ret = p.remove_option("N")
        self.assertFalse("N" in p.options)
        self.assertEqual(ret, "new option")

        # remove non-existing option
        ret = p.remove_option("non-existing")
        self.assertIsNone(ret)
예제 #21
0
파일: rescue.py 프로젝트: rvykydal/anaconda
 def prompt(self, args=None):
     """ Override the default TUI prompt."""
     prompt = Prompt()
     prompt.add_continue_option()
     return prompt
예제 #22
0
 def prompt(self, args=None):
     return Prompt(
         _("Installation complete. Press %s to quit") % Prompt.ENTER)
예제 #23
0
 def prompt(self, args=None):
     """ Override the default TUI prompt."""
     prompt = Prompt()
     prompt.add_continue_option()
     return prompt
예제 #24
0
 def prompt(self, args=None):
     return Prompt(message=self._message)
예제 #25
0
 def prompt(self, args=None):
     return Prompt(_("Press %s to exit") % Prompt.ENTER)