class_docstr: Dependency management API tests.
  - mock()
  - extern()
  - deny()
class_docstr_tok: ["Dependency","management","API","tests",".","-","mock","(",")","-","extern","(",")","-","deny","(",")"]
docstr: An incorrectly-formed import should raise a PackagingError.
docstr_tok: ["An","incorrectly-formed","import","should","raise","a","PackagingError","."]
code: def test_invalid_import(self):
      """An incorrectly-formed import should raise a PackagingError."""
      buffer = BytesIO()
      with self.assertRaises(PackagingError) as e:
          with PackageExporter(buffer) as exporter:
              # This import will fail to load.
              exporter.save_source_string(
                  "foo", "from ........ import lol"
              )
  
      self.assertEqual(
          str(e.exception),
          dedent(
              """
                  * Dependency resolution failed.
                      foo
                        Context: attempted relative import beyond top-level package
  
                  Set debug=True when invoking PackageExporter for a visualization of where broken modules are coming from!
                  """
          ),
      )
  
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 15 for calling the TestDependencyAPI obj's underlying member method code with example usage: obj.test_invalid_import() without return types