Ejemplo n.º 1
0
    def test_list_bindings(self):
        prompt = ListPrompt(
            message="Select a fruit",
            choices=self.choices,
            default="watermelon",
            style=InquirerPyStyle({"pointer": "#61afef"}),
            vi_mode=True,
            qmark="[?]",
            pointer=">",
            instruction="(j/k)",
        )
        self.assertEqual(prompt.content_control.selected_choice_index, 2)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 0)
        prompt._handle_up(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 2)
        prompt._handle_up(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 2)

        self.assertEqual(prompt.status, {
            "result": None,
            "answered": False,
            "skipped": False
        })
        with patch("prompt_toolkit.utils.Event") as mock:
            event = mock.return_value
            prompt._handle_enter(event)
        self.assertEqual(prompt.status, {
            "result": "melon",
            "answered": True,
            "skipped": False
        })
Ejemplo n.º 2
0
 def test_handle_down(self) -> None:
     prompt = ListPrompt(
         message="Select one:",
         choices=[1, 2, 3, Separator()],
     )
     self.assertEqual(prompt.content_control.selected_choice_index, 0)
     prompt._handle_down(None)
     self.assertEqual(prompt.content_control.selected_choice_index, 1)
     prompt._handle_down(None)
     prompt._handle_down(None)
     self.assertEqual(prompt.content_control.selected_choice_index, 0)
Ejemplo n.º 3
0
    def test_separator_movement(self):
        prompt = ListPrompt(message="..", choices=[Separator("hello"), "yes"])
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_up(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 1)

        prompt = ListPrompt(
            message="..",
            choices=[Separator("hello"), "yes",
                     Separator(), "no"])
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 3)
        prompt._handle_up(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_up(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 3)
Ejemplo n.º 4
0
    def test_handle_down_no_cycle(self):
        prompt = ListPrompt(
            message="Select one:",
            choices=[Separator(), 1, 2, 3, Separator()],
            cycle=False,
        )
        self.assertEqual(prompt.content_control.selected_choice_index, 1)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 2)
        prompt._handle_down(None)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 3)

        prompt = ListPrompt(
            message="Select one:",
            choices=[1, 2, 3, Separator()],
            cycle=False,
        )
        self.assertEqual(prompt.content_control.selected_choice_index, 0)
        prompt._handle_down(None)
        prompt._handle_down(None)
        prompt._handle_down(None)
        prompt._handle_down(None)
        self.assertEqual(prompt.content_control.selected_choice_index, 2)