class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test to verify when saving multiple packages with same CU
  that packages don't include unnecessary torchscript code files.
  The TorchVision code should only be saved in the package that
  relies on it.
docstr_tok: ["Test","to","verify","when","saving","multiple","packages","with","same","CU","that","packages","do","n't","include","unnecessary","torchscript","code","files",".","The","TorchVision","code","should","only","be","saved","in","the","package","that","relies","on","it","."]
code: def test_save_scriptmodule_only_necessary_code(self):
      """
      Test to verify when saving multiple packages with same CU
      that packages don't include unnecessary torchscript code files.
      The TorchVision code should only be saved in the package that
      relies on it.
      """
      from package_a.test_module import ModWithTensor
  
      class ModWithTorchVision(torch.nn.Module):
          def __init__(self, name: str):
              super().__init__()
              self.tvmod = resnet18()
  
          def forward(self, input):
              return input * 4
  
      scripted_mod_0 = torch.jit.script(ModWithTorchVision("foo"))
      scripted_mod_1 = torch.jit.script(
          ModWithTensor(torch.rand(1, 2, 3))
      )
  
      buffer_0 = BytesIO()
      with PackageExporter(buffer_0) as e:
          e.save_pickle("res", "mod1.pkl", scripted_mod_0)
  
      buffer_0.seek(0)
      importer_0 = importer = PackageImporter(buffer_0)
  
      buffer_1 = BytesIO()
      with PackageExporter(buffer_1) as e:
          e.save_pickle("res", "mod1.pkl", scripted_mod_1)
  
      buffer_1.seek(0)
      importer_1 = PackageImporter(buffer_1)
  
      self.assertTrue("torchvision" in str(importer_0.file_structure()))
      self.assertFalse(
          "torchvision" in str(importer_1.file_structure())
      )
  
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 13 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_save_scriptmodule_only_necessary_code() and returns: unknown