def test_string_to_any(self): l = W_ListObject(self.space, [self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')]) assert isinstance(l.strategy, StringListStrategy) l.append(self.space.wrap('d')) assert isinstance(l.strategy, StringListStrategy) l.append(self.space.wrap(3)) assert isinstance(l.strategy, ObjectListStrategy)
def test_empty_to_any(self): space = self.space w = space.wrap wb = space.wrapbytes l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w((1,3))) assert isinstance(l.strategy, ObjectListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(1)) assert isinstance(l.strategy, IntegerListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(wb('a')) assert isinstance(l.strategy, BytesListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(u'a')) assert isinstance(l.strategy, UnicodeListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(1.2)) assert isinstance(l.strategy, FloatListStrategy)
def test_empty_setslice_with_objectlist(self): l = W_ListObject(self.space, []) o = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap("2"), self.space.wrap(3)]) l.setslice(0, 1, o.length(), o) assert l.getitems() == o.getitems() l.append(self.space.wrap(17)) assert l.getitems() != o.getitems()
def test_empty_to_any(self): space = self.space w = space.wrap l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w((1,3))) assert isinstance(l.strategy, ObjectListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(1)) assert isinstance(l.strategy, IntegerListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w('a')) assert isinstance(l.strategy, BytesListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(u'a')) assert isinstance(l.strategy, UnicodeListStrategy) l = W_ListObject(space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(w(1.2)) assert isinstance(l.strategy, FloatListStrategy)
def test_int_to_any(self): l = W_ListObject(self.space, [self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)]) assert isinstance(l.strategy, IntegerListStrategy) l.append(self.space.wrap(4)) assert isinstance(l.strategy, IntegerListStrategy) l.append(self.space.wrap('a')) assert isinstance(l.strategy, ObjectListStrategy)
def test_float_to_any(self): l = W_ListObject(self.space, [self.space.wrap(1.1),self.space.wrap(2.2),self.space.wrap(3.3)]) assert isinstance(l.strategy, FloatListStrategy) l.append(self.space.wrap(4.4)) assert isinstance(l.strategy, FloatListStrategy) l.append(self.space.wrap("a")) assert isinstance(l.strategy, ObjectListStrategy)
def test_unicode_to_any(self): space = self.space l = W_ListObject(space, [space.wrap(u'a'), space.wrap(u'b'), space.wrap(u'c')]) assert isinstance(l.strategy, UnicodeListStrategy) l.append(space.wrap(u'd')) assert isinstance(l.strategy, UnicodeListStrategy) l.append(space.wrap(3)) assert isinstance(l.strategy, ObjectListStrategy)
def test_string_to_any(self): l = W_ListObject(self.space, [self.space.wrapbytes('a'),self.space.wrapbytes('b'),self.space.wrapbytes('c')]) assert isinstance(l.strategy, BytesListStrategy) l.append(self.space.wrapbytes('d')) assert isinstance(l.strategy, BytesListStrategy) l.append(self.space.wrap(3)) assert isinstance(l.strategy, ObjectListStrategy)
def test_empty_setslice_with_objectlist(self): space = self.space w = space.wrap l = W_ListObject(space, []) o = W_ListObject(space, [space.wrap(1), space.wrap("2"), space.wrap(3)]) l.setslice(0, 1, o.length(), o) assert l.getitems() == o.getitems() l.append(space.wrap(17)) assert l.getitems() != o.getitems()
def test_int_or_float_from_float(self): space = self.space w = space.wrap w_l = W_ListObject(space, [space.wrap(-42.5)]) assert isinstance(w_l.strategy, FloatListStrategy) w_l.append(w(-15)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) assert space.float_w(w_l.getitem(0)) == -42.5 assert space.int_w(w_l.getitem(1)) == -15 assert space.len_w(w_l) == 2
def test_int_or_float_from_integer(self): space = self.space w = space.wrap w_l = W_ListObject(space, [space.wrap(int(-2**31))]) assert isinstance(w_l.strategy, IntegerListStrategy) w_l.append(w(-5.1)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) assert space.int_w(w_l.getitem(0)) == -2**31 assert space.float_w(w_l.getitem(1)) == -5.1 assert space.len_w(w_l) == 2
def test_int_or_float_from_float_special_nan(self): from rpython.rlib import longlong2float, rarithmetic space = self.space w = space.wrap ll = rarithmetic.r_longlong(0xfffffffe12345678 - 2**64) specialnan = longlong2float.longlong2float(ll) w_l = W_ListObject(space, [space.wrap(specialnan)]) assert isinstance(w_l.strategy, FloatListStrategy) w_l.append(w(42)) assert isinstance(w_l.strategy, ObjectListStrategy) assert space.int_w(w_l.getitem(1)) == 42 assert space.len_w(w_l) == 2
def test_int_or_float_from_float_int_overflow(self): if sys.maxint == 2147483647: py.test.skip("only on 64-bit") space = self.space w = space.wrap ovf1 = 2 ** 31 w_l = W_ListObject(space, [space.wrap(1.2)]) assert isinstance(w_l.strategy, FloatListStrategy) w_l.append(w(ovf1)) assert isinstance(w_l.strategy, ObjectListStrategy) assert space.float_w(w_l.getitem(0)) == 1.2 assert space.int_w(w_l.getitem(1)) == ovf1 assert space.len_w(w_l) == 2
def test_empty_to_any(self): l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap((1,3))) assert isinstance(l.strategy, ObjectListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap(1)) assert isinstance(l.strategy, IntegerListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap('a')) assert isinstance(l.strategy, StringListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap(1.2)) assert isinstance(l.strategy, FloatListStrategy)
def test_empty_to_any(self): l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap((1, 3))) assert isinstance(l.strategy, ObjectListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap(1)) assert isinstance(l.strategy, IntegerListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap('a')) assert isinstance(l.strategy, StringListStrategy) l = W_ListObject(self.space, []) assert isinstance(l.strategy, EmptyListStrategy) l.append(self.space.wrap(1.2)) assert isinstance(l.strategy, FloatListStrategy)
def test_int_or_float_base(self): from rpython.rlib.rfloat import INFINITY, NAN space = self.space w = space.wrap w_l = W_ListObject(space, [space.wrap(1), space.wrap(2.3)]) assert isinstance(w_l.strategy, IntOrFloatListStrategy) w_l.append(w(int(2**31-1))) assert isinstance(w_l.strategy, IntOrFloatListStrategy) w_l.append(w(-5.1)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) assert space.int_w(w_l.getitem(2)) == 2**31-1 assert space.float_w(w_l.getitem(3)) == -5.1 w_l.append(w(INFINITY)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) w_l.append(w(NAN)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) w_l.append(w(-NAN)) assert isinstance(w_l.strategy, IntOrFloatListStrategy) w_l.append(space.newlist([])) assert isinstance(w_l.strategy, ObjectListStrategy)