| 1 |
|
| 2 |
import py |
| 3 |
from py.test import raises |
| 4 |
from pypy.interpreter.error import OperationError |
| 5 |
|
| 6 |
class TestW_StdObjSpace: |
| 7 |
|
| 8 |
def test_wrap_wrap(self): |
| 9 |
py.test.skip("maybe unskip in the future") |
| 10 |
raises(TypeError, |
| 11 |
self.space.wrap, |
| 12 |
self.space.wrap(0)) |
| 13 |
|
| 14 |
def test_utf8(self): |
| 15 |
assert self.space.isinstance_w(self.space.newtext("abc"), self.space.w_unicode) |
| 16 |
|
| 17 |
def test_text_w_non_str(self): |
| 18 |
raises(OperationError,self.space.text_w,self.space.wrap(None)) |
| 19 |
raises(OperationError,self.space.text_w,self.space.wrap(0)) |
| 20 |
|
| 21 |
def test_int_w_non_int(self): |
| 22 |
raises(OperationError,self.space.int_w,self.space.wrap(None)) |
| 23 |
raises(OperationError,self.space.int_w,self.space.wrap("")) |
| 24 |
|
| 25 |
def test_uint_w_non_int(self): |
| 26 |
raises(OperationError,self.space.uint_w,self.space.wrap(None)) |
| 27 |
raises(OperationError,self.space.uint_w,self.space.wrap("")) |
| 28 |
|
| 29 |
def test_sliceindices(self): |
| 30 |
space = self.space |
| 31 |
w_obj = space.appexec([], """(): |
| 32 |
class Stuff(object): |
| 33 |
def indices(self, l): |
| 34 |
return 1,2,3 |
| 35 |
return Stuff() |
| 36 |
""") |
| 37 |
w = space.wrap |
| 38 |
w_slice = space.newslice(w(1), w(2), w(1)) |
| 39 |
assert space.sliceindices(w_slice, w(3)) == (1,2,1) |
| 40 |
assert space.sliceindices(w_obj, w(3)) == (1,2,3) |
| 41 |
|
| 42 |
def test_fastpath_isinstance(self): |
| 43 |
from pypy.objspace.std.bytesobject import W_BytesObject |
| 44 |
from pypy.objspace.std.intobject import W_AbstractIntObject |
| 45 |
from pypy.objspace.std.iterobject import W_AbstractSeqIterObject |
| 46 |
from pypy.objspace.std.iterobject import W_SeqIterObject |
| 47 |
|
| 48 |
space = self.space |
| 49 |
assert space._get_interplevel_cls(space.w_bytes) is W_BytesObject |
| 50 |
assert space._get_interplevel_cls(space.w_int) is W_AbstractIntObject |
| 51 |
class X(W_BytesObject): |
| 52 |
def __init__(self): |
| 53 |
pass |
| 54 |
|
| 55 |
typedef = None |
| 56 |
|
| 57 |
assert space.isinstance_w(X(), space.w_bytes) |
| 58 |
|
| 59 |
w_sequenceiterator = space.gettypefor(W_SeqIterObject) |
| 60 |
cls = space._get_interplevel_cls(w_sequenceiterator) |
| 61 |
assert cls is W_AbstractSeqIterObject |
| 62 |
|
| 63 |
def test_wrap_various_unsigned_types(self): |
| 64 |
import sys |
| 65 |
from rpython.rlib.rarithmetic import r_uint |
| 66 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 67 |
space = self.space |
| 68 |
value = sys.maxint * 2 |
| 69 |
x = r_uint(value) |
| 70 |
assert space.eq_w(space.wrap(value), space.wrap(x)) |
| 71 |
x = rffi.cast(rffi.UINTPTR_T, r_uint(value)) |
| 72 |
assert x > 0 |
| 73 |
assert space.eq_w(space.wrap(value), space.wrap(x)) |
| 74 |
value = 60000 |
| 75 |
x = rffi.cast(rffi.USHORT, r_uint(value)) |
| 76 |
assert space.eq_w(space.wrap(value), space.wrap(x)) |
| 77 |
value = 200 |
| 78 |
x = rffi.cast(rffi.UCHAR, r_uint(value)) |
| 79 |
assert space.eq_w(space.wrap(value), space.wrap(x)) |
| 80 |
|
| 81 |
def test_wrap_string(self): |
| 82 |
from pypy.objspace.std.unicodeobject import W_UnicodeObject |
| 83 |
from pypy.objspace.std.unicodeobject import BadUtf8 |
| 84 |
w_x = self.space.wrap('foo') |
| 85 |
assert isinstance(w_x, W_UnicodeObject) |
| 86 |
assert w_x._utf8 == 'foo' |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
py.test.raises(BadUtf8, self.space.wrap, 'foo\xF0') |