pytorch/tools/test/test_actions_local_runner.py
davidriazati@fb.com 5e4dfd0140 Add quicklint make target (#56559)
Summary:
This queries the local git repo for changed files (any changed files, not just committed ones) and sends them to mypy/flake8 instead of the default (which is the whole repo, defined the .flake8 and mypy.ini files). This brings a good speedup (from 15 seconds with no cache to < 1 second from my local testing on this PR).

```bash
make quicklint -j 6
```

It should be noted that the results of this aren’t exactly what’s in the CI, since mypy and flake8 ignore the `include` and `exclude` parts of their config when an explicit list of files is passed in.
](https://our.intern.facebook.com/intern/diff/27901577/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56559

Pulled By: driazati

Reviewed By: malfet

Differential Revision: D27901577

fbshipit-source-id: 99f351cdfe5aba007948aea2b8a78f683c5d8583
2021-04-21 13:47:25 -07:00

60 lines
1.9 KiB
Python

import unittest
import sys
import contextlib
import io
from typing import List, Dict, Any
from tools import actions_local_runner
if __name__ == '__main__':
if sys.version_info >= (3, 8):
# actions_local_runner uses asyncio features not available in 3.6, and
# IsolatedAsyncioTestCase was added in 3.8, so skip testing on
# unsupported systems
class TestRunner(unittest.IsolatedAsyncioTestCase):
def run(self, *args: List[Any], **kwargs: List[Dict[str, Any]]) -> Any:
return super().run(*args, **kwargs)
def test_step_extraction(self) -> None:
fake_job = {
"steps": [
{
"name": "test1",
"run": "echo hi"
},
{
"name": "test2",
"run": "echo hi"
},
{
"name": "test3",
"run": "echo hi"
},
]
}
actual = actions_local_runner.grab_specific_steps(["test2"], fake_job)
expected = [
{
"name": "test2",
"run": "echo hi"
},
]
self.assertEqual(actual, expected)
async def test_runner(self) -> None:
fake_step = {
"name": "say hello",
"run": "echo hi"
}
f = io.StringIO()
with contextlib.redirect_stdout(f):
await actions_local_runner.run_steps([fake_step], "test", None)
result = f.getvalue()
self.assertIn("say hello", result)
self.assertIn("hi", result)
unittest.main()