[pypy-commit] pypy py3k: Match cpython's inconsistent warning about the now-deprecated unicode_internal codec.
marky1991
pypy.commits at gmail.com
Sat May 7 18:02:47 EDT 2016
Author: Mark Young <marky1991 at gmail.com>
Branch: py3k
Changeset: r84281:3c339639fd2f
Date: 2016-05-07 16:29 -0400
http://bitbucket.org/pypy/pypy/changeset/3c339639fd2f/
Log: Match cpython's inconsistent warning about the now-deprecated
unicode_internal codec.
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -802,8 +802,6 @@
@unwrap_spec(errors='str_or_None')
def unicode_internal_decode(space, w_string, errors="strict"):
- space.warn(space.wrap("unicode_internal codec has been deprecated"),
- space.w_DeprecationWarning)
if errors is None:
errors = 'strict'
# special case for this codec: unicodes are returned as is
@@ -811,6 +809,8 @@
return space.newtuple([w_string, space.len(w_string)])
string = space.readbuf_w(w_string).as_str()
+ space.warn(space.wrap("unicode_internal codec has been deprecated"),
+ space.w_DeprecationWarning)
if len(string) == 0:
return space.newtuple([space.wrap(u''), space.wrap(0)])
diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -805,3 +805,38 @@
assert _codecs.unicode_escape_decode(b) == (u'', 0)
assert _codecs.raw_unicode_escape_decode(b) == (u'', 0)
assert _codecs.unicode_internal_decode(b) == (u'', 0)
+
+ def test_unicode_internal_warnings(self):
+ import codecs, warnings
+ warnings.simplefilter("always")
+ encoder = codecs.getencoder("unicode_internal")
+ decoder = codecs.getdecoder("unicode_internal")
+ warning_msg = "unicode_internal codec has been deprecated"
+ with warnings.catch_warnings(record=True) as w:
+ try:
+ encoder(42)
+ except TypeError:
+ pass
+ assert len(w) == 1
+ assert str(w[0].message) == warning_msg
+ assert w[0].category == DeprecationWarning
+
+ with warnings.catch_warnings(record=True) as w:
+ try:
+ decoder(42)
+ except TypeError:
+ pass
+ assert len(w) == 0
+
+ with warnings.catch_warnings(record=True) as w:
+ encoded_abc = encoder("abc")[0]
+ assert len(w) == 1
+ assert str(w[0].message)== warning_msg
+ assert w[0].category == DeprecationWarning
+
+ with warnings.catch_warnings(record=True) as w:
+ print(type(encoded_abc))
+ decoder(encoded_abc)
+ assert len(w) == 1
+ assert str(w[0].message) == warning_msg
+ assert w[0].category == DeprecationWarning
More information about the pypy-commit
mailing list