code: def test_to_str():
      assert strings.to_str("str") == "str" if six.PY2 else b"str"
      assert (
          strings.to_str("unicode") == "unicode"
          if six.PY2
          else b"unicode"
      )
      assert strings.to_str("юникод") == "юникод".encode("utf-8")
      assert strings.to_str("юникод", "cp1251") == "юникод".encode(
          "cp1251"
      )
      if six.PY2:
          assert strings.to_str(Convertible()) == Convertible.text_utf8
          with pytest.raises(UnicodeEncodeError):
              strings.to_str(ConvertibleToUnicodeOnly())
          assert (
              strings.to_str(ConvertibleToStrOnly())
              == Convertible.text_utf8
          )
          with pytest.raises(UnicodeEncodeError):
              strings.to_str(NonConvertible())
  
imports: import pytest
  import six
  from library.python import strings
label_desc: Use image node_id 4 for calling a global function with example usage: test_to_str() without return types