summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-02 18:16:38 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-02 18:16:38 (GMT)
commit63b5b6fd450260a4239371e96263020587648ad9 (patch)
tree32be29b96ce945e9cb5704548f4a88b7abcb1c6b /Lib
parent480b0692701317637189180ec5df296ec71487e0 (diff)
downloadcpython-63b5b6fd450260a4239371e96263020587648ad9.zip
cpython-63b5b6fd450260a4239371e96263020587648ad9.tar.gz
cpython-63b5b6fd450260a4239371e96263020587648ad9.tar.bz2
Moved Unicode C API related tests to separate test class.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_unicode.py231
1 files changed, 117 insertions, 114 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index a38e7b1..082f6b5 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -2275,6 +2275,123 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual("%s" % s, '__str__ overridden')
self.assertEqual("{}".format(s), '__str__ overridden')
+ def test_subclass_add(self):
+ class S(str):
+ def __add__(self, o):
+ return "3"
+ self.assertEqual(S("4") + S("5"), "3")
+ class S(str):
+ def __iadd__(self, o):
+ return "3"
+ s = S("1")
+ s += "4"
+ self.assertEqual(s, "3")
+
+ def test_getnewargs(self):
+ text = 'abc'
+ args = text.__getnewargs__()
+ self.assertIsNot(args[0], text)
+ self.assertEqual(args[0], text)
+ self.assertEqual(len(args), 1)
+
+ def test_resize(self):
+ for length in range(1, 100, 7):
+ # generate a fresh string (refcount=1)
+ text = 'a' * length + 'b'
+
+ with support.check_warnings(('unicode_internal codec has been '
+ 'deprecated', DeprecationWarning)):
+ # fill wstr internal field
+ abc = text.encode('unicode_internal')
+ self.assertEqual(abc.decode('unicode_internal'), text)
+
+ # resize text: wstr field must be cleared and then recomputed
+ text += 'c'
+ abcdef = text.encode('unicode_internal')
+ self.assertNotEqual(abc, abcdef)
+ self.assertEqual(abcdef.decode('unicode_internal'), text)
+
+ def test_compare(self):
+ # Issue #17615
+ N = 10
+ ascii = 'a' * N
+ ascii2 = 'z' * N
+ latin = '\x80' * N
+ latin2 = '\xff' * N
+ bmp = '\u0100' * N
+ bmp2 = '\uffff' * N
+ astral = '\U00100000' * N
+ astral2 = '\U0010ffff' * N
+ strings = (
+ ascii, ascii2,
+ latin, latin2,
+ bmp, bmp2,
+ astral, astral2)
+ for text1, text2 in itertools.combinations(strings, 2):
+ equal = (text1 is text2)
+ self.assertEqual(text1 == text2, equal)
+ self.assertEqual(text1 != text2, not equal)
+
+ if equal:
+ self.assertTrue(text1 <= text2)
+ self.assertTrue(text1 >= text2)
+
+ # text1 is text2: duplicate strings to skip the "str1 == str2"
+ # optimization in unicode_compare_eq() and really compare
+ # character per character
+ copy1 = duplicate_string(text1)
+ copy2 = duplicate_string(text2)
+ self.assertIsNot(copy1, copy2)
+
+ self.assertTrue(copy1 == copy2)
+ self.assertFalse(copy1 != copy2)
+
+ self.assertTrue(copy1 <= copy2)
+ self.assertTrue(copy2 >= copy2)
+
+ self.assertTrue(ascii < ascii2)
+ self.assertTrue(ascii < latin)
+ self.assertTrue(ascii < bmp)
+ self.assertTrue(ascii < astral)
+ self.assertFalse(ascii >= ascii2)
+ self.assertFalse(ascii >= latin)
+ self.assertFalse(ascii >= bmp)
+ self.assertFalse(ascii >= astral)
+
+ self.assertFalse(latin < ascii)
+ self.assertTrue(latin < latin2)
+ self.assertTrue(latin < bmp)
+ self.assertTrue(latin < astral)
+ self.assertTrue(latin >= ascii)
+ self.assertFalse(latin >= latin2)
+ self.assertFalse(latin >= bmp)
+ self.assertFalse(latin >= astral)
+
+ self.assertFalse(bmp < ascii)
+ self.assertFalse(bmp < latin)
+ self.assertTrue(bmp < bmp2)
+ self.assertTrue(bmp < astral)
+ self.assertTrue(bmp >= ascii)
+ self.assertTrue(bmp >= latin)
+ self.assertFalse(bmp >= bmp2)
+ self.assertFalse(bmp >= astral)
+
+ self.assertFalse(astral < ascii)
+ self.assertFalse(astral < latin)
+ self.assertFalse(astral < bmp2)
+ self.assertTrue(astral < astral2)
+ self.assertTrue(astral >= ascii)
+ self.assertTrue(astral >= latin)
+ self.assertTrue(astral >= bmp2)
+ self.assertFalse(astral >= astral2)
+
+ def test_free_after_iterating(self):
+ support.check_free_after_iterating(self, iter, str)
+ support.check_free_after_iterating(self, reversed, str)
+
+
+class CAPITest(unittest.TestCase):
+
# Test PyUnicode_FromFormat()
def test_from_format(self):
support.import_module('ctypes')
@@ -2570,18 +2687,6 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual(size, nchar)
self.assertEqual(wchar, nonbmp + '\0')
- def test_subclass_add(self):
- class S(str):
- def __add__(self, o):
- return "3"
- self.assertEqual(S("4") + S("5"), "3")
- class S(str):
- def __iadd__(self, o):
- return "3"
- s = S("1")
- s += "4"
- self.assertEqual(s, "3")
-
@support.cpython_only
def test_encode_decimal(self):
from _testcapi import unicode_encodedecimal
@@ -2610,104 +2715,6 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual(transform_decimal('123\u20ac'),
'123\u20ac')
- def test_getnewargs(self):
- text = 'abc'
- args = text.__getnewargs__()
- self.assertIsNot(args[0], text)
- self.assertEqual(args[0], text)
- self.assertEqual(len(args), 1)
-
- def test_resize(self):
- for length in range(1, 100, 7):
- # generate a fresh string (refcount=1)
- text = 'a' * length + 'b'
-
- with support.check_warnings(('unicode_internal codec has been '
- 'deprecated', DeprecationWarning)):
- # fill wstr internal field
- abc = text.encode('unicode_internal')
- self.assertEqual(abc.decode('unicode_internal'), text)
-
- # resize text: wstr field must be cleared and then recomputed
- text += 'c'
- abcdef = text.encode('unicode_internal')
- self.assertNotEqual(abc, abcdef)
- self.assertEqual(abcdef.decode('unicode_internal'), text)
-
- def test_compare(self):
- # Issue #17615
- N = 10
- ascii = 'a' * N
- ascii2 = 'z' * N
- latin = '\x80' * N
- latin2 = '\xff' * N
- bmp = '\u0100' * N
- bmp2 = '\uffff' * N
- astral = '\U00100000' * N
- astral2 = '\U0010ffff' * N
- strings = (
- ascii, ascii2,
- latin, latin2,
- bmp, bmp2,
- astral, astral2)
- for text1, text2 in itertools.combinations(strings, 2):
- equal = (text1 is text2)
- self.assertEqual(text1 == text2, equal)
- self.assertEqual(text1 != text2, not equal)
-
- if equal:
- self.assertTrue(text1 <= text2)
- self.assertTrue(text1 >= text2)
-
- # text1 is text2: duplicate strings to skip the "str1 == str2"
- # optimization in unicode_compare_eq() and really compare
- # character per character
- copy1 = duplicate_string(text1)
- copy2 = duplicate_string(text2)
- self.assertIsNot(copy1, copy2)
-
- self.assertTrue(copy1 == copy2)
- self.assertFalse(copy1 != copy2)
-
- self.assertTrue(copy1 <= copy2)
- self.assertTrue(copy2 >= copy2)
-
- self.assertTrue(ascii < ascii2)
- self.assertTrue(ascii < latin)
- self.assertTrue(ascii < bmp)
- self.assertTrue(ascii < astral)
- self.assertFalse(ascii >= ascii2)
- self.assertFalse(ascii >= latin)
- self.assertFalse(ascii >= bmp)
- self.assertFalse(ascii >= astral)
-
- self.assertFalse(latin < ascii)
- self.assertTrue(latin < latin2)
- self.assertTrue(latin < bmp)
- self.assertTrue(latin < astral)
- self.assertTrue(latin >= ascii)
- self.assertFalse(latin >= latin2)
- self.assertFalse(latin >= bmp)
- self.assertFalse(latin >= astral)
-
- self.assertFalse(bmp < ascii)
- self.assertFalse(bmp < latin)
- self.assertTrue(bmp < bmp2)
- self.assertTrue(bmp < astral)
- self.assertTrue(bmp >= ascii)
- self.assertTrue(bmp >= latin)
- self.assertFalse(bmp >= bmp2)
- self.assertFalse(bmp >= astral)
-
- self.assertFalse(astral < ascii)
- self.assertFalse(astral < latin)
- self.assertFalse(astral < bmp2)
- self.assertTrue(astral < astral2)
- self.assertTrue(astral >= ascii)
- self.assertTrue(astral >= latin)
- self.assertTrue(astral >= bmp2)
- self.assertFalse(astral >= astral2)
-
@support.cpython_only
def test_pep393_utf8_caching_bug(self):
# Issue #25709: Problem with string concatenation and utf-8 cache
@@ -2725,10 +2732,6 @@ class UnicodeTest(string_tests.CommonTest,
# Check that the second call returns the same result
self.assertEqual(getargs_s_hash(s), chr(k).encode() * (i + 1))
- def test_free_after_iterating(self):
- support.check_free_after_iterating(self, iter, str)
- support.check_free_after_iterating(self, reversed, str)
-
class StringModuleTest(unittest.TestCase):
def test_formatter_parser(self):