mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 21:43:01 +00:00
Remove 3.6 compatibility shims
- asyncio.all_tasks/current_task - pytest-asyncio 0.17 - contextmanager.nullcontext
This commit is contained in:
@@ -16,8 +16,7 @@ mock
|
|||||||
nbclassic<0.4
|
nbclassic<0.4
|
||||||
pre-commit
|
pre-commit
|
||||||
pytest>=3.3
|
pytest>=3.3
|
||||||
pytest-asyncio; python_version < "3.7"
|
pytest-asyncio>=0.17
|
||||||
pytest-asyncio>=0.17; python_version >= "3.7"
|
|
||||||
pytest-cov
|
pytest-cov
|
||||||
requests-mock
|
requests-mock
|
||||||
tbump
|
tbump
|
||||||
|
@@ -23,15 +23,6 @@ from urllib.parse import unquote, urlparse, urlunparse
|
|||||||
if sys.version_info[:2] < (3, 3):
|
if sys.version_info[:2] < (3, 3):
|
||||||
raise ValueError("Python < 3.3 not supported: %s" % sys.version)
|
raise ValueError("Python < 3.3 not supported: %s" % sys.version)
|
||||||
|
|
||||||
# For compatibility with python versions 3.6 or earlier.
|
|
||||||
# asyncio.Task.all_tasks() is fully moved to asyncio.all_tasks() starting with 3.9. Also applies to current_task.
|
|
||||||
try:
|
|
||||||
asyncio_all_tasks = asyncio.all_tasks
|
|
||||||
asyncio_current_task = asyncio.current_task
|
|
||||||
except AttributeError as e:
|
|
||||||
asyncio_all_tasks = asyncio.Task.all_tasks
|
|
||||||
asyncio_current_task = asyncio.Task.current_task
|
|
||||||
|
|
||||||
import tornado.httpserver
|
import tornado.httpserver
|
||||||
import tornado.options
|
import tornado.options
|
||||||
from dateutil.parser import parse as parse_date
|
from dateutil.parser import parse as parse_date
|
||||||
@@ -3248,7 +3239,7 @@ class JupyterHub(Application):
|
|||||||
|
|
||||||
await self.cleanup()
|
await self.cleanup()
|
||||||
|
|
||||||
tasks = [t for t in asyncio_all_tasks() if t is not asyncio_current_task()]
|
tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
|
||||||
|
|
||||||
if tasks:
|
if tasks:
|
||||||
self.log.debug("Cancelling pending tasks")
|
self.log.debug("Cancelling pending tasks")
|
||||||
@@ -3261,7 +3252,7 @@ class JupyterHub(Application):
|
|||||||
except StopAsyncIteration as e:
|
except StopAsyncIteration as e:
|
||||||
self.log.error("Caught StopAsyncIteration Exception", exc_info=True)
|
self.log.error("Caught StopAsyncIteration Exception", exc_info=True)
|
||||||
|
|
||||||
tasks = [t for t in asyncio_all_tasks()]
|
tasks = [t for t in asyncio.all_tasks()]
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
self.log.debug("Task status: %s", t)
|
self.log.debug("Task status: %s", t)
|
||||||
asyncio.get_event_loop().stop()
|
asyncio.get_event_loop().stop()
|
||||||
|
@@ -54,28 +54,6 @@ from .utils import add_user
|
|||||||
_db = None
|
_db = None
|
||||||
|
|
||||||
|
|
||||||
def _pytest_collection_modifyitems(items):
|
|
||||||
"""This function is automatically run by pytest passing all collected test
|
|
||||||
functions.
|
|
||||||
|
|
||||||
We use it to add asyncio marker to all async tests and assert we don't use
|
|
||||||
test functions that are async generators which wouldn't make sense.
|
|
||||||
|
|
||||||
It is no longer required with pytest-asyncio >= 0.17
|
|
||||||
"""
|
|
||||||
for item in items:
|
|
||||||
if inspect.iscoroutinefunction(item.obj):
|
|
||||||
item.add_marker('asyncio')
|
|
||||||
assert not inspect.isasyncgenfunction(item.obj)
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info < (3, 7):
|
|
||||||
# apply pytest-asyncio's 'auto' mode on Python 3.6.
|
|
||||||
# 'auto' mode is new in pytest-asyncio 0.17,
|
|
||||||
# which requires Python 3.7.
|
|
||||||
pytest_collection_modifyitems = _pytest_collection_modifyitems
|
|
||||||
|
|
||||||
|
|
||||||
@fixture(scope='module')
|
@fixture(scope='module')
|
||||||
def ssl_tmpdir(tmpdir_factory):
|
def ssl_tmpdir(tmpdir_factory):
|
||||||
return tmpdir_factory.mktemp('ssl')
|
return tmpdir_factory.mktemp('ssl')
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
"""Tests for jupyterhub.singleuser"""
|
"""Tests for jupyterhub.singleuser"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager, nullcontext
|
||||||
from subprocess import CalledProcessError, check_output
|
from subprocess import CalledProcessError, check_output
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from urllib.parse import urlencode, urlparse
|
from urllib.parse import urlencode, urlparse
|
||||||
@@ -17,12 +17,6 @@ from .mocking import StubSingleUserSpawner, public_url
|
|||||||
from .utils import AsyncSession, async_requests, get_page
|
from .utils import AsyncSession, async_requests, get_page
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def nullcontext():
|
|
||||||
"""Python 3.7+ contextlib.nullcontext, backport for 3.6"""
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"access_scopes, server_name, expect_success",
|
"access_scopes, server_name, expect_success",
|
||||||
[
|
[
|
||||||
|
@@ -27,14 +27,26 @@ from tornado import gen, ioloop, web
|
|||||||
from tornado.httpclient import AsyncHTTPClient, HTTPError
|
from tornado.httpclient import AsyncHTTPClient, HTTPError
|
||||||
from tornado.log import app_log
|
from tornado.log import app_log
|
||||||
|
|
||||||
# For compatibility with python versions 3.6 or earlier.
|
|
||||||
# asyncio.Task.all_tasks() is fully moved to asyncio.all_tasks() starting with 3.9. Also applies to current_task.
|
# Deprecated aliases: no longer needed now that we require 3.7
|
||||||
try:
|
def asyncio_all_tasks(loop=None):
|
||||||
asyncio_all_tasks = asyncio.all_tasks
|
warnings.warn(
|
||||||
asyncio_current_task = asyncio.current_task
|
"jupyterhub.utils.asyncio_all_tasks is deprecated in JupyterHub 2.4."
|
||||||
except AttributeError as e:
|
" Use asyncio.all_tasks().",
|
||||||
asyncio_all_tasks = asyncio.Task.all_tasks
|
DeprecationWarning,
|
||||||
asyncio_current_task = asyncio.Task.current_task
|
stacklevel=2,
|
||||||
|
)
|
||||||
|
return asyncio.all_tasks(loop=loop)
|
||||||
|
|
||||||
|
|
||||||
|
def asyncio_current_task(loop=None):
|
||||||
|
warnings.warn(
|
||||||
|
"jupyterhub.utils.asyncio_current_task is deprecated in JupyterHub 2.4."
|
||||||
|
" Use asyncio.current_task().",
|
||||||
|
DeprecationWarning,
|
||||||
|
stacklevel=2,
|
||||||
|
)
|
||||||
|
return asyncio.current_task(loop=loop)
|
||||||
|
|
||||||
|
|
||||||
def random_port():
|
def random_port():
|
||||||
|
Reference in New Issue
Block a user