refactor: centralize classifier constants and simplify logic
This commit is contained in:
53
backend/tests/test_classifier_refactor.py
Normal file
53
backend/tests/test_classifier_refactor.py
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
import pytest
|
||||
from app.services.integrated_classifier import classify_material_integrated
|
||||
from app.services.fitting_classifier import classify_fitting
|
||||
from app.services.classifier_constants import LEVEL1_TYPE_KEYWORDS
|
||||
|
||||
def test_classify_simple_pipe():
|
||||
result = classify_material_integrated("PIPE, A106 Gr.B, 2 INCH")
|
||||
# LEVEL1_TYPE_KEYWORDS["PIPE"] contains "PIPE"
|
||||
assert result["category"] == "PIPE"
|
||||
|
||||
def test_classify_fitting_elbow():
|
||||
result = classify_material_integrated("ELBOW 90DEG, BW")
|
||||
# Should route to FITTING and then call fitting_classifier
|
||||
assert result["category"] == "FITTING"
|
||||
# detail check
|
||||
if "fitting_type" in result:
|
||||
assert result["fitting_type"]["type"] == "ELBOW"
|
||||
|
||||
def test_classify_swagelok_partno():
|
||||
# Regex check in integrated_classifier
|
||||
result = classify_material_integrated("SS-400-1-4 CONNECTOR")
|
||||
# Should be detected by swagelok_pattern as TUBE_FITTING (Level 0)
|
||||
assert result["category"] == "TUBE_FITTING"
|
||||
|
||||
def test_classify_swagelok_keyword():
|
||||
# Keyword check
|
||||
result = classify_material_integrated("SWAGELOK UNION 1/4 INCH")
|
||||
# 'SWAGELOK' is in FITTING list in constants.
|
||||
# So it should be FITTING?
|
||||
# BUT integrated_classifier has logic: if detected_type == FITTING -> call classify_fitting
|
||||
# classify_fitting checks 'SWAGELOK' -> sets category 'INSTRUMENT_FITTING'
|
||||
|
||||
# Let's see what meaningful category it returns.
|
||||
# The return from classify_fitting overrides integrated result if present.
|
||||
assert result["category"] in ["FITTING", "INSTRUMENT_FITTING"]
|
||||
|
||||
def test_classify_u_bolt():
|
||||
# Priority check: U-BOLT is in BOLT keywords but integrated_classifier has early check for SUPPORT
|
||||
result = classify_material_integrated("U-BOLT, 2 INCH")
|
||||
assert result["category"] == "SUPPORT"
|
||||
|
||||
def test_classify_pressure_constants_usage():
|
||||
# fitting_classifier uses imported constants
|
||||
# Test if it recognizes 3000LB (from constants)
|
||||
result = classify_fitting("P_DAT", "COUPLING, 3000LB, SW", "2")
|
||||
assert result["pressure_rating"]["rating"] == "3000LB"
|
||||
assert result["pressure_rating"]["confidence"] > 0.9
|
||||
|
||||
def test_classify_olet_constants_usage():
|
||||
# Detect OLET
|
||||
result = classify_fitting("P_DAT", "WELDOLET, 3000LB", "2", "1")
|
||||
assert result["fitting_type"]["type"] == "OLET"
|
||||
Reference in New Issue
Block a user