Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84100:bf4e328270ce
Date: 2016-05-01 15:38 +0200
http://bitbucket.org/pypy/pypy/changeset/bf4e328270ce/
Log: merge heads
diff --git a/pypy/module/unicodedata/interp_ucd.py
b/pypy/module/unicodedata/interp_ucd.py
--- a/pypy/module/unicodedata/interp_ucd.py
+++ b/pypy/module/unicodedata/interp_ucd.py
@@ -4,7 +4,7 @@
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from rpython.rlib.rarithmetic import r_longlong
from rpython.rlib.objectmodel import we_are_translated
@@ -34,8 +34,9 @@
# Target is wide build
def unichr_to_code_w(space, w_unichr):
if not space.isinstance_w(w_unichr, space.w_unicode):
- raise OperationError(space.w_TypeError, space.wrap(
- 'argument 1 must be unicode'))
+ raise oefmt(
+ space.w_TypeError, 'argument 1 must be unicode, not %T',
+ w_unichr)
if not we_are_translated() and sys.maxunicode == 0xFFFF:
# Host CPython is narrow build, accept surrogates
@@ -54,8 +55,9 @@
# Target is narrow build
def unichr_to_code_w(space, w_unichr):
if not space.isinstance_w(w_unichr, space.w_unicode):
- raise OperationError(space.w_TypeError, space.wrap(
- 'argument 1 must be unicode'))
+ raise oefmt(
+ space.w_TypeError, 'argument 1 must be unicode, not %T',
+ w_unichr)
if not we_are_translated() and sys.maxunicode > 0xFFFF:
# Host CPython is wide build, forbid surrogates
@@ -179,7 +181,9 @@
@unwrap_spec(form=str)
def normalize(self, space, form, w_unistr):
if not space.isinstance_w(w_unistr, space.w_unicode):
- raise OperationError(space.w_TypeError, space.wrap('argument 2
must be unicode'))
+ raise oefmt(
+ space.w_TypeError, 'argument 2 must be unicode, not %T',
+ w_unistr)
if form == 'NFC':
composed = True
decomposition = self._canon_decomposition
diff --git a/pypy/module/unicodedata/test/test_unicodedata.py
b/pypy/module/unicodedata/test/test_unicodedata.py
--- a/pypy/module/unicodedata/test/test_unicodedata.py
+++ b/pypy/module/unicodedata/test/test_unicodedata.py
@@ -78,10 +78,15 @@
import unicodedata
assert unicodedata.lookup("GOTHIC LETTER FAIHU") == u'\U00010346'
- def test_normalize(self):
+ def test_normalize_bad_argcount(self):
import unicodedata
raises(TypeError, unicodedata.normalize, 'x')
+ def test_normalize_nonunicode(self):
+ import unicodedata
+ exc_info = raises(TypeError, unicodedata.normalize, 'NFC', 'x')
+ assert str(exc_info.value).endswith('must be unicode, not str')
+
@py.test.mark.skipif("sys.maxunicode < 0x10ffff")
def test_normalize_wide(self):
import unicodedata
@@ -103,6 +108,12 @@
# For no reason, unicodedata.mirrored() returns an int, not a bool
assert repr(unicodedata.mirrored(u' ')) == '0'
- def test_bidirectional(self):
+ def test_bidirectional_not_one_character(self):
import unicodedata
- raises(TypeError, unicodedata.bidirectional, u'xx')
+ exc_info = raises(TypeError, unicodedata.bidirectional, u'xx')
+ assert str(exc_info.value) == 'need a single Unicode character as
parameter'
+
+ def test_bidirectional_not_one_character(self):
+ import unicodedata
+ exc_info = raises(TypeError, unicodedata.bidirectional, 'x')
+ assert str(exc_info.value).endswith('must be unicode, not str')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit