-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_errors.py
More file actions
175 lines (116 loc) · 5.77 KB
/
Copy pathtest_errors.py
File metadata and controls
175 lines (116 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import errno
import ssl
from app import errors
def test_is_tls_certificate_error_detects_ssl_error():
exc = ssl.SSLCertVerificationError("CERTIFICATE_VERIFY_FAILED")
assert errors.is_tls_certificate_error(exc)
def test_is_tls_certificate_error_walks_cause_chain():
root = ssl.SSLCertVerificationError("unable to get local issuer certificate")
wrapper = RuntimeError("download failed")
wrapper.__cause__ = root
assert errors.is_tls_certificate_error(wrapper)
def test_is_tls_certificate_error_matches_message_text():
exc = RuntimeError("…CERTIFICATE_VERIFY_FAILED… while contacting host")
assert errors.is_tls_certificate_error(exc)
def test_is_tls_certificate_error_false_for_plain_error():
assert not errors.is_tls_certificate_error(ValueError("nope"))
def test_is_tls_certificate_error_handles_cause_cycle():
a = RuntimeError("a")
b = RuntimeError("b")
a.__cause__ = b
b.__cause__ = a # cycle must not hang
assert not errors.is_tls_certificate_error(a)
def test_openvino_tokenizer_runtime_error_matches_packaged_failure_chain():
root = RuntimeError(
"Cannot add extension. Cannot find entry point to the extension library. "
'Cannot load library "openvino_tokenizers.dll": 126'
)
wrapper = RuntimeError("model compilation failed")
wrapper.__cause__ = root
assert errors.is_openvino_tokenizer_runtime_error(wrapper)
def test_openvino_tokenizer_runtime_error_rejects_unrelated_device_failure():
assert not errors.is_openvino_tokenizer_runtime_error(
RuntimeError("OpenVINO GPU plugin could not compile this model")
)
def test_format_model_load_error_tokenizer_package_message(monkeypatch):
monkeypatch.setattr(errors.sys, "frozen", True, raising=False)
exc = RuntimeError('Cannot load library "openvino_tokenizers.dll": 126')
msg = errors.format_model_load_error(exc)
assert "Reinstall the latest InferBridge build" in msg
assert "falling back to CPU will not fix" in msg
assert "126" not in msg
def test_format_model_convert_error_tokenizer_dependency_message(monkeypatch):
monkeypatch.setattr(errors.sys, "frozen", False, raising=False)
exc = RuntimeError("Cannot add extension openvino_tokenizers.dll: WinError 126")
msg = errors.format_model_convert_error(exc)
assert "matching versions" in msg
assert "openvino-tokenizers" in msg
def test_format_model_convert_error_collapses_nested_failure_prefixes():
exc = RuntimeError(
"Conversion failed: RuntimeError: Conversion failed: Conversion failed: "
"Command '['optimum-cli', 'export']' returned non-zero exit status 1."
)
msg = errors.format_model_convert_error(exc)
assert msg == (
"Conversion failed: Command '['optimum-cli', 'export']' returned non-zero exit status 1."
)
assert msg.count("Conversion failed") == 1
def test_format_model_convert_error_collapses_traceback_wrapper():
exc = RuntimeError(
"optimum-cli failed\n"
"Traceback (most recent call last):\n"
"RuntimeError: Conversion failed: OSError: disk full"
)
msg = errors.format_model_convert_error(exc)
assert "not enough free disk space" in msg
assert "disk full" not in msg.lower()
def test_format_model_convert_error_reports_disk_exhaustion_from_cause():
root = OSError(errno.ENOSPC, "No space left on device")
wrapper = RuntimeError("Optimum export failed")
wrapper.__cause__ = root
msg = errors.format_model_convert_error(wrapper)
assert "not enough free disk space" in msg
assert "previously working model" in msg
def test_format_model_convert_error_reports_windows_file_lock():
exc = PermissionError(errno.EACCES, "Access is denied")
msg = errors.format_model_convert_error(exc)
assert "Windows is using or blocking" in msg
assert "antivirus" in msg
assert "previously working model" in msg
def test_format_model_convert_error_preserves_cross_process_lock_guidance():
exc = RuntimeError(
"Another InferBridge process is already preparing this model. Wait for it to finish."
)
msg = errors.format_model_convert_error(exc)
assert "Another InferBridge process" in msg
assert "close the other InferBridge instance" in msg
def test_format_model_load_error_tls_message_and_bundle(monkeypatch):
monkeypatch.setenv("REQUESTS_CA_BUNDLE", r"C:\certs\corp.pem")
msg = errors.format_model_load_error(ssl.SSLCertVerificationError("CERTIFICATE_VERIFY_FAILED"))
assert "TLS certificate" in msg
assert "python-certifi-win32" in msg
assert r"C:\certs\corp.pem" in msg # active bundle surfaced
def test_format_model_load_error_passes_through_plain():
assert errors.format_model_load_error(ValueError("boom")) == "boom"
def test_format_missing_openvino_mentions_install_and_mock():
msg = errors.format_missing_openvino()
assert "requirements.txt" in msg
assert "OV_LLM_MOCK" in msg
def test_format_model_not_converted_with_source_gives_cli_hint():
msg = errors.format_model_not_converted("My Model", "/models/m", "org/model")
assert "optimum-cli export openvino" in msg
assert "org/model" in msg
assert "/models/m" in msg
def test_format_model_not_converted_without_source():
msg = errors.format_model_not_converted("My Model", "/models/m", "")
assert "optimum-cli" not in msg
assert "/models/m" in msg
def test_format_device_error_npu_and_gpu_hints():
npu = errors.format_device_error("NPU", ["CPU"])
assert "NPU driver" in npu
assert "--device CPU" in npu
gpu = errors.format_device_error("GPU", ["CPU"])
assert "GPU driver" in gpu
def test_format_device_error_lists_available_or_none():
assert "CPU, GPU" in errors.format_device_error("NPU", ["CPU", "GPU"])
assert "none detected" in errors.format_device_error("NPU", [])