Skip to content

Merge some pythoneval tests to speed them up #17990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 68 additions & 109 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,138 +11,97 @@ print('hello, world')
[out]
hello, world

[case testReversed]
[case testMiscStdlibFeatures]
# Various legacy tests merged together to speed up test runtimes.

def f(x: object) -> None: pass

# testReversed
from typing import Reversible
class A(Reversible):
class R(Reversible):
def __iter__(self): return iter('oof')
def __reversed__(self): return iter('foo')
print(list(reversed(range(5))))
print(list(reversed([1,2,3])))
print(list(reversed('abc')))
print(list(reversed(A())))
[out]
-- Escape bracket at line beginning
\[4, 3, 2, 1, 0]
\[3, 2, 1]
\['c', 'b', 'a']
\['f', 'o', 'o']

[case testIntAndFloatConversion]
f(list(reversed(range(5))))
f(list(reversed([1,2,3])))
f(list(reversed('abc')))
f(list(reversed(R())))

# testIntAndFloatConversion
from typing import SupportsInt, SupportsFloat
class A(SupportsInt):
def __int__(self): return 5
class B(SupportsFloat):
def __float__(self): return 1.2
print(int(1))
print(int(6.2))
print(int('3'))
print(int(b'4'))
print(int(A()))
print(float(-9))
print(float(B()))
[out]
1
6
3
4
5
-9.0
1.2

[case testAbs]
f(int(1))
f(int(6.2))
f(int('3'))
f(int(b'4'))
f(int(A()))
f(float(-9))
f(float(B()))

# testAbs
from typing import SupportsAbs
class A(SupportsAbs[float]):
class Ab(SupportsAbs[float]):
def __abs__(self) -> float: return 5.5

print(abs(-1))
print(abs(-1.2))
print(abs(A()))
[out]
1
1.2
5.5

[case testAbs2]
n: int
f: float
n = abs(1)
abs(1) + 'x' # Error
f = abs(1.1)
abs(1.1) + 'x' # Error
[out]
_program.py:4: error: Unsupported operand types for + ("int" and "str")
_program.py:6: error: Unsupported operand types for + ("float" and "str")
f(abs(-1))
f(abs(-1.2))
f(abs(Ab()))

[case testRound]
# testRound
from typing import SupportsRound
class A(SupportsRound):
class Ro(SupportsRound):
def __round__(self, ndigits=0): return 'x%d' % ndigits
print(round(1.6))
print(round(A()))
print(round(A(), 2))
[out]
2
x0
x2
f(round(1.6))
f(round(Ro()))
f(round(Ro(), 2))

[case testCallMethodViaTypeObject]
import typing
print(list.__add__([1, 2], [3, 4]))
[out]
\[1, 2, 3, 4]
# testCallMethodViaTypeObject
list.__add__([1, 2], [3, 4])

[case testInheritedClassAttribute]
# testInheritedClassAttribute
import typing
class A:
class AA:
x = 1
def f(self: typing.Optional["A"]) -> None: print('f')
class B(A):
def f(self: typing.Optional["AA"]) -> None: pass
class BB(AA):
pass
B.f(None)
print(B.x)
[out]
f
1

[case testModuleAttributes]
import math
import typing
print(type(__spec__))
print(math.__name__)
print(math.__spec__.name)
print(type(math.__dict__))
print(type(math.__doc__ or ''))
print(type(math.__spec__).__name__)
print(math.__class__)
[out]
<class 'NoneType'>
math
math
<class 'dict'>
<class 'str'>
ModuleSpec
<class 'module'>
BB.f(None)
f(BB.x)

[case testSpecialAttributes]
import typing
class A:
# testSpecialAttributes
class Doc:
"""A docstring!"""
print(A().__doc__)
print(A().__class__)
[out]
A docstring!
<class '__main__.A'>
f(Doc().__doc__)
f(Doc().__class__)

[case testFunctionAttributes]
import typing
ord.__class__
print(type(ord.__doc__ or '' + ''))
print(ord.__name__)
print(ord.__module__)
# testFunctionAttributes
f(ord.__class__)
f(type(ord.__doc__ or '' + ''))
f(ord.__name__)
f(ord.__module__)

# testModuleAttributes
import math
f(type(__spec__))
f(math.__name__)
f(math.__spec__.name)
f(type(math.__dict__))
f(type(math.__doc__ or ''))
f(type(math.__spec__).__name__)
f(math.__class__)

[case testAbs2]
n: int
f: float
n = abs(1)
abs(1) + 'x' # Error
f = abs(1.1)
abs(1.1) + 'x' # Error
[out]
<class 'str'>
ord
builtins
_program.py:4: error: Unsupported operand types for + ("int" and "str")
_program.py:6: error: Unsupported operand types for + ("float" and "str")

[case testTypeAttributes]
import typing
Expand Down
Loading