Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 53 additions & 42 deletions braillove-case-collector/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
import json
from pywinauto.application import Application
import csv

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

# output 파일명을 생성합니다
output_file = f"../test_cases/{file_name}.csv"

with open(output_file, "w", encoding="utf-8") as output_file:
writer = csv.writer(output_file)
with open(test_file, "r", encoding="utf-8") as file:
for row in file.readlines():
row = row.strip()
time.sleep(0.3)
pane.type_keys(
row.replace(" ", "{SPACE}")
.replace("(", "{(}")
.replace(")", "{)}"),
pause=0.05,
)

time.sleep(0.3)

# output 에서 read text 가져오기
output_text = output.get_value()
output_num = ""
output_braille = ""
for i in range(len(output_text)):
if output_text[i] in pattern:
output_num += str(pattern.index(output_text[i]))
output_braille += braille[pattern.index(output_text[i])]
output_path = f"../test_cases/{file_name}.json"

entries = []
with open(test_file, "r", encoding="utf-8") as file:
for row in file.readlines():
row = row.strip()
if not row:
continue
time.sleep(0.3)
pane.type_keys(
row.replace(" ", "{SPACE}")
.replace("(", "{(}")
.replace(")", "{)}"),
pause=0.05,
)

time.sleep(0.3)

# output 에서 read text 가져오기
output_text = output.get_value()
output_num = ""
output_braille = ""
for i in range(len(output_text)):
if output_text[i] in pattern:
output_num += str(pattern.index(output_text[i]))
output_braille += braille[pattern.index(output_text[i])]
else:
if output_text[i] == "@":
output_num += "8"
output_braille += braille[8]
elif output_text[i] == "|":
output_num += "51"
output_braille += braille[51]
else:
if output_text[i] == "@":
output_num += "8"
output_braille += braille[8]
elif output_text[i] == "|":
output_num += "51"
output_braille += braille[51]
else:
raise Exception(f"오류: {output_text[i]}")

main_window.set_focus()
time.sleep(0.3)
writer.writerow([row, output_text, output_num, output_braille])

pane.type_keys("{BACKSPACE}" * len(row))
while output.get_value() != "":
pane.type_keys("{BACKSPACE}")
raise Exception(f"오류: {output_text[i]}")

main_window.set_focus()
time.sleep(0.3)
entries.append(
{
"input": row,
"internal": output_text,
"expected": output_num,
"unicode": output_braille,
}
)

pane.type_keys("{BACKSPACE}" * len(row))
while output.get_value() != "":
pane.type_keys("{BACKSPACE}")

with open(output_path, "w", encoding="utf-8") as f:
json.dump(entries, f, ensure_ascii=False, indent=2)

print("완료")
except Exception as e:
Expand Down
14 changes: 5 additions & 9 deletions braillove-case-collector/verify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
import csv
import os
import glob
import json
Expand Down Expand Up @@ -43,7 +42,7 @@ def main():
pane = main_window.child_window(control_type="Pane", title="작업 영역")
output_edit = main_window.child_window(control_type="Edit", title="")

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

with open(test_file, "r", encoding="utf-8") as f:
reader = csv.reader(f)
for row in reader:
if not row or len(row) < 4:
continue

korean_input = row[0].strip()
expected_unicode = row[-1].strip()
records = json.load(f)
for row in records:
korean_input = row["input"].strip()
expected_unicode = row["unicode"].strip()

if not korean_input or not expected_unicode:
continue
Expand Down
1 change: 0 additions & 1 deletion libs/braillify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ once_cell = "1"
unicode-normalization = "0.1.25"

[dev-dependencies]
csv = "1.4.0"
serde_json = "^1"
proptest = "1.10"
assert_cmd = "2"
Expand Down
50 changes: 32 additions & 18 deletions libs/braillify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ mod test {
let mut file_stats = std::collections::BTreeMap::new();
let files = dir
.map(|entry| entry.unwrap().path())
.filter(|path| path.extension().unwrap_or_default() == "csv")
.filter(|path| path.extension().unwrap_or_default() == "json")
.collect::<Vec<_>>();

// read rule_map.json
Expand Down Expand Up @@ -997,28 +997,42 @@ mod test {
}

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

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

for (line_num, result) in reader.into_records().enumerate() {
for (line_num, record) in records.iter().enumerate() {
total += 1;
file_total += 1;
let error = format!(
"CSV 레코드를 읽는 중 오류 발생: {:?} at {} in {}",
result, line_num, filename
);
let record = result.expect(&error);
let input = &record[0];
let input = record["input"].as_str().unwrap_or_else(|| {
panic!(
"'input' 필드를 읽는 중 오류 발생: at {} in {}",
line_num, filename
)
});
// 테스트 케이스 파일의 숫자 코드에서 앞뒤 공백 제거 후 비교
let expected = record[2].trim().replace(" ", "⠀");
let expected = record["expected"]
.as_str()
.unwrap_or_else(|| {
panic!(
"'expected' 필드를 읽는 중 오류 발생: at {} in {}",
line_num, filename
)
})
.trim()
.replace(" ", "⠀");
let unicode_braille = record["unicode"].as_str().unwrap_or_else(|| {
panic!(
"'unicode' 필드를 읽는 중 오류 발생: at {} in {}",
line_num, filename
)
});
match encode(input) {
Ok(actual) => {
let braille_expected = actual
Expand All @@ -1036,15 +1050,15 @@ mod test {
expected.to_string(),
actual_str.clone(),
braille_expected.clone(),
record[3].to_string(),
unicode_braille.to_string(),
));
}

test_status.push((
input.to_string(),
record[3].to_string(),
unicode_braille.to_string(),
braille_expected.clone(),
record[3].to_string() == braille_expected,
unicode_braille == braille_expected,
));
}
Err(e) => {
Expand All @@ -1058,12 +1072,12 @@ mod test {
expected.to_string(),
"".to_string(),
e.to_string(),
record[3].to_string(),
unicode_braille.to_string(),
));

test_status.push((
input.to_string(),
record[3].to_string(),
unicode_braille.to_string(),
e.to_string(),
false,
));
Expand Down
26 changes: 0 additions & 26 deletions test_cases/rule_1.csv

This file was deleted.

Loading
Loading