Skip to content

Commit

Permalink
Merge pull request #72 from kotaro-kinoshita/test/add-unittest
Browse files Browse the repository at this point in the history
add unittest
  • Loading branch information
kotaro-kinoshita authored Jan 4, 2025
2 parents 7979ead + 07f4da8 commit 2f44b27
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/yomitoku/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import os
import torch
from pathlib import Path

import cv2
Expand Down Expand Up @@ -235,7 +236,7 @@ def main():
if args.lite:
configs["ocr"]["text_recognizer"]["model_name"] = "parseq-small"

if args.device == "cpu":
if args.device == "cpu" or not torch.cuda.is_available():
configs["ocr"]["text_detector"]["infer_onnx"] = True

# Note: Text Detector以外はONNX推論よりもPyTorch推論の方が速いため、ONNX推論は行わない
Expand Down
1 change: 0 additions & 1 deletion src/yomitoku/document_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def extract_words_within_element(pred_words, element):
if len(contained_words) == 0:
return None, None, check_list

element_direction = "horizontal"
word_direction = [word.direction for word in contained_words]
cnt_horizontal = word_direction.count("horizontal")
cnt_vertical = word_direction.count("vertical")
Expand Down
2 changes: 2 additions & 0 deletions src/yomitoku/export/export_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def save_figure(
out_path,
figure_dir="figures",
):
assert img is not None, "img is required for saving figures"

for i, figure in enumerate(figures):
x1, y1, x2, y2 = map(int, figure.box)
figure_img = img[y1:y2, x1:x2, :]
Expand Down
2 changes: 2 additions & 0 deletions src/yomitoku/export/export_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def figure_to_html(
figure_dir="figures",
width=200,
):
assert img is not None, "img is required for saving figures"

elements = []
for i, figure in enumerate(figures):
x1, y1, x2, y2 = map(int, figure.box)
Expand Down
2 changes: 2 additions & 0 deletions src/yomitoku/export/export_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def save_figure(
out_path,
figure_dir="figures",
):
assert img is not None, "img is required for saving figures"

for i, figure in enumerate(figures):
x1, y1, x2, y2 = map(int, figure.box)
figure_img = img[y1:y2, x1:x2, :]
Expand Down
2 changes: 2 additions & 0 deletions src/yomitoku/export/export_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def figure_to_md(
width=200,
figure_dir="figures",
):
assert img is not None, "img is required for saving figures"

elements = []
for i, figure in enumerate(figures):
x1, y1, x2, y2 = map(int, figure.box)
Expand Down
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def test_validate_encoding():
validate_encoding("utf-9")

assert validate_encoding("utf-8")
assert validate_encoding("utf-8-sig")
assert validate_encoding("shift-jis")
assert validate_encoding("euc-jp")
assert validate_encoding("cp932")
Loading

0 comments on commit 2f44b27

Please sign in to comment.