mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: This PR - moves `torch/testing/_internal/mypy_wrapper.py` (and its accompanying tests from `test/test_testing.py`) to `tools`, - removes the now-unused `test_run_mypy` from `test/test_type_hints.py`, and - replaces the hardcoded list of `mypy` configs (previously duplicated across `mypy_wrapper.py` and `.github/workflows/lint.yml`) with a simpler glob Pull Request resolved: https://github.com/pytorch/pytorch/pull/54268 Test Plan: Should also be run in the "Test tools" GHA workflow in CI: ``` python tools/test/test_mypy_wrapper.py ``` Reviewed By: janeyx99 Differential Revision: D27168095 Pulled By: samestep fbshipit-source-id: a8dc18407b5e4c103ace23a636b0a8534951905a
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
import unittest
|
|
from pathlib import PurePosixPath
|
|
|
|
from tools import mypy_wrapper
|
|
|
|
|
|
class TestMypyWrapper(unittest.TestCase):
|
|
def test_config_files(self):
|
|
self.assertEqual(mypy_wrapper.config_files(), {
|
|
'mypy.ini',
|
|
'mypy-strict.ini',
|
|
})
|
|
|
|
def test_glob_can_match_individual_files(self):
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='test/test_torch.py',
|
|
filename=PurePosixPath('test/test_torch.py'),
|
|
))
|
|
self.assertFalse(mypy_wrapper.glob(
|
|
pattern='test/test_torch.py',
|
|
filename=PurePosixPath('test/test_testing.py'),
|
|
))
|
|
|
|
def test_glob_dir_matters(self):
|
|
self.assertFalse(mypy_wrapper.glob(
|
|
pattern='tools/codegen/utils.py',
|
|
filename=PurePosixPath('torch/nn/modules.py'),
|
|
))
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='setup.py',
|
|
filename=PurePosixPath('setup.py'),
|
|
))
|
|
self.assertFalse(mypy_wrapper.glob(
|
|
pattern='setup.py',
|
|
filename=PurePosixPath('foo/setup.py'),
|
|
))
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='foo/setup.py',
|
|
filename=PurePosixPath('foo/setup.py'),
|
|
))
|
|
|
|
def test_glob_can_match_dirs(self):
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='torch',
|
|
filename=PurePosixPath('torch/random.py'),
|
|
))
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='torch',
|
|
filename=PurePosixPath('torch/nn/cpp.py'),
|
|
))
|
|
self.assertFalse(mypy_wrapper.glob(
|
|
pattern='torch',
|
|
filename=PurePosixPath('tools/fast_nvcc/fast_nvcc.py'),
|
|
))
|
|
|
|
def test_glob_can_match_wildcards(self):
|
|
self.assertTrue(mypy_wrapper.glob(
|
|
pattern='tools/autograd/*.py',
|
|
filename=PurePosixPath('tools/autograd/gen_autograd.py'),
|
|
))
|
|
self.assertFalse(mypy_wrapper.glob(
|
|
pattern='tools/autograd/*.py',
|
|
filename=PurePosixPath('tools/autograd/deprecated.yaml'),
|
|
))
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|