Download code/tt_dsocr/tests/test_host_inputs.py from changh95/DeepSeek-OCR: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/changh95/DeepSeek-OCR/resolve/main/code/tt_dsocr/tests/test_host_inputs.py
- Command line
-
hf download hf://changh95/DeepSeek-OCR/code/tt_dsocr/tests/test_host_inputs.py
-
curl -L -o test_host_inputs.py https://huggingface.co/changh95/DeepSeek-OCR/resolve/main/code/tt_dsocr/tests/test_host_inputs.py
1.23 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| """Text inputs that the tokenizer cannot take (a lone UTF-16 surrogate, valid in JSON) are a 400, not a 500.""" | |
| from __future__ import annotations | |
| import os | |
| import sys | |
| import pytest | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(HERE))) | |
| from tt_dsocr import config as C # noqa: E402 | |
| from tt_dsocr.api import DeepSeekOcr, InputError # noqa: E402 | |
| def _model(variant): | |
| m = DeepSeekOcr.__new__(DeepSeekOcr) | |
| m.cfg = C.resolve_config({"DSOCR_VARIANT": variant, "DSOCR_BACKEND": "fake"}) | |
| m.vinfo = m.cfg.info | |
| m.tasks = C.TASK_PROMPTS[variant] | |
| return m | |
| def test_lone_surrogate_prompt_is_an_input_error(variant): | |
| m = _model(variant) | |
| with pytest.raises(InputError, match="surrogate"): | |
| m.resolve_prompt(None, "read this \ud800 please", None) | |
| if "locate" in m.tasks: | |
| with pytest.raises(InputError, match="surrogate"): | |
| m.resolve_prompt("locate", None, "x\udfff") | |
| # ordinary non-ASCII text is fine | |
| assert m.resolve_prompt(None, "읽어 주세요 ✓", None)[1] == "읽어 주세요 ✓" | |