Test that multi-line commands work properly over remote connection.
(self)
| 1384 | self.assertEqual(process.returncode, 0) |
| 1385 | |
| 1386 | def test_multi_line_commands(self): |
| 1387 | """Test that multi-line commands work properly over remote connection.""" |
| 1388 | self._create_script() |
| 1389 | process, client_file = self._connect_and_get_client_file() |
| 1390 | |
| 1391 | with kill_on_error(process): |
| 1392 | # Skip initial messages until we get to the prompt |
| 1393 | self._read_until_prompt(client_file) |
| 1394 | |
| 1395 | # Send a multi-line command |
| 1396 | multi_line_commands = [ |
| 1397 | # Define a function |
| 1398 | "def test_func():\n return 42", |
| 1399 | |
| 1400 | # For loop |
| 1401 | "for i in range(3):\n print(i)", |
| 1402 | |
| 1403 | # If statement |
| 1404 | "if True:\n x = 42\nelse:\n x = 0", |
| 1405 | |
| 1406 | # Try/except |
| 1407 | "try:\n result = 10/2\n print(result)\nexcept ZeroDivisionError:\n print('Error')", |
| 1408 | |
| 1409 | # Class definition |
| 1410 | "class TestClass:\n def __init__(self):\n self.value = 100\n def get_value(self):\n return self.value" |
| 1411 | ] |
| 1412 | |
| 1413 | for cmd in multi_line_commands: |
| 1414 | self._send_command(client_file, cmd) |
| 1415 | self._read_until_prompt(client_file) |
| 1416 | |
| 1417 | # Test executing the defined function |
| 1418 | self._send_command(client_file, "test_func()") |
| 1419 | messages = self._read_until_prompt(client_file) |
| 1420 | |
| 1421 | # Find the result message |
| 1422 | result_msg = next(msg['message'] for msg in messages if 'message' in msg) |
| 1423 | self.assertIn("42", result_msg) |
| 1424 | |
| 1425 | # Test creating an instance of the defined class |
| 1426 | self._send_command(client_file, "obj = TestClass()") |
| 1427 | self._read_until_prompt(client_file) |
| 1428 | |
| 1429 | # Test calling a method on the instance |
| 1430 | self._send_command(client_file, "obj.get_value()") |
| 1431 | messages = self._read_until_prompt(client_file) |
| 1432 | |
| 1433 | # Find the result message |
| 1434 | result_msg = next(msg['message'] for msg in messages if 'message' in msg) |
| 1435 | self.assertIn("100", result_msg) |
| 1436 | |
| 1437 | # Continue execution to finish |
| 1438 | self._send_command(client_file, "c") |
| 1439 | |
| 1440 | stdout, stderr = process.communicate(timeout=SHORT_TIMEOUT) |
| 1441 | self.assertIn("Function returned: 42", stdout) |
| 1442 | self.assertEqual(process.returncode, 0) |
| 1443 |
nothing calls this directly
no test coverage detected