MCPcopy Index your code
hub / github.com/python/cpython / test_protocol_version

Method test_protocol_version

Lib/test/test_remote_pdb.py:1295–1345  ·  view source on GitHub ↗

Test that incompatible protocol versions are properly detected.

(self)

Source from the content-addressed store, hash-verified

1293 self.assertEqual(stderr, "")
1294
1295 def test_protocol_version(self):
1296 """Test that incompatible protocol versions are properly detected."""
1297 # Create a script using an incompatible protocol version
1298 script = textwrap.dedent(f'''
1299 import sys
1300 import pdb
1301
1302 def run_test():
1303 frame = sys._getframe()
1304
1305 # Use a fake version number that's definitely incompatible
1306 fake_version = 0x01010101 # A fake version that doesn't match any real Python version
1307
1308 # Connect with the wrong version
1309 pdb._connect(
1310 host='127.0.0.1',
1311 port={self.port},
1312 frame=frame,
1313 commands="",
1314 version=fake_version,
1315 signal_raising_thread=False,
1316 colorize=False,
1317 )
1318
1319 # This should print if the debugger detaches correctly
1320 print("Debugger properly detected version mismatch")
1321 return True
1322
1323 if __name__ == "__main__":
1324 print("Test result:", run_test())
1325 ''')
1326 self._create_script(script=script)
1327 process, client_file = self._connect_and_get_client_file()
1328
1329 with kill_on_error(process):
1330 # First message should be an error about protocol version mismatch
1331 data = client_file.readline()
1332 message = json.loads(data.decode())
1333
1334 self.assertIn('message', message)
1335 self.assertEqual(message['type'], 'error')
1336 self.assertIn('incompatible', message['message'])
1337 self.assertIn('protocol version', message['message'])
1338
1339 # The process should complete normally
1340 stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT)
1341
1342 # Verify the process completed successfully
1343 self.assertIn("Test result: True", stdout)
1344 self.assertIn("Debugger properly detected version mismatch", stdout)
1345 self.assertEqual(process.returncode, 0)
1346
1347 def test_help_system(self):
1348 """Test that the help system properly sends help text to the client."""

Callers

nothing calls this directly

Calls 10

_create_scriptMethod · 0.95
assertInMethod · 0.80
kill_on_errorFunction · 0.70
dedentMethod · 0.45
readlineMethod · 0.45
loadsMethod · 0.45
decodeMethod · 0.45
assertEqualMethod · 0.45
communicateMethod · 0.45

Tested by

no test coverage detected