Test the command loop with various commands.
(self)
| 974 | self.assertFalse(self.pdb.quitting) |
| 975 | |
| 976 | def test_cmdloop(self): |
| 977 | """Test the command loop with various commands.""" |
| 978 | # Mock onecmd to track command execution |
| 979 | with unittest.mock.patch.object(self.pdb, 'onecmd', return_value=False) as mock_onecmd: |
| 980 | # Add commands to the queue |
| 981 | self.pdb.cmdqueue = ['help', 'list'] |
| 982 | |
| 983 | # Add a command from the socket for when cmdqueue is empty |
| 984 | self.sockfile.add_input({"reply": "next"}) |
| 985 | |
| 986 | # Add a second command to break the loop |
| 987 | self.sockfile.add_input({"reply": "quit"}) |
| 988 | |
| 989 | # Configure onecmd to exit the loop on "quit" |
| 990 | def side_effect(line): |
| 991 | return line == 'quit' |
| 992 | mock_onecmd.side_effect = side_effect |
| 993 | |
| 994 | # Run the command loop |
| 995 | self.pdb.quitting = False # Set this by hand because we don't want to really call set_trace() |
| 996 | self.pdb.cmdloop() |
| 997 | |
| 998 | # Should have processed 4 commands: 2 from cmdqueue, 2 from socket |
| 999 | self.assertEqual(mock_onecmd.call_count, 4) |
| 1000 | mock_onecmd.assert_any_call('help') |
| 1001 | mock_onecmd.assert_any_call('list') |
| 1002 | mock_onecmd.assert_any_call('next') |
| 1003 | mock_onecmd.assert_any_call('quit') |
| 1004 | |
| 1005 | # Check if prompt was sent to client |
| 1006 | outputs = self.sockfile.get_output() |
| 1007 | prompts = [o for o in outputs if 'prompt' in o] |
| 1008 | self.assertEqual(len(prompts), 2) # Should have sent 2 prompts |
| 1009 | |
| 1010 | |
| 1011 | @requires_subprocess() |
nothing calls this directly
no test coverage detected