@@ -1836,6 +1836,44 @@ def test_showrefcount(self):
18361836 self .assertEqual (len (matches ), 3 )
18371837
18381838
1839+ @force_not_colorized
1840+ def test_no_newline (self ):
1841+ env = os .environ .copy ()
1842+ env .pop ("PYTHON_BASIC_REPL" , "" )
1843+ env ["PYTHON_BASIC_REPL" ] = "1"
1844+
1845+ commands = "print('Something pretty long', end='')\n exit()\n "
1846+ expected_output_sequence = "Something pretty long>>> exit()"
1847+
1848+ basic_output , basic_exit_code = self .run_repl (commands , env = env )
1849+ self .assertEqual (basic_exit_code , 0 )
1850+ self .assertIn (expected_output_sequence , basic_output )
1851+
1852+ output , exit_code = self .run_repl (commands )
1853+ self .assertEqual (exit_code , 0 )
1854+
1855+ # Define escape sequences that don't affect cursor position or visual output
1856+ bracketed_paste_mode = r'\x1b\[\?2004[hl]' # Enable/disable bracketed paste
1857+ application_cursor_keys = r'\x1b\[\?1[hl]' # Enable/disable application cursor keys
1858+ application_keypad_mode = r'\x1b[=>]' # Enable/disable application keypad
1859+ insert_character = r'\x1b\[(?:1)?@(?=[ -~])' # Insert exactly 1 char (safe form)
1860+ cursor_visibility = r'\x1b\[\?25[hl]' # Show/hide cursor
1861+ cursor_blinking = r'\x1b\[\?12[hl]' # Start/stop cursor blinking
1862+ device_attributes = r'\x1b\[\?[01]c' # Device Attributes (DA) queries/responses
1863+
1864+ safe_escapes = re .compile (
1865+ f'{ bracketed_paste_mode } |'
1866+ f'{ application_cursor_keys } |'
1867+ f'{ application_keypad_mode } |'
1868+ f'{ insert_character } |'
1869+ f'{ cursor_visibility } |'
1870+ f'{ cursor_blinking } |'
1871+ f'{ device_attributes } '
1872+ )
1873+ cleaned_output = safe_escapes .sub ('' , output )
1874+ self .assertIn (expected_output_sequence , cleaned_output )
1875+
1876+
18391877class TestPyReplCtrlD (TestCase ):
18401878 """Test Ctrl+D behavior in _pyrepl to match old pre-3.13 REPL behavior.
18411879
0 commit comments