code: def test_str(doc):
      assert m.str_from_char_ssize_t().encode().decode() == "red"
      assert m.str_from_char_size_t().encode().decode() == "blue"
      assert m.str_from_string().encode().decode() == "baz"
      assert m.str_from_bytes().encode().decode() == "boo"
  
      assert doc(m.str_from_bytes) == "str_from_bytes() -> str"
  
      class A:
          def __str__(self):
              return "this is a str"
  
          def __repr__(self):
              return "this is a repr"
  
      assert m.str_from_object(A()) == "this is a str"
      assert m.repr_from_object(A()) == "this is a repr"
      assert m.str_from_handle(A()) == "this is a str"
  
      s1, s2 = m.str_format()
      assert s1 == "1 + 2 = 3"
      assert s1 == s2
  
      malformed_utf8 = b"\x80"
      if hasattr(m, "PYBIND11_STR_LEGACY_PERMISSIVE"):
          assert m.str_from_object(malformed_utf8) is malformed_utf8
      else:
          assert m.str_from_object(malformed_utf8) == "b'\\x80'"
      assert m.str_from_handle(malformed_utf8) == "b'\\x80'"
  
      assert (
          m.str_from_string_from_str("this is a str") == "this is a str"
      )
      ucs_surrogates_str = "\udcc3"
      with pytest.raises(UnicodeEncodeError):
          m.str_from_string_from_str(ucs_surrogates_str)
  
imports: import contextlib
  import sys
  import types
  import pytest
  import env
  from pybind11_tests import detailed_error_messages_enabled
  from pybind11_tests import pytypes
label_desc: Use image node_id 17 for calling a global function with example usage: test_str(doc) and returns: str, str