Skip to content

Commit 1b275a2

Browse files
committed
try again to run the pow tests at least on graalpython
1 parent 9875643 commit 1b275a2

File tree

2 files changed

+122
-75
lines changed

2 files changed

+122
-75
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import sys
41+
42+
43+
def test_pow():
44+
if sys.implementation.name == "graalpython":
45+
try:
46+
2 ** (2**128)
47+
except ArithmeticError:
48+
assert True
49+
else:
50+
assert False
51+
52+
assert 2 ** -(2**128) == 0.0
53+
54+
class X(float):
55+
def __rpow__(self, other):
56+
return 42
57+
58+
assert 2 ** X() == 42
59+
60+
try:
61+
2.0 .__pow__(2, 2)
62+
except TypeError as e:
63+
assert True
64+
else:
65+
assert False
66+
67+
try:
68+
2.0 .__pow__(2.0, 2.0)
69+
except TypeError as e:
70+
assert True
71+
else:
72+
assert False
73+
74+
assert 2 ** 2.0 == 4.0
75+
76+
assert 2 .__pow__("a") == NotImplemented
77+
assert 2 .__pow__("a", 2) == NotImplemented
78+
assert 2 .__pow__(2**30, 2**128) == 0
79+
80+
# crafted to try specializations
81+
def mypow(a, b, c):
82+
return a.__pow__(b, c)
83+
84+
values = [
85+
[1, 2, None, 1], # long
86+
[1, 128, None, 1], # BigInteger
87+
[1, -2, None, 1.0], # double result
88+
[1, 0xffffffffffffffffffffffffffffffff & 0x80, None, 1], # narrow to long
89+
[2, 0xffffffffffffffffffffffffffffffff & 0x80, None, 340282366920938463463374607431768211456], # cannot narrow
90+
[2, -(0xffffffffffffffffffffffffffffffff & 0x80), None, 2.938735877055719e-39], # double result
91+
[2**128, 0, None, 1], # narrow to long
92+
[2**128, 1, None, 340282366920938463463374607431768211456], # cannot narrow
93+
[2**128, -2, None, 8.636168555094445e-78], # double
94+
[2**128, 0xffffffffffffffffffffffffffffffff & 0x2, None, 115792089237316195423570985008687907853269984665640564039457584007913129639936], # large
95+
[2**128, -(0xffffffffffffffffffffffffffffffff & 0x8), None, 5.562684646268003e-309], # double result
96+
[1, 2, 3, 1], # fast path
97+
[2, 2**30, 2**128, 0], # generic
98+
] + []
99+
100+
if sys.version_info.minor >= 8:
101+
values += [
102+
[1, -2, 3, 1], # fast path double
103+
[1, 2, -3, -2], # negative mod
104+
[1, -2, -3, -2], # negative mod and negative right
105+
[1, -2**128, 3, 1], # mod and large negative right
106+
[1, -2**128, -3, -2], # negative mod and large negative right
107+
[1, -2**128, -2**64, -18446744073709551615], # large negative mod and large negative right
108+
]
109+
110+
for args in values:
111+
assert mypow(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
112+
113+
def mypow_rev(a, b, c):
114+
return a.__pow__(b, c)
115+
116+
for args in reversed(values):
117+
assert mypow_rev(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
118+
119+
assert 2**1.0 == 2.0

graalpython/com.oracle.graal.python.test/src/tests/test_binary_arithmetic.py

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -300,78 +300,6 @@ def test_pow():
300300
assert 2**(0xffffffffffffffff >> 63) == 2
301301

302302
if sys.implementation.name == "graalpython":
303-
try:
304-
2 ** (2**128)
305-
except ArithmeticError:
306-
assert True
307-
else:
308-
assert False
309-
310-
assert 2 ** -(2**128) == 0.0
311-
312-
class X(float):
313-
def __rpow__(self, other):
314-
return 42
315-
316-
assert 2 ** X() == 42
317-
318-
try:
319-
2.0 .__pow__(2, 2)
320-
except TypeError as e:
321-
assert True
322-
else:
323-
assert False
324-
325-
try:
326-
2.0 .__pow__(2.0, 2.0)
327-
except TypeError as e:
328-
assert True
329-
else:
330-
assert False
331-
332-
assert 2 ** 2.0 == 4.0
333-
334-
assert 2 .__pow__("a") == NotImplemented
335-
assert 2 .__pow__("a", 2) == NotImplemented
336-
assert 2 .__pow__(2**30, 2**128) == 0
337-
338-
# crafted to try specializations
339-
def mypow(a, b, c):
340-
return a.__pow__(b, c)
341-
342-
values = [
343-
[1, 2, None, 1], # long
344-
[1, 128, None, 1], # BigInteger
345-
[1, -2, None, 1.0], # double result
346-
[1, 0xffffffffffffffffffffffffffffffff & 0x80, None, 1], # narrow to long
347-
[2, 0xffffffffffffffffffffffffffffffff & 0x80, None, 340282366920938463463374607431768211456], # cannot narrow
348-
[2, -(0xffffffffffffffffffffffffffffffff & 0x80), None, 2.938735877055719e-39], # double result
349-
[2**128, 0, None, 1], # narrow to long
350-
[2**128, 1, None, 340282366920938463463374607431768211456], # cannot narrow
351-
[2**128, -2, None, 8.636168555094445e-78], # double
352-
[2**128, 0xffffffffffffffffffffffffffffffff & 0x2, None, 115792089237316195423570985008687907853269984665640564039457584007913129639936], # large
353-
[2**128, -(0xffffffffffffffffffffffffffffffff & 0x8), None, 5.562684646268003e-309], # double result
354-
[1, 2, 3, 1], # fast path
355-
[2, 2**30, 2**128, 0], # generic
356-
] + []
357-
358-
if sys.version_info.minor >= 8:
359-
values += [
360-
[1, -2, 3, 1], # fast path double
361-
[1, 2, -3, -2], # negative mod
362-
[1, -2, -3, -2], # negative mod and negative right
363-
[1, -2**128, 3, 1], # mod and large negative right
364-
[1, -2**128, -3, -2], # negative mod and large negative right
365-
[1, -2**128, -2**64, -18446744073709551615], # large negative mod and large negative right
366-
]
367-
368-
for args in values:
369-
assert mypow(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
370-
371-
def mypow_rev(a, b, c):
372-
return a.__pow__(b, c)
373-
374-
for args in reversed(values):
375-
assert mypow_rev(*args[:-1]) == args[-1], "%r -> %r == %r" % (args, mypow(*args[:-1]), args[-1])
376-
377-
assert 2**1.0 == 2.0
303+
# for some reason this hangs CPython on the CI even if it's just parsed
304+
from pow_tests import test_pow
305+
test_pow()

0 commit comments

Comments
 (0)