Marco Ricci commited on 2025-01-25 20:55:43
Zeige 1 geänderte Dateien mit 19 Einfügungen und 16 Löschungen.
... | ... |
@@ -10,6 +10,7 @@ import contextlib |
10 | 10 |
import errno |
11 | 11 |
import gettext |
12 | 12 |
import os |
13 |
+import re |
|
13 | 14 |
import string |
14 | 15 |
from typing import TYPE_CHECKING, cast |
15 | 16 |
|
... | ... |
@@ -215,25 +217,27 @@ class TestL10nMachineryWithDebugTranslations: |
215 | 217 |
""" |
216 | 218 |
with monkeypatched_null_translations(): |
217 | 219 |
ts1 = msg.TranslatedString(s) |
218 |
- with pytest.raises((KeyError, ValueError)) as excinfo: |
|
219 |
- str(ts1) |
|
220 |
- if '{spam}' in s: |
|
221 |
- assert isinstance(excinfo.value, KeyError) |
|
222 |
- assert excinfo.value.args[0] == 'spam' |
|
223 |
- else: |
|
224 |
- assert isinstance(excinfo.value, ValueError) |
|
225 |
- assert excinfo.value.args[0].startswith('Single ') |
|
226 |
- assert excinfo.value.args[0].endswith( |
|
227 |
- ' encountered in format string' |
|
228 |
- ) |
|
229 | 220 |
ts2 = msg.TranslatedString(s, spam='eggs') |
230 |
- try: |
|
221 |
+ if '{spam}' in s: |
|
222 |
+ with pytest.raises(KeyError, match=r'spam'): |
|
223 |
+ str(ts1) |
|
231 | 224 |
assert str(ts2) == s.replace('{spam}', 'eggs') |
232 |
- except ValueError as exc: |
|
233 |
- assert exc.args[0].startswith('Single ') # noqa: PT017 |
|
234 |
- assert exc.args[0].endswith( # noqa: PT017 |
|
235 |
- ' encountered in format string' |
|
225 |
+ else: |
|
226 |
+ # Known error message variations: |
|
227 |
+ # |
|
228 |
+ # * Single { encountered in the pattern string |
|
229 |
+ # * Single } encountered in the pattern string |
|
230 |
+ # * Single '{' encountered in the pattern string |
|
231 |
+ # * Single '}' encountered in the pattern string |
|
232 |
+ # * Single '{' |
|
233 |
+ # * Single '}' |
|
234 |
+ pattern = re.compile( |
|
235 |
+ r"Single (?:\{|\}|'\{'|'\}')(?: encountered in the pattern string)?" |
|
236 | 236 |
) |
237 |
+ with pytest.raises(ValueError, match=pattern): |
|
238 |
+ str(ts1) |
|
239 |
+ with pytest.raises(ValueError, match=pattern): |
|
240 |
+ str(ts2) |
|
237 | 241 |
|
238 | 242 |
@hypothesis.given( |
239 | 243 |
s=strategies.text( |
240 | 244 |