Skip to content

Commit 4b4d1f5

Browse files
committed
Convert testcase format
1 parent 919e561 commit 4b4d1f5

File tree

127 files changed

+7082
-1448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+7082
-1448
lines changed

Cargo.lock

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

braillove-case-collector/main.py

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
2+
import json
23
from pywinauto.application import Application
3-
import csv
44

55
pattern = " a1b'k2l`cif/msp\"e3h9o6r^djg>ntq,*5<-u8v.%[$+x!&;:4\\0z7(_?w]#y)="
66
braille = "⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿"
@@ -49,48 +49,59 @@ def main():
4949
file_name = os.path.splitext(os.path.basename(test_file))[0]
5050

5151
# output 파일명을 생성합니다
52-
output_file = f"../test_cases/{file_name}.csv"
53-
54-
with open(output_file, "w", encoding="utf-8") as output_file:
55-
writer = csv.writer(output_file)
56-
with open(test_file, "r", encoding="utf-8") as file:
57-
for row in file.readlines():
58-
row = row.strip()
59-
time.sleep(0.3)
60-
pane.type_keys(
61-
row.replace(" ", "{SPACE}")
62-
.replace("(", "{(}")
63-
.replace(")", "{)}"),
64-
pause=0.05,
65-
)
66-
67-
time.sleep(0.3)
68-
69-
# output 에서 read text 가져오기
70-
output_text = output.get_value()
71-
output_num = ""
72-
output_braille = ""
73-
for i in range(len(output_text)):
74-
if output_text[i] in pattern:
75-
output_num += str(pattern.index(output_text[i]))
76-
output_braille += braille[pattern.index(output_text[i])]
52+
output_path = f"../test_cases/{file_name}.json"
53+
54+
entries = []
55+
with open(test_file, "r", encoding="utf-8") as file:
56+
for row in file.readlines():
57+
row = row.strip()
58+
if not row:
59+
continue
60+
time.sleep(0.3)
61+
pane.type_keys(
62+
row.replace(" ", "{SPACE}")
63+
.replace("(", "{(}")
64+
.replace(")", "{)}"),
65+
pause=0.05,
66+
)
67+
68+
time.sleep(0.3)
69+
70+
# output 에서 read text 가져오기
71+
output_text = output.get_value()
72+
output_num = ""
73+
output_braille = ""
74+
for i in range(len(output_text)):
75+
if output_text[i] in pattern:
76+
output_num += str(pattern.index(output_text[i]))
77+
output_braille += braille[pattern.index(output_text[i])]
78+
else:
79+
if output_text[i] == "@":
80+
output_num += "8"
81+
output_braille += braille[8]
82+
elif output_text[i] == "|":
83+
output_num += "51"
84+
output_braille += braille[51]
7785
else:
78-
if output_text[i] == "@":
79-
output_num += "8"
80-
output_braille += braille[8]
81-
elif output_text[i] == "|":
82-
output_num += "51"
83-
output_braille += braille[51]
84-
else:
85-
raise Exception(f"오류: {output_text[i]}")
86-
87-
main_window.set_focus()
88-
time.sleep(0.3)
89-
writer.writerow([row, output_text, output_num, output_braille])
90-
91-
pane.type_keys("{BACKSPACE}" * len(row))
92-
while output.get_value() != "":
93-
pane.type_keys("{BACKSPACE}")
86+
raise Exception(f"오류: {output_text[i]}")
87+
88+
main_window.set_focus()
89+
time.sleep(0.3)
90+
entries.append(
91+
{
92+
"input": row,
93+
"internal": output_text,
94+
"expected": output_num,
95+
"unicode": output_braille,
96+
}
97+
)
98+
99+
pane.type_keys("{BACKSPACE}" * len(row))
100+
while output.get_value() != "":
101+
pane.type_keys("{BACKSPACE}")
102+
103+
with open(output_path, "w", encoding="utf-8") as f:
104+
json.dump(entries, f, ensure_ascii=False, indent=2)
94105

95106
print("완료")
96107
except Exception as e:

braillove-case-collector/verify.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import time
2-
import csv
32
import os
43
import glob
54
import json
@@ -43,7 +42,7 @@ def main():
4342
pane = main_window.child_window(control_type="Pane", title="작업 영역")
4443
output_edit = main_window.child_window(control_type="Edit", title="")
4544

46-
test_case_files = sorted(glob.glob("../test_cases/*.csv"))
45+
test_case_files = sorted(glob.glob("../test_cases/*.json"))
4746
if not test_case_files:
4847
print("No test case files found in ../test_cases/")
4948
return
@@ -62,13 +61,10 @@ def main():
6261
file_passed = 0
6362

6463
with open(test_file, "r", encoding="utf-8") as f:
65-
reader = csv.reader(f)
66-
for row in reader:
67-
if not row or len(row) < 4:
68-
continue
69-
70-
korean_input = row[0].strip()
71-
expected_unicode = row[-1].strip()
64+
records = json.load(f)
65+
for row in records:
66+
korean_input = row["input"].strip()
67+
expected_unicode = row["unicode"].strip()
7268

7369
if not korean_input or not expected_unicode:
7470
continue

libs/braillify/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ once_cell = "1"
2222
unicode-normalization = "0.1.25"
2323

2424
[dev-dependencies]
25-
csv = "1.4.0"
2625
serde_json = "^1"
2726
proptest = "1.10"
2827
assert_cmd = "2"

libs/braillify/src/lib.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ mod test {
967967
let mut file_stats = std::collections::BTreeMap::new();
968968
let files = dir
969969
.map(|entry| entry.unwrap().path())
970-
.filter(|path| path.extension().unwrap_or_default() == "csv")
970+
.filter(|path| path.extension().unwrap_or_default() == "json")
971971
.collect::<Vec<_>>();
972972

973973
// read rule_map.json
@@ -997,28 +997,42 @@ mod test {
997997
}
998998

999999
for path in files {
1000-
let file = File::open(&path).unwrap();
1000+
let content = std::fs::read_to_string(&path).unwrap();
10011001
let filename = path.file_name().unwrap().to_string_lossy();
1002-
let reader = csv::ReaderBuilder::new()
1003-
.has_headers(false)
1004-
.from_reader(file);
1002+
let records: Vec<serde_json::Value> = serde_json::from_str(&content)
1003+
.unwrap_or_else(|e| panic!("JSON 파일을 읽는 중 오류 발생: {} in {}", e, filename));
10051004

10061005
let mut file_total = 0;
10071006
let mut file_failed = 0;
10081007
// input, expected, actual, is_success
10091008
let mut test_status: Vec<(String, String, String, bool)> = Vec::new();
10101009

1011-
for (line_num, result) in reader.into_records().enumerate() {
1010+
for (line_num, record) in records.iter().enumerate() {
10121011
total += 1;
10131012
file_total += 1;
1014-
let error = format!(
1015-
"CSV 레코드를 읽는 중 오류 발생: {:?} at {} in {}",
1016-
result, line_num, filename
1017-
);
1018-
let record = result.expect(&error);
1019-
let input = &record[0];
1013+
let input = record["input"].as_str().unwrap_or_else(|| {
1014+
panic!(
1015+
"'input' 필드를 읽는 중 오류 발생: at {} in {}",
1016+
line_num, filename
1017+
)
1018+
});
10201019
// 테스트 케이스 파일의 숫자 코드에서 앞뒤 공백 제거 후 비교
1021-
let expected = record[2].trim().replace(" ", "⠀");
1020+
let expected = record["expected"]
1021+
.as_str()
1022+
.unwrap_or_else(|| {
1023+
panic!(
1024+
"'expected' 필드를 읽는 중 오류 발생: at {} in {}",
1025+
line_num, filename
1026+
)
1027+
})
1028+
.trim()
1029+
.replace(" ", "⠀");
1030+
let unicode_braille = record["unicode"].as_str().unwrap_or_else(|| {
1031+
panic!(
1032+
"'unicode' 필드를 읽는 중 오류 발생: at {} in {}",
1033+
line_num, filename
1034+
)
1035+
});
10221036
match encode(input) {
10231037
Ok(actual) => {
10241038
let braille_expected = actual
@@ -1036,15 +1050,15 @@ mod test {
10361050
expected.to_string(),
10371051
actual_str.clone(),
10381052
braille_expected.clone(),
1039-
record[3].to_string(),
1053+
unicode_braille.to_string(),
10401054
));
10411055
}
10421056

10431057
test_status.push((
10441058
input.to_string(),
1045-
record[3].to_string(),
1059+
unicode_braille.to_string(),
10461060
braille_expected.clone(),
1047-
record[3].to_string() == braille_expected,
1061+
unicode_braille == braille_expected,
10481062
));
10491063
}
10501064
Err(e) => {
@@ -1058,12 +1072,12 @@ mod test {
10581072
expected.to_string(),
10591073
"".to_string(),
10601074
e.to_string(),
1061-
record[3].to_string(),
1075+
unicode_braille.to_string(),
10621076
));
10631077

10641078
test_status.push((
10651079
input.to_string(),
1066-
record[3].to_string(),
1080+
unicode_braille.to_string(),
10671081
e.to_string(),
10681082
false,
10691083
));

test_cases/rule_1.csv

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)