Skip to content

Commit c888613

Browse files
committed
Add tests for UIScreen wide disabling of concurrency check
Related: rhbz#2134889 (cherry picked from commit 741ae90)
1 parent 8727d4c commit c888613

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

tests/units/main/adv_widgets_test.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,100 @@
2323
from unittest.mock import patch
2424
from io import StringIO
2525

26+
from simpleline.render.screen import UIScreen
27+
from simpleline.input.input_handler import InputHandler
2628
from simpleline.render.adv_widgets import GetInputScreen, GetPasswordInputScreen
2729

2830
from .. import UtilityMixin
2931

3032

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

0 commit comments

Comments
 (0)