Lines Matching refs:cast
108 x = cast(p, -65 + 17*256)
112 x = cast(p, -66 + (1<<199)*256)
115 assert (x == cast(p, -66)) is True
116 assert (x != cast(p, -66)) is False
118 assert (x == cast(q, -66)) is True
119 assert (x != cast(q, -66)) is False
132 assert int(cast(p, min)) == min
133 assert int(cast(p, max)) == max
134 assert int(cast(p, min - 1)) == max
135 assert int(cast(p, max + 1)) == min
136 py.test.raises(TypeError, cast, p, None)
137 assert long(cast(p, min - 1)) == max
138 assert int(cast(p, b'\x08')) == 8
139 assert int(cast(p, u+'\x08')) == 8
144 assert int(cast(p, 0)) == 0
145 assert int(cast(p, max)) == max
146 assert int(cast(p, -1)) == max
147 assert int(cast(p, max + 1)) == 0
148 assert long(cast(p, -1)) == max
149 assert int(cast(p, b'\xFE')) == 254
150 assert int(cast(p, u+'\xFE')) == 254
154 py.test.raises(TypeError, float, cast(p, 42))
155 py.test.raises(TypeError, complex, cast(p, 42))
161 assert bool(cast(p, 0)) is False # since 1.7
162 assert bool(cast(p, -0.0)) is False # since 1.7
163 assert bool(cast(p, 1e-42)) is True
164 assert bool(cast(p, -1e-42)) is True
165 assert bool(cast(p, INF))
166 assert bool(cast(p, -INF))
167 assert bool(cast(p, float("nan")))
168 assert int(cast(p, -150)) == -150
169 assert int(cast(p, 61.91)) == 61
170 assert long(cast(p, 61.91)) == 61
171 assert type(int(cast(p, 61.91))) is int
172 assert type(int(cast(p, 1E22))) is long
173 assert type(long(cast(p, 61.91))) is long
174 assert type(long(cast(p, 1E22))) is long
175 py.test.raises(OverflowError, int, cast(p, INF))
176 py.test.raises(OverflowError, int, cast(p, -INF))
177 assert float(cast(p, 1.25)) == 1.25
178 assert float(cast(p, INF)) == INF
179 assert float(cast(p, -INF)) == -INF
181 assert float(cast(p, 1.1)) != 1.1 # rounding error
182 assert float(cast(p, 1E200)) == INF # limited range
184 assert cast(p, -1.1) == cast(p, -1.1)
185 assert repr(float(cast(p, -0.0))) == '-0.0'
186 assert float(cast(p, b'\x09')) == 9.0
187 assert float(cast(p, u+'\x09')) == 9.0
188 assert float(cast(p, True)) == 1.0
189 py.test.raises(TypeError, cast, p, None)
195 assert bool(cast(p, 0)) is False
196 assert bool(cast(p, INF))
197 assert bool(cast(p, -INF))
198 assert bool(cast(p, 0j)) is False
199 assert bool(cast(p, INF*1j))
200 assert bool(cast(p, -INF*1j))
202 py.test.raises(TypeError, int, cast(p, -150))
203 py.test.raises(TypeError, long, cast(p, -150))
204 py.test.raises(TypeError, float, cast(p, -150))
205 assert complex(cast(p, 1.25)) == 1.25
206 assert complex(cast(p, 1.25j)) == 1.25j
207 assert complex(cast(p, complex(0,INF))) == complex(0,INF)
208 assert complex(cast(p, -INF)) == -INF
210 assert complex(cast(p, 1.1j)) != 1.1j # rounding error
211 assert complex(cast(p, 1E200+3j)) == INF+3j # limited range
212 assert complex(cast(p, complex(3,1E200))) == complex(3,INF) # limited range
214 assert cast(p, -1.1j) == cast(p, -1.1j)
215 assert repr(complex(cast(p, -0.0)).real) == '-0.0'
217 assert complex(cast(p, b'\x09')) == 9.0 + 0j
218 assert complex(cast(p, u+'\x09')) == 9.0 + 0j
219 assert complex(cast(p, True)) == 1.0 + 0j
220 py.test.raises(TypeError, cast, p, None)
222 py.test.raises(TypeError, cast, new_primitive_type(name), 1+0j)
226 baseobj = cast(new_primitive_type(basetype), 65)
240 assert complex(cast(p, Foo())) == 2 + 3j
241 py.test.raises(TypeError, cast, new_primitive_type("int"), 1+0j)
245 assert bool(cast(p, 'A')) is True
246 assert bool(cast(p, '\x00')) is False # since 1.7
247 assert cast(p, '\x00') == cast(p, -17*256)
248 assert int(cast(p, 'A')) == 65
249 assert long(cast(p, 'A')) == 65
250 assert type(int(cast(p, 'A'))) is int
251 assert type(long(cast(p, 'A'))) is long
252 assert str(cast(p, 'A')) == repr(cast(p, 'A'))
253 assert repr(cast(p, 'A')) == "<cdata 'char' %s'A'>" % mandatory_b_prefix
254 assert repr(cast(p, 255)) == r"<cdata 'char' %s'\xff'>" % mandatory_b_prefix
255 assert repr(cast(p, 0)) == r"<cdata 'char' %s'\x00'>" % mandatory_b_prefix
288 q = cast(BPtr, p)
299 p = cast(BPtr, 0)
301 p = cast(BPtr, 42)
336 assert int(cast(p, 4.2)) == 4
381 c = cast(BChar, b'A')
384 py.test.raises(TypeError, cast, BChar, b'foo')
385 py.test.raises(TypeError, cast, BChar, u+'foo')
400 assert p[0] == cast(BVoidP, 0)
401 assert p[0] == cast(BCharP, 0)
405 assert p[0] != cast(BVoidP, 0)
406 assert p[0] != cast(BCharP, 0)
432 py.test.raises(TypeError, len, cast(p, 42))
436 x = cast(p, 42)
441 y = cast(p, 0)
446 x = cast(p, 42)
451 x = cast(BChar, 42)
454 x = cast(BInt, 42)
462 x = cast(BInt, 42)
470 x = cast(BInt, 0)
471 y = cast(new_pointer_type(BInt), x)
474 x = cast(BInt, 42)
475 y = cast(BInt, x)
477 y = cast(new_primitive_type("char"), x)
479 y = cast(new_primitive_type("float"), x)
482 z = cast(BInt, 42.5)
484 z = cast(BInt, y)
621 a = cast(BIntPtr, 1240)
623 b = cast(BIntPtr, bi)
633 n = cast(p, cast(p, -42))
637 n = cast(p, cast(p, 42))
641 n = cast(p, cast(p, -(1<<60)))
645 n = cast(p, cast(p, 1<<63))
649 n = cast(p, cast(p, 42.5))
653 n = cast(p, cast(p, "A"))
659 n = newp(p1, cast(p, -42))
664 n = newp(p1, cast(p, 42))
669 n = newp(p1, cast(p, 42.5))
674 n = newp(p1, cast(p, "A"))
682 b = cast(BShortP, a)
683 c = cast(BIntP, b)
686 d = cast(BLongLong, c)
687 e = cast(BIntP, d)
689 f = cast(BIntP, int(d))
692 b = cast(BShortP, 0)
694 c = cast(BIntP, b)
696 assert int(cast(BLongLong, c)) == 0
779 p = cast(BStructPtr, 42)
805 j = cast(BInt, 42)
810 j = cast(new_pointer_type(BInt), 42)
864 assert s.p4 == cast(BVoidP, 0)
871 assert s.p4 == cast(BVoidP, 0)
880 s = newp(BStructPtr, [12, 34, 56, cast(BVoidP, 0)])
881 assert s.p4 == cast(BVoidP, 0)
948 f = cast(BFunc0, _testfunc(0))
958 f = cast(BFunc0, _testfunc(0))
967 f = cast(BFunc1, _testfunc(1))
980 f = cast(BFunc2, _testfunc(2))
989 f = cast(BFunc3, _testfunc(3))
998 f = cast(BFunc4, _testfunc(4))
1005 f = cast(BFunc5, _testfunc(5))
1012 f = cast(BFunc6, _testfunc(6))
1020 f = cast(BFunc6bis, _testfunc(6))
1047 f = cast(BFunc7, _testfunc(7))
1063 f = cast(BFunc20, _testfunc(20))
1082 f = cast(BFunc21, _testfunc(21))
1094 f = cast(BFunc22, _testfunc(22))
1106 f = cast(BFunc23, _testfunc(23))
1109 res = f(cast(BVoidP, 0)) # NULL
1121 f = cast(BFunc23, _testfunc(23))
1131 f = cast(BFunc23, _testfunc(23))
1143 py.test.raises(NotImplementedError, cast(BFunc, 123), cast(BStructP, 123))
1145 py.test.raises(NotImplementedError, cast(BFunc2, 123), 123)
1150 f = cast(BFunc9, _testfunc(9))
1152 assert f(1, cast(BInt, 42)) == 42
1153 assert f(2, cast(BInt, 40), cast(BInt, 2)) == 42
1160 assert f(3, cast(BSChar, -3), cast(BUChar, 200), cast(BSShort, -5)) == 192
1167 f = cast(BFunc3, _testfunc(24))
1173 f = cast(BFunc3, _testfunc(9))
1181 f = cast(BFunc3, _testfunc(25))
1187 f = cast(BFunc3, _testfunc(9))
1199 dummy_func = cast(BFunc, 42)
1233 assert strlenaddr == cast(BVoidP, strlen)
1243 assert stderr == cast(BVoidP, _testfunc(8))
1268 ll.write_variable(BVoidP, "stderr", cast(BVoidP, 0))
1595 e = cast(BEnum, 0)
1597 assert repr(cast(BEnum, -42)) == "<cdata 'enum foo' -42>"
1598 assert repr(cast(BEnum, -20)) == "<cdata 'enum foo' -20: ab>"
1600 assert string(cast(BEnum, -20)) == 'ab'
1601 assert int(cast(BEnum, 1)) == 1
1602 assert int(cast(BEnum, 0)) == 0
1603 assert int(cast(BEnum, -242 + 2**128)) == -242
1604 assert string(cast(BEnum, -242 + 2**128)) == '-242'
1608 e = cast(BEnum, -1)
1614 e = cast(BEnum, -1)
1620 e = cast(BEnum, 7)
1642 assert string(cast(BEnum2, 5)) == 'abc'
1643 assert type(string(cast(BEnum2, 5))) is str
1656 if int(cast(BPrimitive, testcase)) == testcase:
1660 assert int(cast(BEnum, testcase)) == testcase
1671 return cast(BEnum, n)
1688 return cast(BEnum, n)
1809 _weakref.ref(cast(BPtr, 42)),
1810 _weakref.ref(cast(BInt, 42)),
1826 x = cast(BInt, 42)
1850 x = cast(new_primitive_type("int"), 42)
1877 py.test.raises(TypeError, cast, BFloat, newp(BArray, None))
1889 p = newp(new_pointer_type(BInt), cast(BInt, 42))
1893 p = newp(new_pointer_type(BUInt), cast(BUInt, 42))
1897 p = newp(new_pointer_type(BChar), cast(BChar, '!'))
1901 p = newp(new_pointer_type(BFloat), cast(BFloat, 12.25))
1931 p1 = cast(BFunc, 42)
1937 assert string(cast(BChar, 42)) == b'*'
1938 assert string(cast(BChar, 0)) == b'\x00'
1947 py.test.raises(RuntimeError, string, cast(BCharP, 0))
1954 assert string(cast(BByte, 42)) == b'*'
1955 assert string(cast(BByte, 0)) == b'\x00'
1961 assert string(cast(BByte, 42)) == b'*'
1962 assert string(cast(BByte, 0)) == b'\x00'
1975 assert string(cast(BWChar, 42)) == u+'*'
1976 assert string(cast(BWChar, 0x4253)) == u+'\u4253'
1977 assert string(cast(BWChar, 0)) == u+'\x00'
1998 x = cast(BDouble, 42)
2025 py.test.raises(NotImplementedError, cast(BFunc, 123))
2038 f = cast(BFunc10, _testfunc(10))
2048 f = cast(BFunc11, _testfunc(11))
2058 f = cast(BFunc12, _testfunc(12))
2068 f = cast(BFunc13, _testfunc(13))
2079 f = cast(BFunc14, _testfunc(14))
2088 f = cast(BFunc15, _testfunc(15))
2098 f = cast(BFunc16, _testfunc(16))
2108 f = cast(BFunc17, _testfunc(17))
2116 f = cast(BFunc18, _testfunc(18))
2130 newp(BStructPtr, [cast(BFunc, 0)])
2131 newp(BStructPtr, [cast(BCharP, 0)])
2132 py.test.raises(TypeError, newp, BStructPtr, [cast(BIntP, 0)])
2133 py.test.raises(TypeError, newp, BStructPtr, [cast(BFunc2, 0)])
2141 assert int(cast(BWChar, -1)) in (-1, 4294967295)
2147 assert int(cast(BChar16, -1)) == 0xffff # always unsigned
2153 assert int(cast(BChar32, -1)) == 0xffffffff # always unsigned
2160 assert str(cast(BWChar, 0x45)) == "<cdata '%s' %s'E'>" % (
2162 assert str(cast(BWChar, 0x1234)) == "<cdata '%s' %s'\u1234'>" % (
2166 x = cast(BWChar, 0x12345)
2171 x = cast(BWChar, 0x18345)
2194 s.a1 = cast(BWChar, 0x12345)
2225 w = cast(BWChar, 'a')
2230 w = cast(BWChar, 0x1234)
2235 w = cast(BWChar, u+'\u8234')
2240 w = cast(BInt, u+'\u1234')
2243 w = cast(BWChar, u+'\U00012345')
2249 w = cast(BInt, u+'\U00012345')
2251 py.test.raises(TypeError, cast, BInt, u+'')
2252 py.test.raises(TypeError, cast, BInt, u+'XX')
2253 assert int(cast(BInt, u+'a')) == ord('a')
2256 p = cast(BWCharP, a)
2267 q = cast(BWCharP, 0)
2280 x = cast(BWChar, 1114112)
2282 x = cast(BWChar, -1)
2289 assert int(cast(BChar32, cast(BChar16, -2))) == 0xfffe
2290 assert int(cast(BWChar, cast(BChar16, -2))) == 0xfffe
2291 assert int(cast(BChar16, cast(BChar32, 0x0001f345))) == 0xf345
2292 assert int(cast(BChar16, cast(BWChar, 0x0001f345))) == 0xf345
2296 x = cast(BChar32, 'A')
2298 x = cast(BChar16, 'A')
2321 r = cast(BStructPtr, p)
2354 p = cast(BVoidP, 123456)
2356 p = cast(BVoidP, 0)
2366 py.test.raises(TypeError, iter, cast(BInt, 5))
2367 py.test.raises(TypeError, iter, cast(BIntP, 123456))
2374 q = cast(BInt, 124)
2386 r = cast(BVoidP, p)
2494 f = cast(BFunc5, _testfunc(5))
2521 x = cast(BArray, 0)
2527 p = cast(new_pointer_type(BStruct), 123456)
2529 py.test.raises(TypeError, cast, BStruct, s)
2595 x = newp(BIntPtr, cast(BInt, 42))
2597 x = newp(BIntPtr, cast(BLongLong, 42))
2599 x = newp(BIntPtr, cast(BULongLong, 42))
2601 x = newp(BULongLongPtr, cast(BInt, 42))
2603 py.test.raises(OverflowError, newp, BULongLongPtr, cast(BInt, -42))
2604 x = cast(BInt, cast(BInt, 42))
2606 x = cast(BInt, cast(BLongLong, 42))
2608 x = cast(BInt, cast(BULongLong, 42))
2610 x = cast(BULongLong, cast(BInt, 42))
2612 x = cast(BULongLong, cast(BInt, -42))
2614 x = cast(BIntPtr, cast(BInt, 42))
2615 assert int(cast(BInt, x)) == 42
2621 x = newp(BFloatPtr, cast(BDouble, 12.5))
2623 x = cast(BFloat, cast(BDouble, 12.5))
2647 f = cast(BFunc19, _testfunc(19))
2754 nullchr = cast(BChar, 0)
2769 py.test.raises(TypeError, newp, BIntP, cast(BFloat, 0.0))
2770 py.test.raises(TypeError, newp, BUIntP, cast(BFloat, 0.0))
2775 assert int(cast(BBool, False)) == 0
2776 assert int(cast(BBool, True)) == 1
2777 assert bool(cast(BBool, False)) is False # since 1.7
2778 assert bool(cast(BBool, True)) is True
2779 assert int(cast(BBool, 3)) == 1
2780 assert int(cast(BBool, long(3))) == 1
2781 assert int(cast(BBool, long(10)**4000)) == 1
2782 assert int(cast(BBool, -0.1)) == 1
2783 assert int(cast(BBool, -0.0)) == 0
2784 assert int(cast(BBool, '\x00')) == 0
2785 assert int(cast(BBool, '\xff')) == 1
2796 q = cast(BBoolP, p)
2799 q = cast(BBoolP, p)
2801 py.test.raises(TypeError, string, cast(BBool, False))
2803 assert int(cast(BBool, cast(BDouble, 0.1))) == 1
2804 assert int(cast(BBool, cast(BDouble, 0.0))) == 0
2816 q = cast(BBoolP, p)
2885 assert b == cast(BCharP, p)
2888 py.test.raises(TypeError, rawaddressof, BStructPtr, cast(BChar, '?'), 0)
2891 assert d == cast(BCharP, p) + 1
2893 e = cast(BCharP, 109238)
3021 fw1p = cast(BFILEP, fw1)
3189 x = cast(p, 17)
3197 x = cast(BVoidP, 12345)
3198 assert x == cast(BIntP, 12345)
3199 assert x != cast(BIntP, 12344)
3200 assert hash(x) == hash(cast(BIntP, 12345))
3213 assert from_handle(cast(BCharP, x)) is o
3219 assert from_handle(cast(BCharP, x)) == list((2, 3, 4))
3225 py.test.raises(RuntimeError, from_handle, cast(BCharP, 0))
3376 assert p.y == cast(BIntP, p) + 1
3420 q = cast(new_pointer_type(BStruct), p)
3545 p = cast(new_pointer_type(BVoid), 100000)
3546 assert int(cast(BInt, p)) == 100000
3547 assert int(cast(BInt, p + 42)) == 100042
3548 assert int(cast(BInt, p - (-42))) == 100042
3550 q = cast(new_pointer_type(new_primitive_type("char")), 100000)
3634 cast(p, c)[1] += 500
3812 assert cast(BIntP, p1) == from_buffer(BIntA, bytestring)
3882 p = cast(BInt, 42)
3889 p = cast(BIntPtr, 0)
3975 py.test.raises(TypeError, unpack, cast(BInt, 42), 1)
3978 random_ptr = cast(BPtr, -424344)
3979 other_ptr = cast(BPtr, 54321)
3993 e = py.test.raises(ValueError, unpack, cast(BStructPtr, 42), 5)
4002 py.test.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 0)
4003 py.test.raises(RuntimeError, unpack, cast(new_pointer_type(BChar), 0), 10)
4010 p = cast(BInt, 42)
4015 p = cast(new_pointer_type(BStruct), 0)
4036 z1 = cast(BCharP, 0)
4037 z2 = cast(BIntP, 0)
4038 z3 = cast(BVoidP, 0)
4039 z4 = cast(BUCharP, 0)
4123 assert_eq(cast(t1, 65), b'A')
4124 assert_lt(cast(t1, 64), b'\x99')
4125 assert_gt(cast(t1, 200), b'A')
4126 assert_ne(cast(t1, 65), 65)
4127 assert_eq(cast(t2, -25), -25)
4128 assert_lt(cast(t2, -25), -24)
4129 assert_gt(cast(t2, -25), -26)
4130 assert_eq(cast(t3, 65), 65)
4131 assert_ne(cast(t3, 65), b'A')
4132 assert_ne(cast(t3, 65), cast(t1, 65))
4133 assert_gt(cast(t4, -1), -1, check_hash=False)
4134 assert_gt(cast(t4, -1), cast(t2, -1), check_hash=False)
4135 assert_gt(cast(t4, -1), 99999)
4136 assert_eq(cast(t4, -1), 256 ** size_of_int() - 1)
4137 assert_eq(cast(t5, 3.0), 3)
4138 assert_eq(cast(t5, 3.5), 3.5)
4139 assert_lt(cast(t5, 3.3), 3.3) # imperfect rounding
4140 assert_eq(cast(t6, 3.3), 3.3)
4141 assert_eq(cast(t5, 3.5), cast(t6, 3.5))
4142 assert_lt(cast(t5, 3.1), cast(t6, 3.1)) # imperfect rounding
4143 assert_eq(cast(t5, 7.0), cast(t3, 7))
4144 assert_lt(cast(t5, 3.1), 3.101)
4145 assert_gt(cast(t5, 3.1), 3)
4163 assert pstruct.p == cast(BIntP, 0)
4178 p = cast(BIntP, 12345)
4189 p = cast(BIntP, 12345)
4197 p1 = cast(BIntP, intp1)
4210 p1 = cast(BIntP, intp1)