Enable UFMT on test/onnx_caffe2, test/optim, test/package and test/profiler (#123901)

Part of: #123062

Ran lintrunner on:

 - `test/onnx_caffe2`
- `test/optim`
- `test/package`
- `test/profiler`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/123901
Approved by: https://github.com/ezyang
This commit is contained in:
Yuanhao Ji
2024-04-15 17:46:54 +00:00
committed by PyTorch MergeBot
parent 63dcb5b0f2
commit 8ce29f1416
17 changed files with 797 additions and 572 deletions

View File

@ -11,7 +11,12 @@ 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
from torch.testing._internal.common_utils import (
IS_FBCODE,
IS_SANDCASTLE,
run_tests,
skipIfTorchDynamo,
)
try:
from .common import PackageTestCase
@ -118,7 +123,9 @@ class TestMisc(PackageTestCase):
def get_filename(self, name):
result = super().get_filename(name)
if name == "module_a":
return os.path.join(os.path.dirname(result), "module_a_remapped_path.py")
return os.path.join(
os.path.dirname(result), "module_a_remapped_path.py"
)
else:
return result
@ -139,7 +146,9 @@ class TestMisc(PackageTestCase):
if spec is not None:
break
assert spec is not None and isinstance(spec.loader, SourceFileLoader)
spec.loader = LoaderThatRemapsModuleA(spec.loader.name, spec.loader.path)
spec.loader = LoaderThatRemapsModuleA(
spec.loader.name, spec.loader.path
)
return spec
sys.meta_path.insert(0, FinderThatRemapsModuleA())
@ -154,7 +163,6 @@ class TestMisc(PackageTestCase):
he.intern("**")
he.save_module(module_a.__name__)
buffer.seek(0)
hi = PackageImporter(buffer)
self.assertTrue("remapped_path" in hi.get_source("module_a"))