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: Tests package's Directory structure representation of a zip file. Ensures
  that the returned Directory prints what is expected and filters
  inputs/outputs correctly.
docstr_tok: ["Tests","package","'s","Directory","structure","representation","of","a","zip","file",".","Ensures","that","the","returned","Directory","prints","what","is","expected","and","filters","inputs\/outputs","correctly","."]
code: def test_file_structure(self):
      """
      Tests package's Directory structure representation of a zip file. Ensures
      that the returned Directory prints what is expected and filters
      inputs/outputs correctly.
      """
      buffer = BytesIO()
  
      export_plain = dedent(
          """\
                  ├── .data
                  │   ├── extern_modules
                  │   ├── python_version
                  │   ├── serialization_id
                  │   └── version
                  ├── main
                  │   └── main
                  ├── obj
                  │   └── obj.pkl
                  ├── package_a
                  │   ├── __init__.py
                  │   └── subpackage.py
                  ├── byteorder
                  └── module_a.py
              """
      )
      export_include = dedent(
          """\
                  ├── obj
                  │   └── obj.pkl
                  └── package_a
                      └── subpackage.py
              """
      )
      import_exclude = dedent(
          """\
                  ├── .data
                  │   ├── extern_modules
                  │   ├── python_version
                  │   ├── serialization_id
                  │   └── version
                  ├── main
                  │   └── main
                  ├── obj
                  │   └── obj.pkl
                  ├── package_a
                  │   ├── __init__.py
                  │   └── subpackage.py
                  ├── byteorder
                  └── module_a.py
              """
      )
  
      with PackageExporter(buffer) as he:
          import module_a
          import package_a
          import package_a.subpackage
  
          obj = package_a.subpackage.PackageASubpackageObject()
          he.intern("**")
          he.save_module(module_a.__name__)
          he.save_module(package_a.__name__)
          he.save_pickle("obj", "obj.pkl", obj)
          he.save_text("main", "main", "my string")
  
      buffer.seek(0)
      hi = PackageImporter(buffer)
  
      file_structure = hi.file_structure()
      # remove first line from testing because WINDOW/iOS/Unix treat the buffer differently
      self.assertEqual(
          dedent("\n".join(str(file_structure).split("\n")[1:])),
          export_plain,
      )
      file_structure = hi.file_structure(
          include=["**/subpackage.py", "**/*.pkl"]
      )
      self.assertEqual(
          dedent("\n".join(str(file_structure).split("\n")[1:])),
          export_include,
      )
  
      file_structure = hi.file_structure(exclude="**/*.storage")
      self.assertEqual(
          dedent("\n".join(str(file_structure).split("\n")[1:])),
          import_exclude,
      )
  
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 1 for calling the TestMisc obj's underlying member method code with example usage: obj.test_file_structure() without return types