GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — gh-111495: improve test coverage of codecs C API by picnixz · Pull Request #126030 · python/cpython Conversation
|
|
Edit: please disregard this comment, I tested the wrong code! Click to expand the originalThis passes for me when I remove the diff --git a/Lib/test/test_capi/test_codecs.py b/Lib/test/test_capi/test_codecs.py index b764981cca6..d3af4d576f9 100644 --- a/Lib/test/test_capi/test_codecs.py +++ b/Lib/test/test_capi/test_codecs.py @@ -745,28 +745,6 @@ def test_codec_stream_writer(self): codec_stream_writer(NULL, stream, 'strict') -class UnsafeUnicodeEncodeError(UnicodeEncodeError): - def __init__(self, encoding, message, start, end, reason): - self.may_crash = (end - start) < 0 or (end - start) >= len(message) - super().__init__(encoding, message, start, end, reason) - - -class UnsafeUnicodeDecodeError(UnicodeDecodeError): - def __init__(self, encoding, message, start, end, reason): - # the case end - start >= len(message) does not crash - self.may_crash = (end - start) < 0 - super().__init__(encoding, message, start, end, reason) - - -class UnsafeUnicodeTranslateError(UnicodeTranslateError): - def __init__(self, message, start, end, reason): - # <= 0 because PyCodec_ReplaceErrors tries to check the Unicode kind - # of a 0-length result (which is by convention PyUnicode_1BYTE_KIND - # and not PyUnicode_2BYTE_KIND as it currently expects) - self.may_crash = (end - start) <= 0 or (end - start) >= len(message) - super().__init__(message, start, end, reason) - - class CAPICodecErrors(unittest.TestCase): @classmethod def _generate_exceptions(cls, atomic_literal, factory, objlens): @@ -780,19 +758,19 @@ def _generate_exceptions(cls, atomic_literal, factory, objlens): @classmethod def generate_encode_errors(cls, objlen, *objlens): def factory(obj, start, end): - return UnsafeUnicodeEncodeError('utf-8', obj, start, end, 'reason') + return UnicodeEncodeError('utf-8', obj, start, end, 'reason') return tuple(cls._generate_exceptions('0', factory, [objlen, *objlens])) @classmethod def generate_decode_errors(cls, objlen, *objlens): def factory(obj, start, end): - return UnsafeUnicodeDecodeError('utf-8', obj, start, end, 'reason') + return UnicodeDecodeError('utf-8', obj, start, end, 'reason') return tuple(cls._generate_exceptions(b'0', factory, [objlen, *objlens])) @classmethod def generate_translate_errors(cls, objlen, *objlens): def factory(obj, start, end): - return UnsafeUnicodeTranslateError(obj, start, end, 'reason') + return UnicodeTranslateError(obj, start, end, 'reason') return tuple(cls._generate_exceptions('0', factory, [objlen, *objlens])) @classmethod @@ -889,20 +867,11 @@ def test_codec_namereplace_errors_handler(self): self.do_test_codec_errors_handler(handler, exceptions, bad_exceptions) def do_test_codec_errors_handler(self, handler, exceptions, bad_exceptions): - at_least_one = False for exc in exceptions: - # See https://github.com/python/cpython/issues/123378 and related - # discussion and issues for details. - if exc.may_crash: - continue - - at_least_one = True with self.subTest(handler=handler, exc=exc): # test that the handler does not crash self.assertIsInstance(handler(exc), tuple) - self.assertTrue(at_least_one, "all exceptions are crashing") - for bad_exc in bad_exceptions: with self.subTest('bad type', handler=handler, exc=bad_exc): self.assertRaises(TypeError, handler, bad_exc) What am I missing? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Huh... I don't really know now. Are the PoCs: ./python -c "import codecs; codecs.xmlcharrefreplace_errors(UnicodeEncodeError('bad', '', 0, 1, 'reason'))" ./python -c "import codecs; codecs.replace_errors(UnicodeTranslateError('000', 1, -7, 'reason'))" crashing for you? I am no more on my dev env so I'll have a look at it tomorrow. EDIT 1: Ah! I actually did not test the translate errors in ./python -c "import codecs; codecs.backslashreplace_errors(UnicodeDecodeError('utf-8', b'00000', 9, 2, 'reason'))" does not crash, it simply raises a SystemError due to negative size. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@encukou I think I know: did you configure Python using |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ah, misconfiguratoin on my side. Sorry for the noise! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
These look good, but I think some of the code could be made easier to read.
It's all subjective, of course. Do you find your version easier (or have particular reason to write them that way)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Not really, that was the first approach I had in mind :D but I'll include some of your suggestions, thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks Petr! (you just reviewed when I left my dev session...) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Petr Viktorin <[email protected]>
For now, skip some crashers (tracked in pythongh-123378).
For now, skip some crashers (tracked in pythongh-123378).
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.