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

Simplify tests for preheat kernel mode #996

Merged
merged 6 commits into from
Oct 8, 2021
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
15 changes: 3 additions & 12 deletions tests/app/cgi-test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import pytest
import os
NOTEBOOK_PATH = 'cgi.ipynb'


@pytest.fixture
def notebook_cgi_path(base_url, preheat_mode):
if preheat_mode:
return base_url
def notebook_cgi_path(base_url):
return base_url + f'voila/render/{NOTEBOOK_PATH}'


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory, NOTEBOOK_PATH),
'--VoilaTest.log_level=DEBUG'
] + voila_args_extra
def voila_args(notebook_directory, voila_args_extra):

return [
'--VoilaTest.root_dir=%r' % notebook_directory,
Expand All @@ -25,8 +17,7 @@ def voila_args(notebook_directory, voila_args_extra, preheat_mode):


async def test_cgi_using_query_parameters(http_server_client,
notebook_cgi_path, wait_for_kernel):
await wait_for_kernel()
notebook_cgi_path):
response = await http_server_client.fetch(notebook_cgi_path +
'?username=VOILA')
assert response.code == 200
Expand Down
4 changes: 2 additions & 2 deletions tests/app/config_paths_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_config_contents_manager(voila_app):
assert voila_app.contents_manager.use_atomic_writing is False


async def test_template(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
async def test_template(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
assert response.code == 200
assert 'test_template.css' in response.body.decode('utf-8')
Expand Down
21 changes: 6 additions & 15 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pytest
import voila.app
import asyncio


BASE_DIR = os.path.dirname(__file__)

Expand Down Expand Up @@ -33,13 +33,13 @@ def voila_args(voila_notebook, voila_args_extra, voila_config_file_paths_arg):
return [voila_notebook, voila_config_file_paths_arg] + voila_args_extra + debug_args


@pytest.fixture(params=[False, True])
def preheat_mode(request):
@pytest.fixture
def preheat_mode():
"""Fixture used to activate/deactivate pre-heat kernel mode.
All tests will be executed in two modes automatically, override
this fixture in test file if you want to run only one mode.
Override this fixture in test file if you want to activate
preheat mode.
"""
return request.param
return False


@pytest.fixture
Expand All @@ -61,12 +61,3 @@ def voila_app(voila_args, voila_config, preheat_config):
@pytest.fixture
def app(voila_app):
return voila_app.app


@pytest.fixture
def wait_for_kernel(preheat_mode):
"""Wait for kernel be heated in case of `preheat_mode = True`"""
async def inner(time=1):
if preheat_mode:
await asyncio.sleep(time)
return inner
25 changes: 8 additions & 17 deletions tests/app/cwd_subdir_test.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
# test serving a notebook
import pytest
import os

NOTEBOOK_PATH = 'subdir/cwd_subdir.ipynb'


@pytest.fixture
def cwd_subdir_notebook_url(base_url, preheat_mode):
if preheat_mode:
return base_url
def cwd_subdir_notebook_url(base_url):
return base_url + f'voila/render/{NOTEBOOK_PATH}'


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory, NOTEBOOK_PATH),
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra
else:
return [
'--VoilaTest.root_dir=%r' % notebook_directory,
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra
def voila_args(notebook_directory, voila_args_extra):
return [
'--VoilaTest.root_dir=%r' % notebook_directory,
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra


async def test_hello_world(
http_server_client, cwd_subdir_notebook_url, wait_for_kernel
http_server_client, cwd_subdir_notebook_url
):
await wait_for_kernel()

response = await http_server_client.fetch(cwd_subdir_notebook_url)
html_text = response.body.decode('utf-8')
assert 'check for the cwd' in html_text
4 changes: 2 additions & 2 deletions tests/app/cwd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, 'cwd.ipynb')


async def test_template_cwd(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
async def test_template_cwd(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
html_text = response.body.decode('utf-8')
assert 'check for the cwd' in html_text
8 changes: 2 additions & 6 deletions tests/app/execute_cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

@pytest.fixture
def cpp_file_url(base_url, preheat_mode):
if preheat_mode:
return base_url
return base_url + f'voila/render/{NOTEBOOK_PATH}'


Expand All @@ -19,14 +17,12 @@ def voila_args_extra():

@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra


@pytest.mark.skipif(not TEST_XEUS_CLING, reason='opt in to avoid having to install xeus-cling')
async def test_non_existing_kernel(http_server_client, cpp_file_url, wait_for_kernel):
await wait_for_kernel()
async def test_non_existing_kernel(http_server_client, cpp_file_url):

response = await http_server_client.fetch(cpp_file_url)
assert response.code == 200
assert 'Hello Voilà, from c++' in response.body.decode('utf-8')
8 changes: 4 additions & 4 deletions tests/app/execute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import mock


async def test_hello_world(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
async def test_hello_world(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
Expand All @@ -21,8 +21,8 @@ async def test_hello_world(http_server_client, base_url, wait_for_kernel):
assert 'test_template.css' not in html_text, "test_template should not be the default"


async def test_no_execute_allowed(voila_app, app, http_server_client, base_url, http_server_port, wait_for_kernel):
await wait_for_kernel()
async def test_no_execute_allowed(voila_app, app, http_server_client, base_url, http_server_port):

assert voila_app.app is app
response = (await http_server_client.fetch(base_url)).body.decode('utf-8')
pattern = r"""kernelId": ["']([0-9a-zA-Z-]+)["']"""
Expand Down
4 changes: 2 additions & 2 deletions tests/app/image_inlining_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, NOTEBOOK_PATH)


async def test_image_inlining(http_server_client, base_url, notebook_directory, wait_for_kernel):
await wait_for_kernel()
async def test_image_inlining(http_server_client, base_url, notebook_directory):

response = await http_server_client.fetch(base_url)
html_text = response.body.decode('utf-8')

Expand Down
9 changes: 7 additions & 2 deletions tests/app/kernel_death_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ def voila_args_extra():
return ['--debug']


async def test_kernel_death(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
@pytest.fixture
def preheat_mode():
return False


async def test_kernel_death(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
html_text = response.body.decode('utf-8')
assert 'raise DeadKernelError' in html_text
4 changes: 2 additions & 2 deletions tests/app/nbextensions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def voila_config_file_paths_arg():
return '--VoilaTest.config_file_paths=[%r]' % path


async def test_lists_extension(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
async def test_lists_extension(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
Expand Down
15 changes: 4 additions & 11 deletions tests/app/no_kernelspec_test.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import pytest
import os


NOTEBOOK_PATH = 'no_kernelspec.ipynb'


@pytest.fixture
def non_existing_kernel_notebook(base_url, preheat_mode):
if preheat_mode:
return base_url
def non_existing_kernel_notebook(base_url):
return base_url + f"voila/render/{NOTEBOOK_PATH}"


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra

def voila_args(notebook_directory, voila_args_extra):
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra


async def test_non_existing_kernel(http_server_client,
non_existing_kernel_notebook,
wait_for_kernel):
await wait_for_kernel()
):

response = await http_server_client.fetch(non_existing_kernel_notebook)
assert response.code == 200
assert 'Executing without a kernelspec' in response.body.decode('utf-8')
14 changes: 5 additions & 9 deletions tests/app/no_metadata.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import pytest
import os


NOTEBOOK_PATH = 'no_metadata.ipynb'


@pytest.fixture
def non_existing_notebook_metadata(base_url, preheat_mode):
if preheat_mode:
return base_url
def non_existing_notebook_metadata(base_url):
return base_url + f'voila/render/{NOTEBOOK_PATH}'


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
def voila_args(notebook_directory, voila_args_extra):
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra


async def test_non_existing_metadata(
http_server_client, non_existing_notebook_metadata, wait_for_kernel
http_server_client, non_existing_notebook_metadata
):
await wait_for_kernel()

response = await http_server_client.fetch(non_existing_notebook_metadata)
assert response.code == 200
assert 'Executing without notebook metadata' in response.body.decode('utf-8')
4 changes: 2 additions & 2 deletions tests/app/no_strip_sources_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def voila_args_extra():
return ['--VoilaConfiguration.strip_sources=False', '--VoilaExecutor.timeout=240']


async def test_no_strip_sources(http_server_client, base_url, wait_for_kernel):
await wait_for_kernel()
async def test_no_strip_sources(http_server_client, base_url):

response = await http_server_client.fetch(base_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
Expand Down
14 changes: 4 additions & 10 deletions tests/app/non_existing_kernel_test.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import pytest
import os

NOTEBOOK_PATH = "non_existing_kernel.ipynb"


@pytest.fixture
def non_existing_kernel_notebook(base_url, preheat_mode):
if preheat_mode:
return base_url
def non_existing_kernel_notebook(base_url):
return base_url + f"voila/render/{NOTEBOOK_PATH}"


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
def voila_args(notebook_directory, voila_args_extra):
return ["--VoilaTest.root_dir=%r" % notebook_directory] + voila_args_extra


async def test_non_existing_kernel(
http_server_client, non_existing_kernel_notebook, wait_for_kernel
http_server_client, non_existing_kernel_notebook
):
await wait_for_kernel()

response = await http_server_client.fetch(non_existing_kernel_notebook)
assert response.code == 200
assert "non-existing kernel" in response.body.decode("utf-8")
16 changes: 4 additions & 12 deletions tests/app/notebooks_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
# simply tests if some notebooks execute
import pytest
import os

NOTEBOOK_PATH = 'other_comms.ipynb'


@pytest.fixture
def notebook_other_comms_path(base_url, preheat_mode):
if preheat_mode:
return base_url
def notebook_other_comms_path(base_url):
return base_url + f'voila/render/{NOTEBOOK_PATH}'


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory, NOTEBOOK_PATH),
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra
def voila_args(notebook_directory, voila_args_extra):
return [
'--VoilaTest.root_dir=%r' % notebook_directory,
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra


async def test_other_comms(
http_server_client, notebook_other_comms_path, wait_for_kernel
http_server_client, notebook_other_comms_path
):
await wait_for_kernel()

response = await http_server_client.fetch(notebook_other_comms_path)
html_text = response.body.decode('utf-8')
assert 'This notebook executed' in html_text
Loading