9a7987
From 584f3cff7d5cb8a588189ae1137b814cf5c47e05 Mon Sep 17 00:00:00 2001
9a7987
From: David Lord <davidism@gmail.com>
9a7987
Date: Wed, 19 May 2021 20:01:58 -0700
9a7987
Subject: [PATCH] address deprecation warnings from Python 3.10b1
9a7987
9a7987
---
9a7987
 tests/conftest.py   |  5 ++++-
9a7987
 tests/test_local.py | 34 +++++++++++++++++++++++++---------
9a7987
 2 files changed, 29 insertions(+), 10 deletions(-)
9a7987
9a7987
diff --git a/tests/conftest.py b/tests/conftest.py
9a7987
index 3b5cbd71c..4ad1ff23e 100644
9a7987
--- a/tests/conftest.py
9a7987
+++ b/tests/conftest.py
9a7987
@@ -66,7 +66,10 @@ def connect(self, **kwargs):
9a7987
 
9a7987
         if protocol == "https":
9a7987
             if "context" not in kwargs:
9a7987
-                kwargs["context"] = ssl.SSLContext()
9a7987
+                context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
9a7987
+                context.check_hostname = False
9a7987
+                context.verify_mode = ssl.CERT_NONE
9a7987
+                kwargs["context"] = context
9a7987
 
9a7987
             return http.client.HTTPSConnection(self.addr, **kwargs)
9a7987
 
9a7987
diff --git a/tests/test_local.py b/tests/test_local.py
9a7987
index 537fc32fb..b5c392890 100644
9a7987
--- a/tests/test_local.py
9a7987
+++ b/tests/test_local.py
9a7987
@@ -12,6 +12,18 @@
9a7987
 from werkzeug import local
9a7987
 
9a7987
 
9a7987
+if sys.version_info < (3, 7):
9a7987
+
9a7987
+    def run_async(coro):
9a7987
+        return asyncio.get_event_loop().run_until_complete(coro)
9a7987
+
9a7987
+
9a7987
+else:
9a7987
+
9a7987
+    def run_async(coro):
9a7987
+        return asyncio.run(coro)
9a7987
+
9a7987
+
9a7987
 def test_basic_local():
9a7987
     ns = local.Local()
9a7987
     ns.foo = 0
9a7987
@@ -55,9 +67,11 @@ async def value_setter(idx):
9a7987
         await asyncio.sleep(0.02)
9a7987
         values.append(ns.foo)
9a7987
 
9a7987
-    loop = asyncio.get_event_loop()
9a7987
-    futures = [asyncio.ensure_future(value_setter(idx)) for idx in [1, 2, 3]]
9a7987
-    loop.run_until_complete(asyncio.gather(*futures))
9a7987
+    async def main():
9a7987
+        futures = [asyncio.ensure_future(value_setter(i)) for i in [1, 2, 3]]
9a7987
+        await asyncio.gather(*futures)
9a7987
+
9a7987
+    run_async(main())
9a7987
     assert sorted(values) == [1, 2, 3]
9a7987
 
9a7987
     def delfoo():
9a7987
@@ -118,9 +132,11 @@ async def task():
9a7987
         ls.push(1)
9a7987
         assert len(ls._local.stack) == 2
9a7987
 
9a7987
-    loop = asyncio.get_event_loop()
9a7987
-    futures = [asyncio.ensure_future(task()) for _ in range(3)]
9a7987
-    loop.run_until_complete(asyncio.gather(*futures))
9a7987
+    async def main():
9a7987
+        futures = [asyncio.ensure_future(task()) for _ in range(3)]
9a7987
+        await asyncio.gather(*futures)
9a7987
+
9a7987
+    run_async(main())
9a7987
 
9a7987
 
9a7987
 @pytest.mark.skipif(
9a7987
@@ -571,7 +587,7 @@ async def get():
9a7987
     async def main():
9a7987
         return await p
9a7987
 
9a7987
-    out = asyncio.get_event_loop().run_until_complete(main())
9a7987
+    out = run_async(main())
9a7987
     assert out == 1
9a7987
 
9a7987
 
9a7987
@@ -599,7 +615,7 @@ async def main():
9a7987
 
9a7987
         return out
9a7987
 
9a7987
-    out = asyncio.get_event_loop().run_until_complete(main())
9a7987
+    out = run_async(main())
9a7987
     assert out == [2, 1, 0]
9a7987
 
9a7987
 
9a7987
@@ -623,4 +639,4 @@ async def main():
9a7987
         assert p.value == 2
9a7987
         return True
9a7987
 
9a7987
-    assert asyncio.get_event_loop().run_until_complete(main())
9a7987
+    assert run_async(main())