Skip to content
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

gh-103553: Improve test_inspect: add more assertions, remove unused #103554

Merged
merged 1 commit into from
Apr 15, 2023
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
24 changes: 9 additions & 15 deletions Lib/test/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,8 +1820,7 @@ def test_errors(self):
self.assertEqualException(f, '2, 3, 4')
self.assertEqualException(f, '1, 2, 3, a=1')
self.assertEqualException(f, '2, 3, 4, c=5')
# XXX: success of this one depends on dict order
## self.assertEqualException(f, '2, 3, 4, a=1, c=5')
self.assertEqualException(f, '2, 3, 4, a=1, c=5')
# f got an unexpected keyword argument
self.assertEqualException(f, 'c=2')
self.assertEqualException(f, '2, c=3')
Expand All @@ -1832,17 +1831,19 @@ def test_errors(self):
self.assertEqualException(f, '1, a=2')
self.assertEqualException(f, '1, **{"a":2}')
self.assertEqualException(f, '1, 2, b=3')
# XXX: Python inconsistency
# - for functions and bound methods: unexpected keyword 'c'
# - for unbound methods: multiple values for keyword 'a'
#self.assertEqualException(f, '1, c=3, a=2')
self.assertEqualException(f, '1, c=3, a=2')
# issue11256:
f3 = self.makeCallable('**c')
self.assertEqualException(f3, '1, 2')
self.assertEqualException(f3, '1, 2, a=1, b=2')
f4 = self.makeCallable('*, a, b=0')
self.assertEqualException(f3, '1, 2')
self.assertEqualException(f3, '1, 2, a=1, b=2')
self.assertEqualException(f4, '1, 2')
self.assertEqualException(f4, '1, 2, a=1, b=2')
self.assertEqualException(f4, 'a=1, a=3')
self.assertEqualException(f4, 'a=1, c=3')
self.assertEqualException(f4, 'a=1, a=3, b=4')
self.assertEqualException(f4, 'a=1, b=2, a=3, b=4')
self.assertEqualException(f4, 'a=1, a=2, a=3, b=4')

# issue #20816: getcallargs() fails to iterate over non-existent
# kwonlydefaults and raises a wrong TypeError
Expand Down Expand Up @@ -2872,8 +2873,6 @@ def foo(cls, *, arg):
def test_signature_on_partial(self):
from functools import partial

Parameter = inspect.Parameter

def test():
pass

Expand Down Expand Up @@ -2988,8 +2987,6 @@ def test(a, b, c:int) -> 42:
((('c', ..., int, "positional_or_keyword"),),
42))

psig = inspect.signature(partial(partial(test, 1), 2))

def foo(a):
return a
_foo = partial(partial(foo, a=10), a=20)
Expand Down Expand Up @@ -4153,8 +4150,6 @@ def test(a, *args, b, z=100, **kwargs):
self.assertEqual(ba.args, (10, 20))

def test_signature_bind_positional_only(self):
P = inspect.Parameter

def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
return a_po, b_po, c_po, foo, bar, kwargs

Expand Down Expand Up @@ -4578,7 +4573,6 @@ def test_qualname_source(self):
self.assertEqual(err, b'')

def test_builtins(self):
module = importlib.import_module('unittest')
_, out, err = assert_python_failure('-m', 'inspect',
'sys')
lines = err.decode().splitlines()
Expand Down