@@ -19,161 +19,161 @@ def setUp(self):
1919 if sys .platform == "win32" :
2020 self .skipTest ("Unix-specific tests" )
2121 self .send_callback = Mock ()
22-
23- @patch (' sys.stdin' )
24- @patch (' select.select' )
25- @patch (' termios.tcgetattr' )
22+
23+ @patch (" sys.stdin" )
24+ @patch (" select.select" )
25+ @patch (" termios.tcgetattr" )
2626 def test_arrow_up_key (self , mock_tcgetattr , mock_select , mock_stdin ):
2727 """Test arrow up key sends complete escape sequence."""
2828 # Mock termios
2929 mock_tcgetattr .return_value = []
30-
30+
3131 # Create handler
3232 handler = UnixInputHandler (self .send_callback )
33-
33+
3434 # Simulate arrow up key: ESC [ A
35- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , 'A' ])
35+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "A" ])
3636 # select returns True for first two calls (more data available)
3737 mock_select .side_effect = [[True ], [True ], [False ]]
38-
38+
3939 result = handler .read_input ()
40-
40+
4141 # Should return complete escape sequence
42- self .assertEqual (result , ' \x1b [A' )
43-
44- @patch (' sys.stdin' )
45- @patch (' select.select' )
46- @patch (' termios.tcgetattr' )
42+ self .assertEqual (result , " \x1b [A" )
43+
44+ @patch (" sys.stdin" )
45+ @patch (" select.select" )
46+ @patch (" termios.tcgetattr" )
4747 def test_arrow_down_key (self , mock_tcgetattr , mock_select , mock_stdin ):
4848 """Test arrow down key sends complete escape sequence."""
4949 mock_tcgetattr .return_value = []
5050 handler = UnixInputHandler (self .send_callback )
51-
51+
5252 # Simulate arrow down key: ESC [ B
53- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , 'B' ])
53+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "B" ])
5454 mock_select .side_effect = [[True ], [True ], [False ]]
55-
55+
5656 result = handler .read_input ()
57- self .assertEqual (result , ' \x1b [B' )
58-
59- @patch (' sys.stdin' )
60- @patch (' select.select' )
61- @patch (' termios.tcgetattr' )
57+ self .assertEqual (result , " \x1b [B" )
58+
59+ @patch (" sys.stdin" )
60+ @patch (" select.select" )
61+ @patch (" termios.tcgetattr" )
6262 def test_arrow_right_key (self , mock_tcgetattr , mock_select , mock_stdin ):
6363 """Test arrow right key sends complete escape sequence."""
6464 mock_tcgetattr .return_value = []
6565 handler = UnixInputHandler (self .send_callback )
66-
66+
6767 # Simulate arrow right key: ESC [ C
68- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , 'C' ])
68+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "C" ])
6969 mock_select .side_effect = [[True ], [True ], [False ]]
70-
70+
7171 result = handler .read_input ()
72- self .assertEqual (result , ' \x1b [C' )
73-
74- @patch (' sys.stdin' )
75- @patch (' select.select' )
76- @patch (' termios.tcgetattr' )
72+ self .assertEqual (result , " \x1b [C" )
73+
74+ @patch (" sys.stdin" )
75+ @patch (" select.select" )
76+ @patch (" termios.tcgetattr" )
7777 def test_arrow_left_key (self , mock_tcgetattr , mock_select , mock_stdin ):
7878 """Test arrow left key sends complete escape sequence."""
7979 mock_tcgetattr .return_value = []
8080 handler = UnixInputHandler (self .send_callback )
81-
81+
8282 # Simulate arrow left key: ESC [ D
83- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , 'D' ])
83+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "D" ])
8484 mock_select .side_effect = [[True ], [True ], [False ]]
85-
85+
8686 result = handler .read_input ()
87- self .assertEqual (result , ' \x1b [D' )
88-
89- @patch (' sys.stdin' )
90- @patch (' select.select' )
91- @patch (' termios.tcgetattr' )
87+ self .assertEqual (result , " \x1b [D" )
88+
89+ @patch (" sys.stdin" )
90+ @patch (" select.select" )
91+ @patch (" termios.tcgetattr" )
9292 def test_escape_key_alone (self , mock_tcgetattr , mock_select , mock_stdin ):
9393 """Test ESC key alone (no following sequence)."""
9494 mock_tcgetattr .return_value = []
9595 handler = UnixInputHandler (self .send_callback )
96-
96+
9797 # Simulate ESC key alone - no more data after timeout
98- mock_stdin .read = Mock (return_value = ' \x1b ' )
98+ mock_stdin .read = Mock (return_value = " \x1b " )
9999 mock_select .return_value = ([], [], []) # No more data available
100-
100+
101101 result = handler .read_input ()
102- self .assertEqual (result , ' \x1b ' )
103-
104- @patch (' sys.stdin' )
105- @patch (' select.select' )
106- @patch (' termios.tcgetattr' )
102+ self .assertEqual (result , " \x1b " )
103+
104+ @patch (" sys.stdin" )
105+ @patch (" select.select" )
106+ @patch (" termios.tcgetattr" )
107107 def test_function_key_f1 (self , mock_tcgetattr , mock_select , mock_stdin ):
108108 """Test F1 key sends complete escape sequence."""
109109 mock_tcgetattr .return_value = []
110110 handler = UnixInputHandler (self .send_callback )
111-
111+
112112 # Simulate F1 key: ESC O P
113- mock_stdin .read = Mock (side_effect = [' \x1b ' , 'O' , 'P' ])
113+ mock_stdin .read = Mock (side_effect = [" \x1b " , "O" , "P" ])
114114 mock_select .side_effect = [[True ], [True ]]
115-
115+
116116 result = handler .read_input ()
117- self .assertEqual (result , ' \x1b OP' )
118-
119- @patch (' sys.stdin' )
120- @patch (' select.select' )
121- @patch (' termios.tcgetattr' )
117+ self .assertEqual (result , " \x1b OP" )
118+
119+ @patch (" sys.stdin" )
120+ @patch (" select.select" )
121+ @patch (" termios.tcgetattr" )
122122 def test_device_control_sequence_filtered (self , mock_tcgetattr , mock_select , mock_stdin ):
123123 """Test device control sequences are filtered out."""
124124 mock_tcgetattr .return_value = []
125125 handler = UnixInputHandler (self .send_callback )
126-
126+
127127 # Simulate cursor position report: ESC [ 1 ; 1 R
128- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , '1' , ';' , '1' , 'R' ])
128+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "1" , ";" , "1" , "R" ])
129129 mock_select .side_effect = [[True ], [True ], [True ], [True ], [True ], [False ]]
130-
130+
131131 result = handler .read_input ()
132132 # Should be filtered out (return None)
133133 self .assertIsNone (result )
134-
135- @patch (' sys.stdin' )
136- @patch (' select.select' )
137- @patch (' termios.tcgetattr' )
134+
135+ @patch (" sys.stdin" )
136+ @patch (" select.select" )
137+ @patch (" termios.tcgetattr" )
138138 def test_regular_character (self , mock_tcgetattr , mock_select , mock_stdin ):
139139 """Test regular character is passed through."""
140140 mock_tcgetattr .return_value = []
141141 handler = UnixInputHandler (self .send_callback )
142-
143- mock_stdin .read = Mock (return_value = 'a' )
144-
142+
143+ mock_stdin .read = Mock (return_value = "a" )
144+
145145 result = handler .read_input ()
146- self .assertEqual (result , 'a' )
147-
148- @patch (' sys.stdin' )
149- @patch (' select.select' )
150- @patch (' termios.tcgetattr' )
146+ self .assertEqual (result , "a" )
147+
148+ @patch (" sys.stdin" )
149+ @patch (" select.select" )
150+ @patch (" termios.tcgetattr" )
151151 def test_page_up_key (self , mock_tcgetattr , mock_select , mock_stdin ):
152152 """Test Page Up key sends complete escape sequence."""
153153 mock_tcgetattr .return_value = []
154154 handler = UnixInputHandler (self .send_callback )
155-
155+
156156 # Simulate Page Up key: ESC [ 5 ~
157- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , '5' , '~' ])
157+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "5" , "~" ])
158158 mock_select .side_effect = [[True ], [True ], [True ], [False ]]
159-
159+
160160 result = handler .read_input ()
161- self .assertEqual (result , ' \x1b [5~' )
162-
163- @patch (' sys.stdin' )
164- @patch (' select.select' )
165- @patch (' termios.tcgetattr' )
161+ self .assertEqual (result , " \x1b [5~" )
162+
163+ @patch (" sys.stdin" )
164+ @patch (" select.select" )
165+ @patch (" termios.tcgetattr" )
166166 def test_home_key (self , mock_tcgetattr , mock_select , mock_stdin ):
167167 """Test Home key sends complete escape sequence."""
168168 mock_tcgetattr .return_value = []
169169 handler = UnixInputHandler (self .send_callback )
170-
170+
171171 # Simulate Home key: ESC [ H
172- mock_stdin .read = Mock (side_effect = [' \x1b ' , '[' , 'H' ])
172+ mock_stdin .read = Mock (side_effect = [" \x1b " , "[" , "H" ])
173173 mock_select .side_effect = [[True ], [True ], [False ]]
174-
174+
175175 result = handler .read_input ()
176- self .assertEqual (result , ' \x1b [H' )
176+ self .assertEqual (result , " \x1b [H" )
177177
178178
179179if __name__ == "__main__" :
0 commit comments