Kaydet (Commit) 040e16e3 authored tarafından Victor Stinner's avatar Victor Stinner

"unicode_internal" codec has been deprecated: fix related tests

üst 8ab440e4
import test.support, unittest import codecs
import sys, codecs, html.entities, unicodedata import html.entities
import sys
import test.support
import unicodedata
import unittest
import warnings
try: try:
import ctypes import ctypes
...@@ -621,6 +626,9 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -621,6 +626,9 @@ class CodecCallbackTest(unittest.TestCase):
("utf-7", b"+x-"), ("utf-7", b"+x-"),
("unicode-internal", b"\x00"), ("unicode-internal", b"\x00"),
): ):
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
self.assertRaises( self.assertRaises(
TypeError, TypeError,
bytes.decode, bytes.decode,
...@@ -842,6 +850,9 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -842,6 +850,9 @@ class CodecCallbackTest(unittest.TestCase):
else: else:
raise TypeError("don't know how to handle %r" % exc) raise TypeError("don't know how to handle %r" % exc)
codecs.register_error("test.replacing", replacing) codecs.register_error("test.replacing", replacing)
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
for (encoding, data) in baddata: for (encoding, data) in baddata:
self.assertRaises(TypeError, data.decode, encoding, "test.replacing") self.assertRaises(TypeError, data.decode, encoding, "test.replacing")
......
from test import support import _testcapi
import unittest
import codecs import codecs
import io
import locale import locale
import sys, _testcapi, io import sys
import unittest
import warnings
from test import support
if sys.platform == 'win32': if sys.platform == 'win32':
VISTA_OR_LATER = (sys.getwindowsversion().major >= 6) VISTA_OR_LATER = (sys.getwindowsversion().major >= 6)
...@@ -1051,6 +1055,10 @@ class UnicodeInternalTest(unittest.TestCase): ...@@ -1051,6 +1055,10 @@ class UnicodeInternalTest(unittest.TestCase):
self.assertEqual(("ab", 12), ignored) self.assertEqual(("ab", 12), ignored)
def test_encode_length(self): def test_encode_length(self):
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
# Issue 3739 # Issue 3739
encoder = codecs.getencoder("unicode_internal") encoder = codecs.getencoder("unicode_internal")
self.assertEqual(encoder("a")[1], 1) self.assertEqual(encoder("a")[1], 1)
...@@ -1512,6 +1520,11 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling): ...@@ -1512,6 +1520,11 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
elif encoding == "latin_1": elif encoding == "latin_1":
name = "latin_1" name = "latin_1"
self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-")) self.assertEqual(encoding.replace("_", "-"), name.replace("_", "-"))
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
(b, size) = codecs.getencoder(encoding)(s) (b, size) = codecs.getencoder(encoding)(s)
self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding)) self.assertEqual(size, len(s), "%r != %r (encoding=%r)" % (size, len(s), encoding))
(chars, size) = codecs.getdecoder(encoding)(b) (chars, size) = codecs.getdecoder(encoding)(b)
......
...@@ -5,13 +5,13 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). ...@@ -5,13 +5,13 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY. (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""#" """#"
import _string
import codecs import codecs
import struct import struct
import sys import sys
import unittest import unittest
import warnings import warnings
from test import support, string_tests from test import support, string_tests
import _string
# Error handling (bad decoder return) # Error handling (bad decoder return)
def search_function(encoding): def search_function(encoding):
...@@ -1394,6 +1394,10 @@ class UnicodeTest(string_tests.CommonTest, ...@@ -1394,6 +1394,10 @@ class UnicodeTest(string_tests.CommonTest,
for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le',
'utf-16-be', 'raw_unicode_escape', 'utf-16-be', 'raw_unicode_escape',
'unicode_escape', 'unicode_internal'): 'unicode_escape', 'unicode_internal'):
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
self.assertEqual(str(u.encode(encoding),encoding), u) self.assertEqual(str(u.encode(encoding),encoding), u)
# Roundtrip safety for BMP (just the first 256 chars) # Roundtrip safety for BMP (just the first 256 chars)
...@@ -1409,6 +1413,10 @@ class UnicodeTest(string_tests.CommonTest, ...@@ -1409,6 +1413,10 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual(str(u.encode(encoding),encoding), u) self.assertEqual(str(u.encode(encoding),encoding), u)
# Roundtrip safety for non-BMP (just a few chars) # Roundtrip safety for non-BMP (just a few chars)
with warnings.catch_warnings():
# unicode-internal has been deprecated
warnings.simplefilter("ignore", DeprecationWarning)
u = '\U00010001\U00020002\U00030003\U00040004\U00050005' u = '\U00010001\U00020002\U00030003\U00040004\U00050005'
for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be', for encoding in ('utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
'raw_unicode_escape', 'raw_unicode_escape',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment