Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-99593: Add tests for Unicode C API (part 1)#99651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,6 +11,10 @@ | ||
| NULL = None | ||
| class Str(str): | ||
| pass | ||
| class CAPITest(unittest.TestCase): | ||
| @support.cpython_only | ||
| @@ -22,6 +26,11 @@ def test_fromobject(self): | ||
| for s in ['abc', '\xa1\xa2', '\u4f60\u597d', 'a\U0001f600', | ||
| 'a\ud800b\udfffc', '\ud834\udd1e']: | ||
| self.assertEqual(fromobject(s), s) | ||
| o = Str(s) | ||
| s2 = fromobject(o) | ||
| self.assertEqual(s2, s) | ||
| self.assertIs(type(s2), str) | ||
| self.assertIsNot(s2, s) | ||
| self.assertRaises(TypeError, fromobject, b'abc') | ||
| self.assertRaises(TypeError, fromobject, []) | ||
| @@ -438,7 +447,7 @@ def test_split(self): | ||
| self.assertRaises(ValueError, split, 'a|b|c|d', '') | ||
| self.assertRaises(TypeError, split, 'a|b|c|d', ord('|')) | ||
| self.assertRaises(TypeError, split, [], '|') | ||
| #CRASHESsplit(NULL, '|') | ||
| @support.cpython_only | ||
| @unittest.skipIf(_testcapi is None, 'need _testcapi module') | ||
| @@ -462,7 +471,7 @@ def test_rsplit(self): | ||
| self.assertRaises(ValueError, rsplit, 'a|b|c|d', '') | ||
| self.assertRaises(TypeError, rsplit, 'a|b|c|d', ord('|')) | ||
| self.assertRaises(TypeError, rsplit, [], '|') | ||
| #CRASHESrsplit(NULL, '|') | ||
| @support.cpython_only | ||
| @unittest.skipIf(_testcapi is None, 'need _testcapi module') | ||
| @@ -530,6 +539,7 @@ def test_translate(self): | ||
| 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.assertEqual(translate('abc', []), 'abc') | ||
| self.assertRaises(UnicodeTranslateError, translate, 'abc', {ord('b'): None}) | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Is the doc wrong? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. The doc is wrong. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ah. The surprising part is that str.translate() treats None as "delete: Well, it would be nice to update the doc (maybe in a separated PR). MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Because | ||
| self.assertRaises(UnicodeTranslateError, translate, 'abc', {ord('b'): None}, 'strict') | ||
| @@ -543,6 +553,7 @@ def test_translate(self): | ||
| self.assertRaises(TypeError, translate, 'abc', {ord('a'): b'A'}) | ||
| self.assertRaises(TypeError, translate, 'abc', 123) | ||
| self.assertRaises(TypeError, translate, 'abc', NULL) | ||
| self.assertRaises(LookupError, translate, 'abc', {ord('b'): None}, 'foo') | ||
| # CRASHES translate(NULL, []) | ||
| @support.cpython_only | ||
| @@ -551,6 +562,7 @@ def test_join(self): | ||
| """Test PyUnicode_Join()""" | ||
| from _testcapi import unicode_join as join | ||
| self.assertEqual(join('|', ['a', 'b', 'c']), 'a|b|c') | ||
| self.assertEqual(join('|', ['a', '', 'c']), 'a||c') | ||
| self.assertEqual(join('', ['a', 'b', 'c']), 'abc') | ||
| self.assertEqual(join(NULL, ['a', 'b', 'c']), 'a b c') | ||
| self.assertEqual(join('|', ['а', 'б', 'в']), 'а|б|в') | ||
| @@ -596,11 +608,6 @@ def test_tailmatch(self): | ||
| """Test PyUnicode_Tailmatch()""" | ||
| from _testcapi import unicode_tailmatch as tailmatch | ||
| str = 'ababahalamaha' | ||
| self.assertEqual(tailmatch(str, 'aba', 0, len(str), -1), 1) | ||
| self.assertEqual(tailmatch(str, 'aha', 0, len(str), 1), 1) | ||
| @@ -790,7 +797,7 @@ def test_richcompare(self): | ||
| @support.cpython_only | ||
| @unittest.skipIf(_testcapi is None, 'need _testcapi module') | ||
| def test_format(self): | ||
| """TestPyUnicode_Format()""" | ||
| from _testcapi import unicode_format as format | ||
| self.assertEqual(format('x=%d!', 42), 'x=42!') | ||
| @@ -838,6 +845,7 @@ def test_isidentifier(self): | ||
| self.assertEqual(isidentifier("["), 0) | ||
| self.assertEqual(isidentifier("©"), 0) | ||
| self.assertEqual(isidentifier("0"), 0) | ||
serhiy-storchaka marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| self.assertEqual(isidentifier("32M"), 0) | ||
| # CRASHES isidentifier(b"a") | ||
| # CRASHES isidentifier([]) | ||