Skip to content

Commit 9965045

Browse files
committed
Add tests for UIScreen wide disabling of concurrency check
Related: rhbz#2134888 (cherry picked from commit 741ae90)
1 parent 53748cc commit 9965045

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

tests/simpleline_tests/adv_widgets_test.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,98 @@
2323
from io import StringIO
2424

2525
from . import UtilityMixin
26-
26+
from simpleline.render.screen import UIScreen
27+
from simpleline.input.input_handler import InputHandler
2728
from simpleline.render.adv_widgets import GetInputScreen, GetPasswordInputScreen
2829

2930

31+
class InputHandlerMock(InputHandler):
32+
"""Dummy InputHandler instance.
33+
34+
This class based on InputHandler has all threading logic disabled for simpler testing.
35+
"""
36+
def _register_input_ready_signal(self):
37+
pass
38+
39+
def get_input(self, prompt):
40+
pass
41+
42+
def wait_on_input(self):
43+
pass
44+
45+
46+
class UIScreen_TestCase(unittest.TestCase):
47+
@patch('simpleline.render.screen.input_manager.InputHandler')
48+
def test_uiscreen_disable_concurrency_check(self, input_handler_class_mock):
49+
# Replace default InputHandler instance created by InputManager by our mock to have
50+
# it stored after use.
51+
input_handler_instance_mock = InputHandlerMock()
52+
input_handler_class_mock.return_value = input_handler_instance_mock
53+
54+
screen = UIScreen()
55+
input_manager = screen.input_manager
56+
input_manager.skip_concurrency_check = True
57+
screen.get_user_input("test")
58+
59+
self.assertTrue(screen.input_manager.skip_concurrency_check)
60+
# Check that the created InputHandler instance has the flag correctly set.
61+
# We don't need to check the concurrency check functionality, it is tested
62+
# elsewhere already.
63+
self.assertTrue(input_handler_instance_mock.skip_concurrency_check)
64+
65+
@patch('simpleline.render.screen.input_manager.InputHandler')
66+
def test_uiscreen_password_disable_concurrency_check(self, input_handler_class_mock):
67+
# Replace default InputHandler instance created by InputManager by our mock to have
68+
# it stored after use.
69+
input_handler_instance_mock = InputHandlerMock()
70+
input_handler_class_mock.return_value = input_handler_instance_mock
71+
72+
screen = GetPasswordInputScreen(message="Test prompt")
73+
input_manager = screen.input_manager
74+
input_manager.skip_concurrency_check = True
75+
screen.get_user_input("test")
76+
77+
self.assertTrue(screen.input_manager.skip_concurrency_check)
78+
# Check that the created InputHandler instance has the flag correctly set.
79+
# We don't need to check the concurrency check functionality, it is tested
80+
# elsewhere already.
81+
self.assertTrue(input_handler_instance_mock.skip_concurrency_check)
82+
83+
@patch('simpleline.render.screen.input_manager.InputHandler')
84+
def test_uiscreen_non_blocking_input_disable_concurrency_check(self, input_handler_class_mock):
85+
# Replace default InputHandler instance created by InputManager by our mock to have
86+
# it stored after use.
87+
input_handler_instance_mock = InputHandlerMock()
88+
input_handler_class_mock.return_value = input_handler_instance_mock
89+
90+
screen = UIScreen()
91+
input_manager = screen.input_manager
92+
input_manager.skip_concurrency_check = True
93+
screen.get_input_with_error_check("test")
94+
95+
self.assertTrue(screen.input_manager.skip_concurrency_check)
96+
# Check that the created InputHandler instance has the flag correctly set.
97+
# We don't need to check the concurrency check functionality, it is tested
98+
# elsewhere already.
99+
self.assertTrue(input_handler_instance_mock.skip_concurrency_check)
100+
101+
@patch('simpleline.render.screen.input_manager.InputHandler')
102+
def test_uiscreen_default_concurrency_check(self, input_handler_class_mock):
103+
# Replace default InputHandler instance created by InputManager by our mock to have
104+
# it stored after use.
105+
input_handler_instance_mock = InputHandlerMock()
106+
input_handler_class_mock.return_value = input_handler_instance_mock
107+
108+
screen = UIScreen()
109+
screen.get_user_input("test")
110+
111+
self.assertFalse(screen.input_manager.skip_concurrency_check)
112+
# Check that the created InputHandler instance has the flag correctly set.
113+
# We don't need to check the concurrency check functionality, it is tested
114+
# elsewhere already.
115+
self.assertFalse(input_handler_instance_mock.skip_concurrency_check)
116+
117+
30118
@patch('simpleline.input.input_handler.InputHandlerRequest._get_input')
31119
@patch('sys.stdout', new_callable=StringIO)
32120
class AdvWidgets_TestCase(unittest.TestCase, UtilityMixin):

0 commit comments

Comments
 (0)