-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_tests.py
78 lines (68 loc) · 2.6 KB
/
make_tests.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import yaml
import re
from collections import OrderedDict
import yaml_dumpers
def extract_info_from_md(file_path):
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
# Extracting the required fields using regex
id_match = re.search(r"# テスト ID\s*\n\s*(.*?)\s*\n", content, re.DOTALL)
title_match = re.search(r"# テストのタイトル\s*\n\s*(.*?)\s*\n", content, re.DOTALL)
criteria_match = re.search(
r"# テストの対象となる達成基準 \(複数\)\s*\n\s*(.*?)\s*\n", content, re.DOTALL
)
techs_match = re.search(
r"# 関連する達成方法 \(複数\)\s*\n\s*(.*?)\s*\n", content, re.DOTALL
)
code_link_match = re.search(
r"# テストコード \(テストファイルへのリンク\)\s*\n\s*\[(.*?)\]\((.*?)\)",
content,
re.DOTALL,
)
if id_match and title_match and code_link_match:
test_id = id_match.group(1).strip().replace("WAIC-TEST-", "")
title = title_match.group(1).strip()
criteria = (
[c.strip() for c in criteria_match.group(1).split("\n") if c.strip()]
if criteria_match
else []
)
techs = (
[t.strip() for t in techs_match.group(1).split("\n") if t.strip()]
if techs_match
else []
)
code_link = code_link_match.group(2).strip()
return test_id, OrderedDict(
{
"title": title,
"code": code_link,
"document": f"https://github.com/waic/as_test/blob/master/WAIC-TEST/HTML/{os.path.basename(file_path)}",
"criteria": criteria,
"techs": techs,
}
)
return None, None
def generate_tests_yaml(directory):
tests = OrderedDict()
for filename in sorted(os.listdir(directory)):
if filename.endswith(".md"):
file_path = os.path.join(directory, filename)
test_id, info = extract_info_from_md(file_path)
if test_id and info:
tests[test_id] = info
yaml.add_representer(OrderedDict, yaml_dumpers.represent_odict)
yaml.add_representer(str, yaml_dumpers.represent_str)
yaml.add_representer(type(None), yaml_dumpers.represent_none)
with open("tests.yaml", "w", encoding="utf-8") as yaml_file:
yaml.dump(
tests,
yaml_file,
allow_unicode=True,
default_flow_style=False,
sort_keys=False,
)
# Directory containing the markdown files
directory = "../as_test/WAIC-TEST/HTML"
generate_tests_yaml(directory)