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-99593: Add tests for Unicode C API (part 1) by serhiy-storchaka · Pull Request #99651 · python/cpython Conversation
|
| self.assertRaises(ValueError, split, 'a|b|c|d', '') | ||
| self.assertRaises(TypeError, split, 'a|b|c|d', ord('|')) | ||
| self.assertRaises(TypeError, split, [], '|') | ||
| # split(NULL, '|') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
what does this comment stand for? Does the function crash with NULL? Same question for similar rsplit() comment below.
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.
It crashes. It was the first test written by me 4 years ago, before I lost my sign, so I missed to add word CRASHES here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.assertEqual(translate('abcd', {ord('a'): 'A', ord('b'): ord('B'), ord('c'): '<>'}), 'AB<>d') | ||
| self.assertEqual(translate('абвг', {ord('а'): 'А', ord('б'): ord('Б'), ord('в'): '<>'}), 'АБ<>г') | ||
| self.assertEqual(translate('abc', []), 'abc') | ||
| self.assertRaises(UnicodeTranslateError, translate, 'abc', {ord('b'): None}) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. None is supposed to delete the "b" character: https://docs.python.org/dev/library/stdtypes.html#text-sequence-type-str
The mapping table must map Unicode ordinal integers to Unicode ordinal integers or None (causing deletion of the character).
Is the doc wrong?
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.
The doc is wrong.
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.
Ah. The surprising part is that str.translate() treats None as "delete:
>>> "abc".translate(str.maketrans({'b': None}))
'ac'
Well, it would be nice to update the doc (maybe in a separated PR).
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.
Because str.translate calls PyUnicode_Translate() with the error handler "ignore".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| #for str in "\xa1", "\u8000\u8080", "\ud800\udc02", "\U0001f100\U0001f1f1": | ||
| #for i, ch in enumerate(str): | ||
| #self.assertEqual(tailmatch(str, ch, 0, len(str), 1), i) | ||
| #self.assertEqual(tailmatch(str, ch, 0, len(str), -1), i) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
why is this code commented? if it is meaningless for tailmatch, just remove it?
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.
I copied it from other tests (for find/index/count), but did not adapted it to tailmatch yet. I think it is easier to remove it now.
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 a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review Victor. I have a problem with reviewing such large volume of code, especially if many lines looks similar, so I can easily miss some types of errors. Without your help I would not find them.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| self.assertRaises(ValueError, split, 'a|b|c|d', '') | ||
| self.assertRaises(TypeError, split, 'a|b|c|d', ord('|')) | ||
| self.assertRaises(TypeError, split, [], '|') | ||
| # split(NULL, '|') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It crashes. It was the first test written by me 4 years ago, before I lost my sign, so I missed to add word CRASHES here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.assertEqual(translate('abcd', {ord('a'): 'A', ord('b'): ord('B'), ord('c'): '<>'}), 'AB<>d') | ||
| self.assertEqual(translate('абвг', {ord('а'): 'А', ord('б'): ord('Б'), ord('в'): '<>'}), 'АБ<>г') | ||
| self.assertEqual(translate('abc', []), 'abc') | ||
| self.assertRaises(UnicodeTranslateError, translate, 'abc', {ord('b'): None}) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The doc is wrong.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| #for str in "\xa1", "\u8000\u8080", "\ud800\udc02", "\U0001f100\U0001f1f1": | ||
| #for i, ch in enumerate(str): | ||
| #self.assertEqual(tailmatch(str, ch, 0, len(str), 1), i) | ||
| #self.assertEqual(tailmatch(str, ch, 0, len(str), -1), i) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I copied it from other tests (for find/index/count), but did not adapted it to tailmatch yet. I think it is easier to remove it now.
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 a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self.assertEqual(translate('abcd', {ord('a'): 'A', ord('b'): ord('B'), ord('c'): '<>'}), 'AB<>d') | ||
| self.assertEqual(translate('абвг', {ord('а'): 'А', ord('б'): ord('Б'), ord('в'): '<>'}), 'АБ<>г') | ||
| self.assertEqual(translate('abc', []), 'abc') | ||
| self.assertRaises(UnicodeTranslateError, translate, 'abc', {ord('b'): None}) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah. The surprising part is that str.translate() treats None as "delete:
>>> "abc".translate(str.maketrans({'b': None}))
'ac'
Well, it would be nice to update the doc (maybe in a separated PR).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @serhiy-storchaka, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oh, I didn't notice that you want to backport these tests to Python 3.10 and 3.11. You're motivated :-) If it's too complicated, maybe just add them to Python 3.12, no? _testcapi changed a lot since Python 3.11 (splited into multiple files). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think that we should backport as many tests as possible, otherwise we risk to miss a regression introduced before the particular test was added. Especially if we do so many changes in C API. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry @serhiy-storchaka, I had trouble checking out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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.