(monkeypatch)
| 114 | |
| 115 | |
| 116 | def 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 |
nothing calls this directly
no test coverage detected