56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""生产废弃物列表:产出类型解析与关键字匹配语义。"""
|
|
import unittest
|
|
|
|
from app.crud.production_waste_output import (
|
|
WASTE_OUTPUT_TYPE_CODE,
|
|
WASTE_OUTPUT_TYPE_NAME,
|
|
match_waste_output_keyword,
|
|
pick_waste_output_type_ids,
|
|
)
|
|
|
|
|
|
class TestPickWasteOutputTypeIds(unittest.TestCase):
|
|
def test_prefers_type_code_fqw(self):
|
|
rows = [
|
|
{"id": "a", "type_code": "YXW", "type_name": "有效物"},
|
|
{"id": "b", "type_code": "FQW", "type_name": "废弃物"},
|
|
{"id": "c", "type_code": "", "type_name": "废弃物"},
|
|
]
|
|
self.assertEqual(pick_waste_output_type_ids(rows), {"b"})
|
|
|
|
def test_fallback_type_name_when_no_fqw(self):
|
|
rows = [
|
|
{"id": "a", "type_code": "YXW", "type_name": "有效物"},
|
|
{"id": "c", "type_code": "", "type_name": "废弃物"},
|
|
{"id": "d", "type_code": None, "type_name": "废弃物"},
|
|
]
|
|
self.assertEqual(pick_waste_output_type_ids(rows), {"c", "d"})
|
|
|
|
def test_empty_when_no_match(self):
|
|
self.assertEqual(pick_waste_output_type_ids([]), set())
|
|
self.assertEqual(
|
|
pick_waste_output_type_ids([{"id": "a", "type_code": "YXW", "type_name": "有效物"}]),
|
|
set(),
|
|
)
|
|
|
|
|
|
class TestMatchWasteOutputKeyword(unittest.TestCase):
|
|
def test_matches_name_or_barcode(self):
|
|
self.assertTrue(match_waste_output_keyword("废液", "废液A", "X1"))
|
|
self.assertTrue(match_waste_output_keyword("X1", "废液", "BX1Y"))
|
|
self.assertFalse(match_waste_output_keyword("zzz", "废液", "X1"))
|
|
|
|
def test_blank_keyword_always_true(self):
|
|
self.assertTrue(match_waste_output_keyword("", "废液", ""))
|
|
self.assertTrue(match_waste_output_keyword(None, "", ""))
|
|
|
|
|
|
class TestConstants(unittest.TestCase):
|
|
def test_constants(self):
|
|
self.assertEqual(WASTE_OUTPUT_TYPE_CODE, "FQW")
|
|
self.assertEqual(WASTE_OUTPUT_TYPE_NAME, "废弃物")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|