plotscribe / tests /test_ocr_parse.py
jkos9's picture
Claude Opus 5.5
plotscribe: classical-CV chart image to CSV extractor
6f423bd
Raw History Blame Contribute Delete
794 Bytes
import pytest
from plotscribe.ocr import parse_number, parse_offset_text
@pytest.mark.parametrize("text,value", [
("1,000", 1000.0), ("1e3", 1000.0), ("5%", 5.0), ("$10", 10.0), ("1.5k", 1500.0),
("−2.5", -2.5), ("(5)", -5.0), ("O.5", 0.5), ("l00", 100.0), ("S0", 50.0),
("2M", 2e6), ("1,5", 1.5), ("10^3", 1000.0), ("-0.25", -0.25), ("3bn", 3e9),
])
def test_parse_number(text, value):
assert parse_number(text) == pytest.approx(value)
@pytest.mark.parametrize("text", ["Jan", "Revenue", "", "--", "1.2.3"])
def test_parse_number_rejects_text(text):
assert parse_number(text) is None
def test_offset_text():
assert parse_offset_text("1e6") == (1e6, 0.0)
assert parse_offset_text("+1.063e3") == (1.0, 1063.0)
assert parse_offset_text("Results") is None