Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r84282:77404fa13979 Date: 2016-05-07 15:01 -0700 http://bitbucket.org/pypy/pypy/changeset/77404fa13979/
Log: merge 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 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit