Files
ewoooc/tests/test_export_excel_sanitizer.py
OoO 8145c227c7
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
fix: sanitize excel export values
2026-06-18 14:58:32 +08:00

24 lines
712 B
Python

import io
import pandas as pd
from routes.export_routes import _sanitize_excel_dataframe
def test_excel_export_sanitizer_removes_openpyxl_illegal_control_chars():
df = pd.DataFrame({
"商品名稱": ["【Cetaphil 舒特膚官方】Baby舒緩潤膚乳400ml\x0b"],
"價格": [399],
})
cleaned = _sanitize_excel_dataframe(df)
assert cleaned.loc[0, "商品名稱"] == "【Cetaphil 舒特膚官方】Baby舒緩潤膚乳400ml"
assert cleaned.loc[0, "價格"] == 399
output = io.BytesIO()
with pd.ExcelWriter(output, engine="openpyxl") as writer:
cleaned.to_excel(writer, index=False, sheet_name="PChome覆核隊列")
assert output.getbuffer().nbytes > 0