@@ -1409,6 +1409,44 @@ def test_showrefcount(self):
14091409 self .assertEqual (len (matches ), 3 )
14101410
14111411
1412+ @force_not_colorized
1413+ def test_no_newline (self ):
1414+ env = os .environ .copy ()
1415+ env .pop ("PYTHON_BASIC_REPL" , "" )
1416+ env ["PYTHON_BASIC_REPL" ] = "1"
1417+
1418+ commands = "print('Something pretty long', end='')\n exit()\n "
1419+ expected_output_sequence = "Something pretty long>>> exit()"
1420+
1421+ basic_output , basic_exit_code = self .run_repl (commands , env = env )
1422+ self .assertEqual (basic_exit_code , 0 )
1423+ self .assertIn (expected_output_sequence , basic_output )
1424+
1425+ output , exit_code = self .run_repl (commands )
1426+ self .assertEqual (exit_code , 0 )
1427+
1428+ # Define escape sequences that don't affect cursor position or visual output
1429+ bracketed_paste_mode = r'\x1b\[\?2004[hl]' # Enable/disable bracketed paste
1430+ application_cursor_keys = r'\x1b\[\?1[hl]' # Enable/disable application cursor keys
1431+ application_keypad_mode = r'\x1b[=>]' # Enable/disable application keypad
1432+ insert_character = r'\x1b\[(?:1)?@(?=[ -~])' # Insert exactly 1 char (safe form)
1433+ cursor_visibility = r'\x1b\[\?25[hl]' # Show/hide cursor
1434+ cursor_blinking = r'\x1b\[\?12[hl]' # Start/stop cursor blinking
1435+ device_attributes = r'\x1b\[\?[01]c' # Device Attributes (DA) queries/responses
1436+
1437+ safe_escapes = re .compile (
1438+ f'{ bracketed_paste_mode } |'
1439+ f'{ application_cursor_keys } |'
1440+ f'{ application_keypad_mode } |'
1441+ f'{ insert_character } |'
1442+ f'{ cursor_visibility } |'
1443+ f'{ cursor_blinking } |'
1444+ f'{ device_attributes } '
1445+ )
1446+ cleaned_output = safe_escapes .sub ('' , output )
1447+ self .assertIn (expected_output_sequence , cleaned_output )
1448+
1449+
14121450class TestPyReplCtrlD (TestCase ):
14131451 """Test Ctrl+D behavior in _pyrepl to match old pre-3.13 REPL behavior.
14141452
0 commit comments