code: def test_instance(capture):
      with pytest.raises(TypeError) as excinfo:
          ExamplePythonTypes()
      assert (
          str(excinfo.value)
          == "pybind11_tests.ExamplePythonTypes: No constructor defined!"
      )
  
      instance = ExamplePythonTypes.new_instance()
  
      with capture:
          dict_result = instance.get_dict()
          dict_result["key2"] = "value2"
          instance.print_dict(dict_result)
      assert (
          capture.unordered
          == """
          key: key, value=value
          key: key2, value=value2
      """
      )
      with capture:
          dict_result = instance.get_dict_2()
          dict_result["key2"] = "value2"
          instance.print_dict_2(dict_result)
      assert (
          capture.unordered
          == """
          key: key, value=value
          key: key2, value=value2
      """
      )
      with capture:
          set_result = instance.get_set()
          set_result.add("key4")
          instance.print_set(set_result)
      assert (
          capture.unordered
          == """
          key: key1
          key: key2
          key: key3
          key: key4
      """
      )
      with capture:
          set_result = instance.get_set2()
          set_result.add("key3")
          instance.print_set_2(set_result)
      assert (
          capture.unordered
          == """
          key: key1
          key: key2
          key: key3
      """
      )
      with capture:
          list_result = instance.get_list()
          list_result.append("value2")
          instance.print_list(list_result)
      assert (
          capture.unordered
          == """
          Entry at position 0: value
          list item 0: overwritten
          list item 1: value2
      """
      )
      with capture:
          list_result = instance.get_list_2()
          list_result.append("value2")
          instance.print_list_2(list_result)
      assert (
          capture.unordered
          == """
          list item 0: value
          list item 1: value2
      """
      )
      with capture:
          list_result = instance.get_list_2()
          list_result.append("value2")
          instance.print_list_2(tuple(list_result))
      assert (
          capture.unordered
          == """
          list item 0: value
          list item 1: value2
      """
      )
      array_result = instance.get_array()
      assert array_result == ["array entry 1", "array entry 2"]
      with capture:
          instance.print_array(array_result)
      assert (
          capture.unordered
          == """
          array item 0: array entry 1
          array item 1: array entry 2
      """
      )
      varray_result = instance.get_valarray()
      assert varray_result == [1, 4, 9]
      with capture:
          instance.print_valarray(varray_result)
      assert (
          capture.unordered
          == """
          valarray item 0: 1
          valarray item 1: 4
          valarray item 2: 9
      """
      )
      with pytest.raises(RuntimeError) as excinfo:
          instance.throw_exception()
      assert (
          str(excinfo.value)
          == "This exception was intentionally thrown."
      )
  
      assert instance.pair_passthrough((True, "test")) == ("test", True)
      assert instance.tuple_passthrough((True, "test", 5)) == (
          5,
          "test",
          True,
      )
      # Any sequence can be cast to a std::pair or std::tuple
      assert instance.pair_passthrough([True, "test"]) == ("test", True)
      assert instance.tuple_passthrough([True, "test", 5]) == (
          5,
          "test",
          True,
      )
  
      assert instance.get_bytes_from_string().decode() == "foo"
      assert instance.get_bytes_from_str().decode() == "bar"
      assert instance.get_str_from_string().encode().decode() == "baz"
      assert instance.get_str_from_bytes().encode().decode() == "boo"
  
      class A(object):
          def __str__(self):
              return "this is a str"
  
          def __repr__(self):
              return "this is a repr"
  
      with capture:
          instance.test_print(A())
      assert (
          capture
          == """
          this is a str
          this is a repr
      """
      )
  
      cstats = ConstructorStats.get(ExamplePythonTypes)
      assert cstats.alive() == 1
      del instance
      assert cstats.alive() == 0
  
file_path: coremltools/deps/pybind11/tests/test_python_types.py
imports: import pytest
  from pybind11_tests import ExamplePythonTypes, ConstructorStats, has_optional, has_exp_optional
label_desc: Use image node_id 3 for calling a global function with example usage: test_instance(capture) and returns: str, str