code: def _test_sys_writestream(self, funname, streamname):
      import_helper.import_module("ctypes")
      from ctypes import pythonapi, c_char_p
  
      func = getattr(pythonapi, funname)
      func.argtypes = (c_char_p,)
  
      # Supports plain C types.
      with support.captured_output(streamname) as stream:
          func(b"Hello, %s!", c_char_p(b"world"))
      self.assertEqual(stream.getvalue(), "Hello, world!")
  
      # There is a limit on the total length.
      with support.captured_output(streamname) as stream:
          func(b"Hello, %s!", c_char_p(b"world" * 100))
      self.assertEqual(
          stream.getvalue(), "Hello, " + "world" * 100 + "!"
      )
      with support.captured_output(streamname) as stream:
          func(b"Hello, %s!", c_char_p(b"world" * 200))
      out = stream.getvalue()
      self.assertEqual(out[:20], "Hello, worldworldwor")
      self.assertEqual(out[-13:], "... truncated")
      self.assertGreater(len(out), 1000)
  
file_path: cpython/Lib/test/test_capi/test_sys.py
imports: import unittest
  import contextlib
  import sys
  from test import support
  from test.support import import_helper
label_desc: Use image node_id 7 for calling the CAPITest obj's underlying member method code with example usage: obj._test_sys_writestream(funname, streamname) without return types