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

Restore public api names #32

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pytest_jupyter/jupyter_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def jp_asyncio_loop():


@pytest.fixture(autouse=True)
def jp_io_loop(jp_asyncio_loop):
def io_loop(jp_asyncio_loop):
"""Override the io_loop for pytest_tornasync. This is a no-op
if tornado is not installed."""

Expand Down
32 changes: 16 additions & 16 deletions pytest_jupyter/jupyter_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@


@pytest.fixture
def jp_http_server(jp_io_loop, jp_http_server_port, jp_web_app):
def http_server(io_loop, http_server_port, jp_web_app):
"""Start a tornado HTTP server that listens on all available interfaces."""

async def get_server():
server = tornado.httpserver.HTTPServer(jp_web_app)
server.add_socket(jp_http_server_port[0])
server.add_socket(http_server_port[0])
return server

server = jp_io_loop.run_sync(get_server)
server = io_loop.run_sync(get_server)
yield server
server.stop()

if hasattr(server, "close_all_connections"):
jp_io_loop.run_sync(server.close_all_connections)
io_loop.run_sync(server.close_all_connections)

jp_http_server_port[0].close()
http_server_port[0].close()


# End pytest_tornasync overrides
Expand Down Expand Up @@ -107,10 +107,10 @@ def jp_argv():


@pytest.fixture()
def jp_http_port(jp_http_server_port):
def http_port(http_server_port):
"""Returns the port value from the http_server_port fixture."""
yield jp_http_server_port[-1]
jp_http_server_port[0].close()
yield http_server_port[-1]
http_server_port[0].close()


@pytest.fixture
Expand Down Expand Up @@ -161,13 +161,13 @@ def jp_configurable_serverapp(
jp_environ,
jp_server_config,
jp_argv,
jp_http_port,
http_port,
jp_base_url,
tmp_path,
jp_root_dir,
jp_logging_stream,
jp_asyncio_loop,
jp_io_loop,
io_loop,
):
"""Starts a Jupyter Server instance based on
the provided configuration values.
Expand Down Expand Up @@ -195,9 +195,9 @@ def _configurable_serverapp(
base_url=jp_base_url,
argv=jp_argv,
environ=jp_environ,
http_port=jp_http_port,
http_port=http_port,
tmp_path=tmp_path,
io_loop=jp_io_loop,
io_loop=io_loop,
root_dir=jp_root_dir,
**kwargs,
):
Expand Down Expand Up @@ -282,7 +282,7 @@ def jp_base_url():


@pytest.fixture
def jp_fetch(jp_serverapp, jp_http_server_client, jp_auth_header, jp_base_url):
def jp_fetch(jp_serverapp, http_server_client, jp_auth_header, jp_base_url):
"""Sends an (asynchronous) HTTP request to a test server.
The fixture is a factory; it can be called like
a function inside a unit test. Here's a basic
Expand All @@ -309,13 +309,13 @@ def client_fetch(*parts, headers=None, params=None, **kwargs):
for key, value in jp_auth_header.items():
headers.setdefault(key, value)
# Make request.
return jp_http_server_client.fetch(url, headers=headers, request_timeout=20, **kwargs)
return http_server_client.fetch(url, headers=headers, request_timeout=20, **kwargs)

return client_fetch


@pytest.fixture
def jp_ws_fetch(jp_serverapp, jp_http_server_client, jp_auth_header, jp_http_port, jp_base_url):
def jp_ws_fetch(jp_serverapp, http_server_client, jp_auth_header, http_port, jp_base_url):
"""Sends a websocket request to a test server.
The fixture is a factory; it can be called like
a function inside a unit test. Here's a basic
Expand Down Expand Up @@ -348,7 +348,7 @@ def client_fetch(*parts, headers=None, params=None, **kwargs):
# Handle URL strings
path_url = url_escape(url_path_join(*parts), plus=False)
base_path_url = url_path_join(jp_base_url, path_url)
urlparts = urllib.parse.urlparse(f"ws://localhost:{jp_http_port}")
urlparts = urllib.parse.urlparse(f"ws://localhost:{http_port}")
urlparts = urlparts._replace(path=base_path_url, query=urllib.parse.urlencode(params))
url = urlparts.geturl()
# Add auth keys to header
Expand Down
10 changes: 5 additions & 5 deletions pytest_jupyter/pytest_tornasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pytest_pyfunc_call(pyfuncitem):
return True

try:
loop = funcargs["jp_io_loop"]
loop = funcargs["io_loop"]
except KeyError:
loop = tornado.ioloop.IOLoop.current()

Expand All @@ -39,23 +39,23 @@ def pytest_pyfunc_call(pyfuncitem):


@pytest.fixture
def jp_http_server_port():
def http_server_port():
"""
Port used by `http_server`.
"""
return tornado.testing.bind_unused_port()


@pytest.fixture
def jp_http_server_client(jp_http_server, jp_io_loop):
def http_server_client(http_server, io_loop):
"""
Create an asynchronous HTTP client that can fetch from `http_server`.
"""

async def get_client():
return AsyncHTTPServerClient(http_server=jp_http_server)
return AsyncHTTPServerClient(http_server=http_server)

client = jp_io_loop.run_sync(get_client)
client = io_loop.run_sync(get_client)
with closing(client) as context:
yield context

Expand Down
2 changes: 1 addition & 1 deletion tests/test_jupyter_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def test_send_request(send_request):
assert code == 200


async def test_connection(jp_fetch, jp_ws_fetch, jp_http_port, jp_auth_header):
async def test_connection(jp_fetch, jp_ws_fetch, http_port, jp_auth_header):
# Create kernel
r = await jp_fetch("api", "kernels", method="POST", body="{}")
kid = json.loads(r.body.decode())["id"]
Expand Down