class_docstr: Dependency management API tests.
  - mock()
  - extern()
  - deny()
class_docstr_tok: ["Dependency","management","API","tests",".","-","mock","(",")","-","extern","(",")","-","deny","(",")"]
code: def test_extern(self):
      buffer = BytesIO()
      with PackageExporter(buffer) as he:
          he.extern(["package_a.subpackage", "module_a"])
          he.save_source_string(
              "foo", "import package_a.subpackage; import module_a"
          )
      buffer.seek(0)
      hi = PackageImporter(buffer)
      import module_a
      import package_a.subpackage
  
      module_a_im = hi.import_module("module_a")
      hi.import_module("package_a.subpackage")
      package_a_im = hi.import_module("package_a")
  
      self.assertIs(module_a, module_a_im)
      self.assertIsNot(package_a, package_a_im)
      self.assertIs(package_a.subpackage, package_a_im.subpackage)
  
imports: import importlib
  from io import BytesIO
  from sys import version_info
  from textwrap import dedent
  from unittest import skipIf
  import torch.nn
  from torch.package import EmptyMatchError, Importer, PackageExporter, PackageImporter
  from torch.package.package_exporter import PackagingError
  from torch.testing._internal.common_utils import IS_WINDOWS, run_tests
label_desc: Use image node_id 1 for calling the TestDependencyAPI obj's underlying member method code with example usage: obj.test_extern() without return types