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