mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Enable UFMT format on test/license.py test/logging.py (#125737)
Fixes some files in #123062 Run lintrunner on files: test/license.py test/logging.py ```bash $ lintrunner -a --take UFMT --all-files ok No lint issues. Successfully applied all patches. ``` Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com> Pull Request resolved: https://github.com/pytorch/pytorch/pull/125737 Approved by: https://github.com/ezyang, https://github.com/malfet
This commit is contained in:
committed by
PyTorch MergeBot
parent
a5c93a6899
commit
01fb9676b8
@ -1081,9 +1081,7 @@ exclude_patterns = [
|
|||||||
'test/test_jit_string.py',
|
'test/test_jit_string.py',
|
||||||
'test/test_jiterator.py',
|
'test/test_jiterator.py',
|
||||||
'test/test_kernel_launch_checks.py',
|
'test/test_kernel_launch_checks.py',
|
||||||
'test/test_license.py',
|
|
||||||
'test/test_linalg.py',
|
'test/test_linalg.py',
|
||||||
'test/test_logging.py',
|
|
||||||
'test/test_masked.py',
|
'test/test_masked.py',
|
||||||
'test/test_maskedtensor.py',
|
'test/test_maskedtensor.py',
|
||||||
'test/test_matmul_cuda.py',
|
'test/test_matmul_cuda.py',
|
||||||
|
@ -6,7 +6,7 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.testing._internal.common_utils import TestCase, run_tests
|
from torch.testing._internal.common_utils import run_tests, TestCase
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -14,24 +14,25 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
create_bundled = None
|
create_bundled = None
|
||||||
|
|
||||||
license_file = 'third_party/LICENSES_BUNDLED.txt'
|
license_file = "third_party/LICENSES_BUNDLED.txt"
|
||||||
starting_txt = 'The Pytorch repository and source distributions bundle'
|
starting_txt = "The Pytorch repository and source distributions bundle"
|
||||||
site_packages = os.path.dirname(os.path.dirname(torch.__file__))
|
site_packages = os.path.dirname(os.path.dirname(torch.__file__))
|
||||||
distinfo = glob.glob(os.path.join(site_packages, 'torch-*dist-info'))
|
distinfo = glob.glob(os.path.join(site_packages, "torch-*dist-info"))
|
||||||
|
|
||||||
|
|
||||||
class TestLicense(TestCase):
|
class TestLicense(TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(not create_bundled, "can only be run in a source tree")
|
@unittest.skipIf(not create_bundled, "can only be run in a source tree")
|
||||||
def test_license_for_wheel(self):
|
def test_license_for_wheel(self):
|
||||||
current = io.StringIO()
|
current = io.StringIO()
|
||||||
create_bundled('third_party', current)
|
create_bundled("third_party", current)
|
||||||
with open(license_file) as fid:
|
with open(license_file) as fid:
|
||||||
src_tree = fid.read()
|
src_tree = fid.read()
|
||||||
if not src_tree == current.getvalue():
|
if not src_tree == current.getvalue():
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
f'the contents of "{license_file}" do not '
|
f'the contents of "{license_file}" do not '
|
||||||
'match the current state of the third_party files. Use '
|
"match the current state of the third_party files. Use "
|
||||||
'"python third_party/build_bundled.py" to regenerate it')
|
'"python third_party/build_bundled.py" to regenerate it'
|
||||||
|
)
|
||||||
|
|
||||||
@unittest.skipIf(len(distinfo) == 0, "no installation in site-package to test")
|
@unittest.skipIf(len(distinfo) == 0, "no installation in site-package to test")
|
||||||
def test_distinfo_license(self):
|
def test_distinfo_license(self):
|
||||||
@ -40,11 +41,14 @@ class TestLicense(TestCase):
|
|||||||
party bundle of licenses"""
|
party bundle of licenses"""
|
||||||
|
|
||||||
if len(distinfo) > 1:
|
if len(distinfo) > 1:
|
||||||
raise AssertionError('Found too many "torch-*dist-info" directories '
|
raise AssertionError(
|
||||||
f'in "{site_packages}, expected only one')
|
'Found too many "torch-*dist-info" directories '
|
||||||
with open(os.path.join(os.path.join(distinfo[0], 'LICENSE'))) as fid:
|
f'in "{site_packages}, expected only one'
|
||||||
|
)
|
||||||
|
with open(os.path.join(os.path.join(distinfo[0], "LICENSE"))) as fid:
|
||||||
txt = fid.read()
|
txt = fid.read()
|
||||||
self.assertTrue(starting_txt in txt)
|
self.assertTrue(starting_txt in txt)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
run_tests()
|
run_tests()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Owner(s): ["module: unknown"]
|
# Owner(s): ["module: unknown"]
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.testing._internal.common_utils import TestCase, run_tests
|
from torch.testing._internal.common_utils import run_tests, TestCase
|
||||||
|
|
||||||
|
|
||||||
class LoggingTest(TestCase):
|
class LoggingTest(TestCase):
|
||||||
@ -14,9 +14,11 @@ class LoggingTest(TestCase):
|
|||||||
s = TestCase.runWithPytorchAPIUsageStderr("import torch")
|
s = TestCase.runWithPytorchAPIUsageStderr("import torch")
|
||||||
self.assertRegex(s, "PYTORCH_API_USAGE.*import")
|
self.assertRegex(s, "PYTORCH_API_USAGE.*import")
|
||||||
# import the shared library directly - it triggers static init but doesn't call anything
|
# import the shared library directly - it triggers static init but doesn't call anything
|
||||||
s = TestCase.runWithPytorchAPIUsageStderr(f"from ctypes import CDLL; CDLL('{torch._C.__file__}')")
|
s = TestCase.runWithPytorchAPIUsageStderr(
|
||||||
|
f"from ctypes import CDLL; CDLL('{torch._C.__file__}')"
|
||||||
|
)
|
||||||
self.assertNotRegex(s, "PYTORCH_API_USAGE")
|
self.assertNotRegex(s, "PYTORCH_API_USAGE")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
run_tests()
|
run_tests()
|
||||||
|
Reference in New Issue
Block a user