MCPcopy Create free account
hub / github.com/DocsaidLab/MRZScanner / test_textdecoder_enum_conversion

Function test_textdecoder_enum_conversion

tests/test_utils.py:116–132  ·  view source on GitHub ↗
(monkeypatch)

Source from the content-addressed store, hash-verified

114
115
116def test_textdecoder_enum_conversion(monkeypatch):
117 chars_dict = {"<PAD>": 0, "<EOS>": 1, "A": 2}
118 # 對 DecodeMode.obj_to_enum 進行 patch,處理數字字串輸入
119 original_obj_to_enum = DecodeMode.obj_to_enum
120
121 def patched_obj_to_enum(cls, obj):
122 if isinstance(obj, str) and obj.isdigit():
123 obj = int(obj)
124 return original_obj_to_enum(obj)
125 monkeypatch.setattr(DecodeMode, "obj_to_enum",
126 classmethod(patched_obj_to_enum))
127
128 decoder1 = TextDecoder(chars_dict=chars_dict, decode_mode=1)
129 assert decoder1.decode_mode == DecodeMode.CTC
130
131 decoder2 = TextDecoder(chars_dict=chars_dict, decode_mode="2")
132 assert decoder2.decode_mode == DecodeMode.Normal

Callers

nothing calls this directly

Calls 1

TextDecoderClass · 0.90

Tested by

no test coverage detected