Files
2026Technology-Competition/tests/test_formatting_detector.py
T

62 lines
1.5 KiB
Python

from copy import copy
from openpyxl import Workbook
from openpyxl.comments import Comment
from genesis.data_models import CellComment, CellFormatting
from genesis.parsers.formatting_detector import (
cell_comment, cell_formatting, collect_comments,
)
def make_wb():
wb = Workbook()
ws = wb.active
ws.title = "機能一覧"
ws["A1"] = "F001"
font = copy(ws["A1"].font)
font.strike = True
ws["A1"].font = font
ws["A2"] = "F002"
ws["A2"].comment = Comment("要確認", "reviewer")
return wb
def test_cell_formatting_detects_strike():
fmt = cell_formatting(make_wb().active["A1"])
assert fmt is not None
assert fmt.strikethrough is True
def test_cell_formatting_none_when_plain():
wb = Workbook()
ws = wb.active
ws["A1"] = "x"
assert cell_formatting(ws["A1"]) is None
def test_cell_formatting_detects_font_color():
from openpyxl.styles import Font
wb = Workbook()
ws = wb.active
ws["A1"] = "x"
f = copy(ws["A1"].font)
f.color = Font(color="FF0000FF").color
ws["A1"].font = f
fmt = cell_formatting(ws["A1"])
assert fmt is not None
assert fmt.font_color is not None
def test_cell_comment_returns_obj():
wb = make_wb()
cm = cell_comment(wb.active["A2"], "f.xlsx")
assert isinstance(cm, CellComment)
assert cm.author == "reviewer"
assert cm.text == "要確認"
assert cm.source_uri == "f.xlsx#機能一覧!A2"
def test_collect_comments():
comments = collect_comments(make_wb().active, "f.xlsx")
assert len(comments) == 1