From 62c6eb54233dd4d09c19b6190a50be754c9e1e4f Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Fri, 14 Aug 2026 14:25:14 +0300 Subject: utils: T9185: revert the proposed fix ask_yes_no() busy-looping forever on non-tty stdin --- src/tests/test_utils_io.py | 51 ---------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/tests/test_utils_io.py (limited to 'src') diff --git a/src/tests/test_utils_io.py b/src/tests/test_utils_io.py deleted file mode 100644 index 9d6471e16..000000000 --- a/src/tests/test_utils_io.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright VyOS maintainers and contributors -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 or later as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import unittest -from unittest.mock import patch - -from vyos.utils.io import ask_yes_no - - -class TestVyOSUtilsIO(unittest.TestCase): - def test_ask_yes_no_non_interactive_raises_without_reading_stdin(self): - # T9185: on a non-TTY stdin (e.g. a non-interactive vbash session), - # input() raises EOFError immediately and forever; looping on it - # spins a core at 100% CPU. Returning a silent default instead is - # also wrong (jestabro/dmbaturin, PR #5390): a caller that forgot - # to guard this with an explicit non-interactive option would get - # no error and no visible hang, just a quietly-succeeding prompt. - # ask_yes_no() must raise immediately instead of ever calling - # input() or returning a default. - with patch('sys.stdin') as mock_stdin: - mock_stdin.isatty.return_value = False - with patch('builtins.input') as mock_input: - self.assertRaises(EOFError, ask_yes_no, 'Proceed?', default=True) - self.assertRaises(EOFError, ask_yes_no, 'Proceed?', default=False) - mock_input.assert_not_called() - - def test_ask_yes_no_interactive_reads_input(self): - with patch('sys.stdin') as mock_stdin: - mock_stdin.isatty.return_value = True - with patch('builtins.input', return_value='y'): - self.assertTrue(ask_yes_no('Proceed?', default=False)) - with patch('builtins.input', return_value='n'): - self.assertFalse(ask_yes_no('Proceed?', default=True)) - with patch('builtins.input', return_value=''): - self.assertTrue(ask_yes_no('Proceed?', default=True)) - self.assertFalse(ask_yes_no('Proceed?', default=False)) - - -if __name__ == '__main__': - unittest.main() -- cgit v1.2.3