Add generic production context helpers
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import pytest
|
||||
|
||||
from production_analytics.context import (
|
||||
build_enlyze_production_order,
|
||||
extract_nominal_width_m,
|
||||
)
|
||||
|
||||
K7_ORDER_TEMPLATE = "K 7-{production_order}"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("order, expected", [
|
||||
("12026000815", "K 7-12026000815"),
|
||||
(" \t12026000815\n", "K 7-12026000815"),
|
||||
("00123", "K 7-00123"),
|
||||
])
|
||||
def test_k7_mapping(order, expected):
|
||||
assert build_enlyze_production_order(order, K7_ORDER_TEMPLATE) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("order", [
|
||||
"", " \t", "K 7-12026000815", "K 7-12025000074-K 7-12025000075",
|
||||
"12025000074-12025000075", "prefix12026000815", "12026000815suffix",
|
||||
"12026 000815", "123", "-123",
|
||||
])
|
||||
def test_mapping_rejects_non_erp_identifiers(order):
|
||||
with pytest.raises(ValueError, match="ERP production order"):
|
||||
build_enlyze_production_order(order, K7_ORDER_TEMPLATE)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template, expected", [
|
||||
("EXAMPLE/{production_order}/finished", "EXAMPLE/00123/finished"),
|
||||
("{production_order}", "00123"),
|
||||
("{production_order}-example", "00123-example"),
|
||||
])
|
||||
def test_mapping_uses_explicit_template(template, expected):
|
||||
assert build_enlyze_production_order(" 00123 ", template) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template", [
|
||||
"", "fixed-order", "{order}", "{production_order}-{production_order}",
|
||||
"{production_order:>20}", "{production_order!r}", "{production_order}{unknown}",
|
||||
"{{production_order}}",
|
||||
])
|
||||
def test_mapping_rejects_invalid_template(template):
|
||||
with pytest.raises(ValueError, match="Format template"):
|
||||
build_enlyze_production_order("12026000815", template)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("description, expected", [
|
||||
("Stex R 1501 C (PR) 5,80 x 50 m", 5.8),
|
||||
("Stex R 401, 6,00 x 90 m", 6.0),
|
||||
("Stex R 1501 5.80 x 50 m", 5.8),
|
||||
("5,80x50 m", 5.8),
|
||||
("5,80x50m", 5.8),
|
||||
("Article 212520 grade 1501 5,80\t x\t50 m", 5.8),
|
||||
("5,80 x 50 m coated (batch 42)", 5.8),
|
||||
("(5,80 x 50 m), coated", 5.8),
|
||||
("6 x 90 m", 6.0),
|
||||
])
|
||||
def test_width(description, expected):
|
||||
assert extract_nominal_width_m(description) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("description", [
|
||||
None, "", "Stex R 1501", "5,80 m", "5,80 x 50", "5,80 x 50 cm",
|
||||
"5,80 x 50 mm", "5,80 x 50 m²", "5,80 x 50 m2", "5,80 x 50 m/min",
|
||||
"5,80 x 50 metres", "5,80,2 x 50 m", "5.80.2 x 50 m",
|
||||
"5,80 x ? m", "5,80 x 50 m or 6,00 x 90 m", "2 x 5,80 x 50 m",
|
||||
"5,80 x 50 m x 2", "0 x 50 m", "-5,80 x 50 m", "+5,80 x 50 m",
|
||||
"nan x 50 m", "inf x 50 m", "Infinity x 50 m", "1e309 x 50 m",
|
||||
"9" * 400 + " x 50 m", "5,80 x 0 m", "5,80 x -50 m", "5,80 x nan m",
|
||||
"1/5,80 x 50 m", "abc5,80 x 50 m",
|
||||
])
|
||||
def test_width_fails_safely(description):
|
||||
assert extract_nominal_width_m(description) is None
|
||||
Reference in New Issue
Block a user