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())
    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)
    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')
Beispiel #4
0
 def _get_meh_input_func(self, text_prompt):
     handler = InputHandler(source=self.meh_interface)
     handler.skip_concurrency_check = True
     handler.get_input(text_prompt)
     handler.wait_on_input()
     return handler.value
Beispiel #5
0
 def _get_meh_input_func(self, text_prompt):
     handler = InputHandler(source=self.meh_interface)
     handler.skip_concurrency_check = True
     handler.get_input(text_prompt)
     handler.wait_on_input()
     return handler.value
    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)