Support universal_newlines and use _translate_newlines in run_pipeline

- Factor out _translate_newlines() as a module-level function, have
  Popen's method delegate to it for code sharing
- Remove rejection of universal_newlines kwarg in run_pipeline(), treat
  it the same as text=True (consistent with Popen behavior)
- Use _translate_newlines() for text mode decoding in run_pipeline()
  to properly handle \r\n and \r newline sequences
- Update documentation to remove mention of universal_newlines rejection
- Update test to verify universal_newlines=True works like text=True

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Gregory P. Smith using claude.ai/code 2025-11-29 09:27:29 +00:00
parent 978cd76cd8
commit 15f8a93bcb
No known key found for this signature in database
3 changed files with 23 additions and 29 deletions

View file

@ -2123,16 +2123,16 @@ def test_pipeline_capture_output_conflict(self):
)
self.assertIn('capture_output', str(cm.exception))
def test_pipeline_rejects_universal_newlines(self):
"""Test that universal_newlines is not supported"""
with self.assertRaises(TypeError) as cm:
subprocess.run_pipeline(
[sys.executable, '-c', 'pass'],
[sys.executable, '-c', 'pass'],
universal_newlines=True
)
self.assertIn('universal_newlines', str(cm.exception))
self.assertIn('text=True', str(cm.exception))
def test_pipeline_universal_newlines(self):
"""Test that universal_newlines=True works like text=True"""
result = subprocess.run_pipeline(
[sys.executable, '-c', 'print("hello")'],
[sys.executable, '-c', 'import sys; print(sys.stdin.read().upper())'],
capture_output=True, universal_newlines=True
)
self.assertIsInstance(result.stdout, str)
self.assertIn('HELLO', result.stdout)
self.assertEqual(result.returncodes, [0, 0])
def test_pipeline_result_repr(self):
"""Test PipelineResult string representation"""