Created
April 8, 2019 02:19
-
-
Save Hanaasagi/d004e47858f11677bbcaf15a6066b079 to your computer and use it in GitHub Desktop.
一种通过 MonkeyType + Pytest 来自动注解的方法(准确率不高,仍需要人工修改)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
python type-apply.py | |
``` | |
import os | |
import subprocess | |
DIR = "" | |
for root, dirs, files in os.walk(DIR, topdown=False): | |
for name in files: | |
if not name.split(".")[-1] == "py" or name == "__init__.py": | |
continue | |
path = os.path.join(root, name) | |
mod = path[:-3].replace("/", ".")[2:] | |
cmd = f"monkeytype apply {mod}" | |
print(f"\033[34m{cmd}\033[0m") | |
p = subprocess.Popen( | |
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True | |
) | |
stdout, stderr = list( | |
map(lambda s: s.decode("utf-8").strip(), p.communicate()) | |
) | |
if len(stdout): | |
print(f"\033[92m{stdout}\033[0m") | |
if len(stderr): | |
print(f"\033[31m{stderr}\033[0m") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
monkeytype run type-gen.py | |
``` | |
import pytest | |
TEST_PATH = "" | |
rv = pytest.main([TEST_PATH, "--verbose"]) | |
exit(rv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment