class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test a case where the script class defined in the package is
  different than the one defined in the loading environment, to make
  sure TorchScript can distinguish between the two.
docstr_tok: ["Test","a","case","where","the","script","class","defined","in","the","package","is","different","than","the","one","defined","in","the","loading","environment",",","to","make","sure","TorchScript","can","distinguish","between","the","two","."]
code: def test_different_package_script_class(self):
      """Test a case where the script class defined in the package is
      different than the one defined in the loading environment, to make
      sure TorchScript can distinguish between the two.
      """
      import package_a.fake_script_class as fake
  
      # Simulate a package that contains a different version of the
      # script class ,with the attribute `bar` instead of `foo`
      buffer = BytesIO()
      with PackageExporter(buffer) as pe2:
          pe2.save_source_string(
              fake.__name__,
              dedent(
                  """\
                      import torch
  
                      @torch.jit.script
                      class MyScriptClass:
                          def __init__(self, x):
                              self.bar = x
                      """
              ),
          )
      buffer.seek(0)
  
      package_importer = PackageImporter(buffer)
      diff_fake = package_importer.import_module(fake.__name__)
      input = torch.rand(2, 3)
      loaded_script_class = diff_fake.MyScriptClass(input)
      orig_script_class = fake.MyScriptClass(input)
      self.assertEqual(loaded_script_class.bar, orig_script_class.foo)
  
imports: from io import BytesIO
  from textwrap import dedent
  from unittest import skipIf
  import torch
  from torch.package import PackageExporter, PackageImporter
  from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE, run_tests
label_desc: Use image node_id 5 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_different_package_script_class() without return types