class_docstr: Tests for one-off or random functionality. Try not to add to this!
class_docstr_tok: ["Tests","for","one-off","or","random","functionality",".","Try","not","to","add","to","this","!"]
docstr: Should be able to retrieve source for a packaged class.
docstr_tok: ["Should","be","able","to","retrieve","source","for","a","packaged","class","."]
code: def test_inspect_class(self):
      """Should be able to retrieve source for a packaged class."""
      import package_a.subpackage
  
      buffer = BytesIO()
      obj = package_a.subpackage.PackageASubpackageObject()
  
      with PackageExporter(buffer) as pe:
          pe.intern("**")
          pe.save_pickle("obj", "obj.pkl", obj)
  
      buffer.seek(0)
      pi = PackageImporter(buffer)
      packaged_class = pi.import_module(
          "package_a.subpackage"
      ).PackageASubpackageObject
      regular_class = package_a.subpackage.PackageASubpackageObject
  
      packaged_src = inspect.getsourcelines(packaged_class)
      regular_src = inspect.getsourcelines(regular_class)
      self.assertEqual(packaged_src, regular_src)
  
imports: import inspect
  import os
  import platform
  import sys
  from io import BytesIO
  from pathlib import Path
  from textwrap import dedent
  from unittest import skipIf
  from torch.package import is_from_package, PackageExporter, PackageImporter
  from torch.package.package_exporter import PackagingError
  from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE, run_tests, skipIfTorchDynamo
label_desc: Use image node_id 8 for calling the TestMisc obj's underlying member method code with example usage: obj.test_inspect_class() without return types