Skip to content

Commit 9f3f109

Browse files
gh-103553: Improve test_inspect: add more assertions, remove unused (GH-103554)
(cherry picked from commit 4fe1c4b) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent a3242c7 commit 9f3f109

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Lib/test/test_inspect.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -1761,8 +1761,7 @@ def test_errors(self):
17611761
self.assertEqualException(f, '2, 3, 4')
17621762
self.assertEqualException(f, '1, 2, 3, a=1')
17631763
self.assertEqualException(f, '2, 3, 4, c=5')
1764-
# XXX: success of this one depends on dict order
1765-
## self.assertEqualException(f, '2, 3, 4, a=1, c=5')
1764+
self.assertEqualException(f, '2, 3, 4, a=1, c=5')
17661765
# f got an unexpected keyword argument
17671766
self.assertEqualException(f, 'c=2')
17681767
self.assertEqualException(f, '2, c=3')
@@ -1773,17 +1772,19 @@ def test_errors(self):
17731772
self.assertEqualException(f, '1, a=2')
17741773
self.assertEqualException(f, '1, **{"a":2}')
17751774
self.assertEqualException(f, '1, 2, b=3')
1776-
# XXX: Python inconsistency
1777-
# - for functions and bound methods: unexpected keyword 'c'
1778-
# - for unbound methods: multiple values for keyword 'a'
1779-
#self.assertEqualException(f, '1, c=3, a=2')
1775+
self.assertEqualException(f, '1, c=3, a=2')
17801776
# issue11256:
17811777
f3 = self.makeCallable('**c')
17821778
self.assertEqualException(f3, '1, 2')
17831779
self.assertEqualException(f3, '1, 2, a=1, b=2')
17841780
f4 = self.makeCallable('*, a, b=0')
1785-
self.assertEqualException(f3, '1, 2')
1786-
self.assertEqualException(f3, '1, 2, a=1, b=2')
1781+
self.assertEqualException(f4, '1, 2')
1782+
self.assertEqualException(f4, '1, 2, a=1, b=2')
1783+
self.assertEqualException(f4, 'a=1, a=3')
1784+
self.assertEqualException(f4, 'a=1, c=3')
1785+
self.assertEqualException(f4, 'a=1, a=3, b=4')
1786+
self.assertEqualException(f4, 'a=1, b=2, a=3, b=4')
1787+
self.assertEqualException(f4, 'a=1, a=2, a=3, b=4')
17871788

17881789
# issue #20816: getcallargs() fails to iterate over non-existent
17891790
# kwonlydefaults and raises a wrong TypeError
@@ -2710,8 +2711,6 @@ def foo(cls, *, arg):
27102711
def test_signature_on_partial(self):
27112712
from functools import partial
27122713

2713-
Parameter = inspect.Parameter
2714-
27152714
def test():
27162715
pass
27172716

@@ -2826,8 +2825,6 @@ def test(a, b, c:int) -> 42:
28262825
((('c', ..., int, "positional_or_keyword"),),
28272826
42))
28282827

2829-
psig = inspect.signature(partial(partial(test, 1), 2))
2830-
28312828
def foo(a):
28322829
return a
28332830
_foo = partial(partial(foo, a=10), a=20)
@@ -3958,8 +3955,6 @@ def test(a, *args, b, z=100, **kwargs):
39583955
self.assertEqual(ba.args, (10, 20))
39593956

39603957
def test_signature_bind_positional_only(self):
3961-
P = inspect.Parameter
3962-
39633958
def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
39643959
return a_po, b_po, c_po, foo, bar, kwargs
39653960

@@ -4392,7 +4387,6 @@ def test_qualname_source(self):
43924387
self.assertEqual(err, b'')
43934388

43944389
def test_builtins(self):
4395-
module = importlib.import_module('unittest')
43964390
_, out, err = assert_python_failure('-m', 'inspect',
43974391
'sys')
43984392
lines = err.decode().splitlines()

0 commit comments

Comments
 (0)