-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
_generate_all_templates.py
33 lines (26 loc) · 1.11 KB
/
_generate_all_templates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding: utf-8
import os
from pathlib import Path
TESTS_DIR_PATH = os.path.dirname(os.path.abspath(__file__)) # path/to/tests
KERASY_LIB_PATH = os.path.join(os.path.dirname(TESTS_DIR_PATH), "gummy") # path/to/kerasy
STOP_FILE = ["__init__.py", "setup.py"] # Files which don't need test.
STOP_DIR = ["templates", "utils"] # Programs under these directories don't need test.
p = Path(KERASY_LIB_PATH)
for abs_path in p.glob("**/*.py"):
rela_path = abs_path.relative_to(p)
fn = rela_path.name # hoge.py
parent = rela_path.parent # (/path/to)/hoge.py
# File Name check.
if fn in STOP_FILE:
continue
# Directory name check.
if any([par.name in STOP_DIR for par in rela_path.parents]):
continue
test_prog_path = os.path.join(parent, "test_" + fn)
if not parent.exists():
os.makedirs(parent)
print(f"- [DIR] \033[32m{parent}\033[0m created.")
if not os.path.exists(test_prog_path):
with open(test_prog_path, mode="w") as f:
f.write("# coding: utf-8")
print(f"\t- [FILE] \033[34m{test_prog_path}\033[0m created.")