Skip to content

Commit

Permalink
gh-127949: fix DeprecationWarning in test_inspect.py (#128215)
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Dec 24, 2024
1 parent 30efede commit 3f6a618
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from annotationlib import Format, ForwardRef
import asyncio
import builtins
import collections
import copy
Expand Down Expand Up @@ -73,11 +72,6 @@ def revise(filename, *args):
git = mod.StupidGit()


def tearDownModule():
if support.has_socket_support:
asyncio._set_event_loop_policy(None)


def signatures_with_lexicographic_keyword_only_parameters():
"""
Yields a whole bunch of functions with only keyword-only parameters,
Expand Down Expand Up @@ -205,7 +199,7 @@ def test_excluding_predicates(self):
self.assertFalse(inspect.ismethodwrapper(type("AnyClass", (), {})))

def test_ispackage(self):
self.istest(inspect.ispackage, 'asyncio')
self.istest(inspect.ispackage, 'unittest')
self.istest(inspect.ispackage, 'importlib')
self.assertFalse(inspect.ispackage(inspect))
self.assertFalse(inspect.ispackage(mod))
Expand Down Expand Up @@ -1166,16 +1160,20 @@ def f(self):
# This is necessary when the test is run multiple times.
sys.modules.pop("inspect_actual")

@unittest.skipIf(
support.is_emscripten or support.is_wasi,
"socket.accept is broken"
)
def test_nested_class_definition_inside_async_function(self):
import asyncio
self.addCleanup(asyncio.set_event_loop_policy, None)
self.assertSourceEqual(asyncio.run(mod2.func225()), 226, 227)
def run(coro):
try:
coro.send(None)
except StopIteration as e:
return e.value
else:
raise RuntimeError("coroutine did not complete synchronously!")
finally:
coro.close()

self.assertSourceEqual(run(mod2.func225()), 226, 227)
self.assertSourceEqual(mod2.cls226, 231, 235)
self.assertSourceEqual(asyncio.run(mod2.cls226().func232()), 233, 234)
self.assertSourceEqual(run(mod2.cls226().func232()), 233, 234)

def test_class_definition_same_name_diff_methods(self):
self.assertSourceEqual(mod2.cls296, 296, 298)
Expand Down

0 comments on commit 3f6a618

Please sign in to comment.