From 706acd99373e622727b7c179eddf5fead7559f73 Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Tue, 5 Oct 2021 23:21:45 +0200 Subject: [PATCH 1/6] Simplify test --- tests/app/cgi-test.py | 11 ++--------- tests/app/conftest.py | 2 +- tests/app/cwd_subdir_test.py | 20 ++++++-------------- tests/app/execute_cpp_test.py | 4 ---- tests/app/no_kernelspec_test.py | 9 ++------- tests/app/no_metadata.py | 8 ++------ tests/app/non_existing_kernel_test.py | 8 ++------ tests/app/notebooks_test.py | 11 ++--------- tests/app/show_traceback_test.py | 11 ++--------- 9 files changed, 19 insertions(+), 65 deletions(-) diff --git a/tests/app/cgi-test.py b/tests/app/cgi-test.py index 8caa0f2fb..c0cd764cc 100644 --- a/tests/app/cgi-test.py +++ b/tests/app/cgi-test.py @@ -4,19 +4,12 @@ @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, diff --git a/tests/app/conftest.py b/tests/app/conftest.py index aa64a27fc..81cc0f412 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -66,7 +66,7 @@ def app(voila_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): + async def inner(time=3): if preheat_mode: await asyncio.sleep(time) return inner diff --git a/tests/app/cwd_subdir_test.py b/tests/app/cwd_subdir_test.py index 162ca43d5..9fd0fed58 100644 --- a/tests/app/cwd_subdir_test.py +++ b/tests/app/cwd_subdir_test.py @@ -6,24 +6,16 @@ @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( diff --git a/tests/app/execute_cpp_test.py b/tests/app/execute_cpp_test.py index 11f0232b3..0aeb08985 100644 --- a/tests/app/execute_cpp_test.py +++ b/tests/app/execute_cpp_test.py @@ -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}' @@ -19,8 +17,6 @@ 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 diff --git a/tests/app/no_kernelspec_test.py b/tests/app/no_kernelspec_test.py index e8c714262..c18bc0951 100644 --- a/tests/app/no_kernelspec_test.py +++ b/tests/app/no_kernelspec_test.py @@ -6,17 +6,12 @@ @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 diff --git a/tests/app/no_metadata.py b/tests/app/no_metadata.py index 25e7cf7e9..32dfc8ca3 100644 --- a/tests/app/no_metadata.py +++ b/tests/app/no_metadata.py @@ -5,16 +5,12 @@ @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 diff --git a/tests/app/non_existing_kernel_test.py b/tests/app/non_existing_kernel_test.py index b9ba16e56..4525cd6de 100644 --- a/tests/app/non_existing_kernel_test.py +++ b/tests/app/non_existing_kernel_test.py @@ -5,16 +5,12 @@ @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 diff --git a/tests/app/notebooks_test.py b/tests/app/notebooks_test.py index d57e605ad..5f1c89cf3 100644 --- a/tests/app/notebooks_test.py +++ b/tests/app/notebooks_test.py @@ -6,19 +6,12 @@ @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', diff --git a/tests/app/show_traceback_test.py b/tests/app/show_traceback_test.py index 3736ac4a8..7fc6f7e19 100644 --- a/tests/app/show_traceback_test.py +++ b/tests/app/show_traceback_test.py @@ -10,19 +10,12 @@ def show_tracebacks(request): @pytest.fixture -def notebook_show_traceback_path(base_url, preheat_mode): - if preheat_mode: - return base_url +def notebook_show_traceback_path(base_url): return base_url + f'voila/render/{NOTEBOOK_PATH}' @pytest.fixture -def voila_args(notebook_directory, voila_args_extra, show_tracebacks, preheat_mode): - if preheat_mode: - return [ - os.path.join(notebook_directory, NOTEBOOK_PATH), - f'--VoilaConfiguration.show_tracebacks={show_tracebacks}', - ] + voila_args_extra +def voila_args(notebook_directory, voila_args_extra, show_tracebacks): return [ '--VoilaTest.root_dir=%r' % notebook_directory, f'--VoilaConfiguration.show_tracebacks={show_tracebacks}', From f2011fb85db17590d06d75e18dded64806844d8c Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Tue, 5 Oct 2021 23:47:48 +0200 Subject: [PATCH 2/6] Lint code --- tests/app/cgi-test.py | 1 - tests/app/cwd_subdir_test.py | 1 - tests/app/no_kernelspec_test.py | 2 -- tests/app/no_metadata.py | 2 +- tests/app/non_existing_kernel_test.py | 2 -- tests/app/notebooks_test.py | 1 - tests/app/show_traceback_test.py | 1 - 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/app/cgi-test.py b/tests/app/cgi-test.py index c0cd764cc..07b589b7f 100644 --- a/tests/app/cgi-test.py +++ b/tests/app/cgi-test.py @@ -1,5 +1,4 @@ import pytest -import os NOTEBOOK_PATH = 'cgi.ipynb' diff --git a/tests/app/cwd_subdir_test.py b/tests/app/cwd_subdir_test.py index 9fd0fed58..93f437512 100644 --- a/tests/app/cwd_subdir_test.py +++ b/tests/app/cwd_subdir_test.py @@ -1,6 +1,5 @@ # test serving a notebook import pytest -import os NOTEBOOK_PATH = 'subdir/cwd_subdir.ipynb' diff --git a/tests/app/no_kernelspec_test.py b/tests/app/no_kernelspec_test.py index c18bc0951..fba1d39e5 100644 --- a/tests/app/no_kernelspec_test.py +++ b/tests/app/no_kernelspec_test.py @@ -1,6 +1,4 @@ import pytest -import os - NOTEBOOK_PATH = 'no_kernelspec.ipynb' diff --git a/tests/app/no_metadata.py b/tests/app/no_metadata.py index 32dfc8ca3..168d7866f 100644 --- a/tests/app/no_metadata.py +++ b/tests/app/no_metadata.py @@ -1,5 +1,5 @@ import pytest -import os + NOTEBOOK_PATH = 'no_metadata.ipynb' diff --git a/tests/app/non_existing_kernel_test.py b/tests/app/non_existing_kernel_test.py index 4525cd6de..9a9ef7227 100644 --- a/tests/app/non_existing_kernel_test.py +++ b/tests/app/non_existing_kernel_test.py @@ -1,6 +1,4 @@ import pytest -import os - NOTEBOOK_PATH = "non_existing_kernel.ipynb" diff --git a/tests/app/notebooks_test.py b/tests/app/notebooks_test.py index 5f1c89cf3..68554a198 100644 --- a/tests/app/notebooks_test.py +++ b/tests/app/notebooks_test.py @@ -1,6 +1,5 @@ # simply tests if some notebooks execute import pytest -import os NOTEBOOK_PATH = 'other_comms.ipynb' diff --git a/tests/app/show_traceback_test.py b/tests/app/show_traceback_test.py index 7fc6f7e19..491932b37 100644 --- a/tests/app/show_traceback_test.py +++ b/tests/app/show_traceback_test.py @@ -1,6 +1,5 @@ import pytest -import os NOTEBOOK_PATH = 'syntax_error.ipynb' From 466d1c5d621b6eb7c56ea317c8da462fd2f8b710 Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Wed, 6 Oct 2021 22:15:53 +0200 Subject: [PATCH 3/6] Add autokill and many_iopub_messages notebook to preheat blacklist --- tests/app/kernel_death_test.py | 5 +++++ tests/app/preheat_activation_test.py | 17 +++++++++-------- tests/app/preheat_configuration_test.py | 3 ++- tests/app/preheat_multiple_notebooks_test.py | 6 +++--- tests/voila.json | 8 ++++++++ voila/voila_kernel_manager.py | 1 + 6 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 tests/voila.json diff --git a/tests/app/kernel_death_test.py b/tests/app/kernel_death_test.py index d12553d6f..9fa7a43f7 100644 --- a/tests/app/kernel_death_test.py +++ b/tests/app/kernel_death_test.py @@ -13,6 +13,11 @@ def voila_args_extra(): return ['--debug'] +@pytest.fixture +def preheat_mode(): + return False + + async def test_kernel_death(http_server_client, base_url, wait_for_kernel): await wait_for_kernel() response = await http_server_client.fetch(base_url) diff --git a/tests/app/preheat_activation_test.py b/tests/app/preheat_activation_test.py index 35d3231b4..d0a85dd8f 100644 --- a/tests/app/preheat_activation_test.py +++ b/tests/app/preheat_activation_test.py @@ -15,6 +15,7 @@ def voila_notebook(notebook_directory): NOTEBOOK_EXECUTION_TIME = 2 +TIME_THRESHOLD = 1 async def send_request(sc, url, wait=0): @@ -40,13 +41,13 @@ async def test_request_before_kernel_heated(http_server_client, base_url): async def test_render_time_with_preheated_kernel(http_server_client, base_url): """ We wait for kernel properly heated before sending request, - it should take under 0.5s to return result + it should take under `TIME_THRESHOLD` second to return result """ time, text = await send_request(sc=http_server_client, url=base_url, wait=NOTEBOOK_EXECUTION_TIME + 2) assert 'hello world' in text - assert time < 0.5 + assert time < TIME_THRESHOLD async def test_render_time_with_multiple_requests(http_server_client, @@ -63,8 +64,8 @@ async def test_render_time_with_multiple_requests(http_server_client, wait=wait) time_list.append(time) - assert max(time_list) > 0.5 # Render time for a normal kernel - assert min(time_list) < 0.5 # Render time for a preheated kernel + assert max(time_list) > TIME_THRESHOLD # Render time for a normal kernel + assert min(time_list) < TIME_THRESHOLD # Render time for a preheated kernel async def test_request_with_query(http_server_client, base_url): @@ -76,7 +77,7 @@ async def test_request_with_query(http_server_client, base_url): time, _ = await send_request(sc=http_server_client, url=url, wait=NOTEBOOK_EXECUTION_TIME + 1) - assert time > 0.5 + assert time > TIME_THRESHOLD async def test_request_with_theme_parameter(http_server_client, base_url): @@ -88,11 +89,11 @@ async def test_request_with_theme_parameter(http_server_client, base_url): url = f'{base_url}?voila-theme=dark' time, _ = await send_request(sc=http_server_client, url=url, wait=wait) - assert time > 0.5 + assert time > TIME_THRESHOLD url = f'{base_url}?voila-theme=light' time, _ = await send_request(sc=http_server_client, url=url, wait=wait) - assert time < 0.5 + assert time < TIME_THRESHOLD async def test_request_with_template_parameter(http_server_client, base_url): @@ -104,4 +105,4 @@ async def test_request_with_template_parameter(http_server_client, base_url): url = f'{base_url}?voila-template=lab' time, _ = await send_request(sc=http_server_client, url=url, wait=wait) - assert time < 0.5 + assert time < TIME_THRESHOLD diff --git a/tests/app/preheat_configuration_test.py b/tests/app/preheat_configuration_test.py index 268195439..425d98f15 100644 --- a/tests/app/preheat_configuration_test.py +++ b/tests/app/preheat_configuration_test.py @@ -6,6 +6,7 @@ BASE_DIR = os.path.dirname(__file__) NOTEBOOK_EXECUTION_TIME = 2 NUMBER_PREHEATED_KERNEL = 2 +TIME_THRESHOLD = 1 @pytest.fixture @@ -39,7 +40,7 @@ async def test_refill_kernel_asynchronously(http_server_client, base_url): slow = [] for i in range(5*NUMBER_PREHEATED_KERNEL): time, _ = await send_request(sc=http_server_client, url=base_url) - if time < 0.5: + if time < TIME_THRESHOLD: fast.append(time) else: slow.append(time) diff --git a/tests/app/preheat_multiple_notebooks_test.py b/tests/app/preheat_multiple_notebooks_test.py index 6ea52e84f..966aab1c0 100644 --- a/tests/app/preheat_multiple_notebooks_test.py +++ b/tests/app/preheat_multiple_notebooks_test.py @@ -6,7 +6,7 @@ BASE_DIR = os.path.dirname(__file__) NOTEBOOK_EXECUTION_TIME = 2 NUMBER_PREHEATED_KERNEL = 2 - +TIME_THRESHOLD = 1 @pytest.fixture def voila_config_file_paths_arg(): @@ -38,7 +38,7 @@ async def test_render_notebook_with_heated_kernel(http_server_client, base_url): time, text = await send_request(sc=http_server_client, url=f'{base_url}voila/render/pre_heat.ipynb') assert 'hello world' in text - assert time < 0.5 + assert time < TIME_THRESHOLD async def test_render_blacklisted_notebook_with_nornal_kernel(http_server_client, base_url): @@ -46,4 +46,4 @@ async def test_render_blacklisted_notebook_with_nornal_kernel(http_server_client time, text = await send_request(sc=http_server_client, url=f'{base_url}voila/render/blacklisted.ipynb') assert 'hello world' in text - assert time > 0.5 + assert time > TIME_THRESHOLD diff --git a/tests/voila.json b/tests/voila.json new file mode 100644 index 000000000..3e08ac6e5 --- /dev/null +++ b/tests/voila.json @@ -0,0 +1,8 @@ +{ + "VoilaKernelManager": { + "preheat_blacklist": [ + "notebooks/autokill.ipynb", + "notebooks/many_iopub_messages.ipynb" + ] + } +} diff --git a/voila/voila_kernel_manager.py b/voila/voila_kernel_manager.py index c4de02558..47b676fed 100644 --- a/voila/voila_kernel_manager.py +++ b/voila/voila_kernel_manager.py @@ -332,6 +332,7 @@ def _notebook_filter(self, nb_path: Path) -> bool: nb_name = str(nb_path) if '.ipynb_checkpoints' in nb_name: return False + print('self.preheat_blacklist', self.preheat_blacklist) for nb_pattern in self.preheat_blacklist: pattern = re.compile(nb_pattern) if (nb_pattern in nb_name) or bool(pattern.match(nb_name)): From cc29ccbd704389df60223f644afc09c7031014dd Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Wed, 6 Oct 2021 22:30:20 +0200 Subject: [PATCH 4/6] Lint code --- tests/app/preheat_multiple_notebooks_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/app/preheat_multiple_notebooks_test.py b/tests/app/preheat_multiple_notebooks_test.py index 966aab1c0..bbb945731 100644 --- a/tests/app/preheat_multiple_notebooks_test.py +++ b/tests/app/preheat_multiple_notebooks_test.py @@ -8,6 +8,7 @@ NUMBER_PREHEATED_KERNEL = 2 TIME_THRESHOLD = 1 + @pytest.fixture def voila_config_file_paths_arg(): path = os.path.join(BASE_DIR, '..', 'configs', 'preheat') From 2dde3f38baae96ec6257a96bcb1b17580f3f5e38 Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Wed, 6 Oct 2021 22:51:41 +0200 Subject: [PATCH 5/6] Catch error while shut down kernel in pool --- tests/voila.json | 4 +++- voila/voila_kernel_manager.py | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/voila.json b/tests/voila.json index 3e08ac6e5..0b090e59e 100644 --- a/tests/voila.json +++ b/tests/voila.json @@ -2,7 +2,9 @@ "VoilaKernelManager": { "preheat_blacklist": [ "notebooks/autokill.ipynb", - "notebooks/many_iopub_messages.ipynb" + "notebooks/many_iopub_messages.ipynb", + "notebooks/sleep.ipynb", + "notebooks/sleep10seconds.ipynb" ] } } diff --git a/voila/voila_kernel_manager.py b/voila/voila_kernel_manager.py index 47b676fed..7e8a99cb3 100644 --- a/voila/voila_kernel_manager.py +++ b/voila/voila_kernel_manager.py @@ -254,9 +254,12 @@ async def shutdown_all(self, *args, **kwargs): else: kid = result['kernel_id'] if kid in self: - await ensure_async( - self.shutdown_kernel(kid, *args, **kwargs) - ) + try: + await ensure_async( + self.shutdown_kernel(kid, *args, **kwargs) + ) + except RuntimeError: + pass # Kernel is not running async def _initialize( self, notebook_path: str, kernel_id: str = None, **kwargs) -> str: @@ -332,7 +335,6 @@ def _notebook_filter(self, nb_path: Path) -> bool: nb_name = str(nb_path) if '.ipynb_checkpoints' in nb_name: return False - print('self.preheat_blacklist', self.preheat_blacklist) for nb_pattern in self.preheat_blacklist: pattern = re.compile(nb_pattern) if (nb_pattern in nb_name) or bool(pattern.match(nb_name)): From 381f3543a38e4832dd6247f41ced4002e6f4fe66 Mon Sep 17 00:00:00 2001 From: Duc Trung LE Date: Thu, 7 Oct 2021 22:11:50 +0200 Subject: [PATCH 6/6] Disable preheat mode for old tests --- tests/app/cgi-test.py | 3 +-- tests/app/config_paths_test.py | 4 ++-- tests/app/conftest.py | 21 ++++++--------------- tests/app/cwd_subdir_test.py | 4 ++-- tests/app/cwd_test.py | 4 ++-- tests/app/execute_cpp_test.py | 4 ++-- tests/app/execute_test.py | 8 ++++---- tests/app/image_inlining_test.py | 4 ++-- tests/app/kernel_death_test.py | 4 ++-- tests/app/nbextensions_test.py | 4 ++-- tests/app/no_kernelspec_test.py | 4 ++-- tests/app/no_metadata.py | 4 ++-- tests/app/no_strip_sources_test.py | 4 ++-- tests/app/non_existing_kernel_test.py | 4 ++-- tests/app/notebooks_test.py | 4 ++-- tests/app/preprocessor_test.py | 4 ++-- tests/app/show_traceback_test.py | 4 ++-- tests/app/shutdown_kernel_test.py | 4 ++-- tests/app/syntax_error_test.py | 4 ++-- tests/app/template_arg_test.py | 4 ++-- tests/app/template_cli_test.py | 4 ++-- tests/app/template_config_file_test.py | 4 ++-- tests/app/template_custom_test.py | 4 ++-- tests/app/template_sanity_test.py | 4 ++-- tests/app/timeout_test.py | 4 ++-- tests/voila.json | 10 ---------- 26 files changed, 55 insertions(+), 75 deletions(-) delete mode 100644 tests/voila.json diff --git a/tests/app/cgi-test.py b/tests/app/cgi-test.py index 07b589b7f..f2ccae0aa 100644 --- a/tests/app/cgi-test.py +++ b/tests/app/cgi-test.py @@ -17,8 +17,7 @@ def voila_args(notebook_directory, voila_args_extra): 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 diff --git a/tests/app/config_paths_test.py b/tests/app/config_paths_test.py index f75a149eb..3f35e0831 100644 --- a/tests/app/config_paths_test.py +++ b/tests/app/config_paths_test.py @@ -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') diff --git a/tests/app/conftest.py b/tests/app/conftest.py index 81cc0f412..f8621f15a 100644 --- a/tests/app/conftest.py +++ b/tests/app/conftest.py @@ -1,7 +1,7 @@ import os import pytest import voila.app -import asyncio + BASE_DIR = os.path.dirname(__file__) @@ -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 @@ -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=3): - if preheat_mode: - await asyncio.sleep(time) - return inner diff --git a/tests/app/cwd_subdir_test.py b/tests/app/cwd_subdir_test.py index 93f437512..9f2688163 100644 --- a/tests/app/cwd_subdir_test.py +++ b/tests/app/cwd_subdir_test.py @@ -18,9 +18,9 @@ def voila_args(notebook_directory, 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 diff --git a/tests/app/cwd_test.py b/tests/app/cwd_test.py index 6ea702668..8664a4c30 100644 --- a/tests/app/cwd_test.py +++ b/tests/app/cwd_test.py @@ -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 diff --git a/tests/app/execute_cpp_test.py b/tests/app/execute_cpp_test.py index 0aeb08985..b58098da9 100644 --- a/tests/app/execute_cpp_test.py +++ b/tests/app/execute_cpp_test.py @@ -21,8 +21,8 @@ def voila_args(notebook_directory, voila_args_extra, preheat_mode): @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') diff --git a/tests/app/execute_test.py b/tests/app/execute_test.py index 8482f8d2c..301aec4b3 100644 --- a/tests/app/execute_test.py +++ b/tests/app/execute_test.py @@ -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') @@ -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-]+)["']""" diff --git a/tests/app/image_inlining_test.py b/tests/app/image_inlining_test.py index 7dd1aa85a..217fd3aa2 100644 --- a/tests/app/image_inlining_test.py +++ b/tests/app/image_inlining_test.py @@ -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') diff --git a/tests/app/kernel_death_test.py b/tests/app/kernel_death_test.py index 9fa7a43f7..a37fc366e 100644 --- a/tests/app/kernel_death_test.py +++ b/tests/app/kernel_death_test.py @@ -18,8 +18,8 @@ def preheat_mode(): return False -async def test_kernel_death(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +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 diff --git a/tests/app/nbextensions_test.py b/tests/app/nbextensions_test.py index 1e6b2b408..4241e17f6 100644 --- a/tests/app/nbextensions_test.py +++ b/tests/app/nbextensions_test.py @@ -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') diff --git a/tests/app/no_kernelspec_test.py b/tests/app/no_kernelspec_test.py index fba1d39e5..1756b990a 100644 --- a/tests/app/no_kernelspec_test.py +++ b/tests/app/no_kernelspec_test.py @@ -15,8 +15,8 @@ def voila_args(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') diff --git a/tests/app/no_metadata.py b/tests/app/no_metadata.py index 168d7866f..8ddf6d97c 100644 --- a/tests/app/no_metadata.py +++ b/tests/app/no_metadata.py @@ -15,9 +15,9 @@ def voila_args(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') diff --git a/tests/app/no_strip_sources_test.py b/tests/app/no_strip_sources_test.py index 20b647940..b983a1dae 100644 --- a/tests/app/no_strip_sources_test.py +++ b/tests/app/no_strip_sources_test.py @@ -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') diff --git a/tests/app/non_existing_kernel_test.py b/tests/app/non_existing_kernel_test.py index 9a9ef7227..d48d82153 100644 --- a/tests/app/non_existing_kernel_test.py +++ b/tests/app/non_existing_kernel_test.py @@ -13,9 +13,9 @@ def voila_args(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") diff --git a/tests/app/notebooks_test.py b/tests/app/notebooks_test.py index 68554a198..b53eb050c 100644 --- a/tests/app/notebooks_test.py +++ b/tests/app/notebooks_test.py @@ -18,9 +18,9 @@ def voila_args(notebook_directory, 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 diff --git a/tests/app/preprocessor_test.py b/tests/app/preprocessor_test.py index 775eef870..aeb895533 100644 --- a/tests/app/preprocessor_test.py +++ b/tests/app/preprocessor_test.py @@ -13,8 +13,8 @@ def voila_args_extra(): return ['--template=skip_template'] -async def test_markdown_preprocessor(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_markdown_preprocessor(http_server_client, base_url): + response = await http_server_client.fetch(base_url) assert response.code == 200 html_text = response.body.decode('utf-8') diff --git a/tests/app/show_traceback_test.py b/tests/app/show_traceback_test.py index 491932b37..b5b4198fa 100644 --- a/tests/app/show_traceback_test.py +++ b/tests/app/show_traceback_test.py @@ -22,9 +22,9 @@ def voila_args(notebook_directory, voila_args_extra, show_tracebacks): async def test_syntax_error( - http_server_client, notebook_show_traceback_path, show_tracebacks, wait_for_kernel + http_server_client, notebook_show_traceback_path, show_tracebacks ): - await wait_for_kernel() + response = await http_server_client.fetch(notebook_show_traceback_path) assert response.code == 200 output = response.body.decode('utf-8') diff --git a/tests/app/shutdown_kernel_test.py b/tests/app/shutdown_kernel_test.py index 063fbf9d1..b3dae9520 100644 --- a/tests/app/shutdown_kernel_test.py +++ b/tests/app/shutdown_kernel_test.py @@ -1,8 +1,8 @@ import re -async def test_shutdown_handler(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_shutdown_handler(http_server_client, base_url): + response = await http_server_client.fetch(base_url) html_text = response.body.decode('utf-8') pattern = r"""kernelId": ["']([0-9a-zA-Z-]+)["']""" diff --git a/tests/app/syntax_error_test.py b/tests/app/syntax_error_test.py index 43e7afcd7..0206d3f53 100644 --- a/tests/app/syntax_error_test.py +++ b/tests/app/syntax_error_test.py @@ -10,8 +10,8 @@ def voila_notebook(notebook_directory): return os.path.join(notebook_directory, NOTEBOOK_PATH) -async def test_syntax_error(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_syntax_error(http_server_client, base_url): + response = await http_server_client.fetch(base_url) assert response.code == 200 output = response.body.decode('utf-8') diff --git a/tests/app/template_arg_test.py b/tests/app/template_arg_test.py index 7011e7f33..8cfe5a859 100644 --- a/tests/app/template_arg_test.py +++ b/tests/app/template_arg_test.py @@ -7,8 +7,8 @@ def voila_args_extra(): return ['--template=test_template', '--VoilaExecutor.timeout=240'] -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') diff --git a/tests/app/template_cli_test.py b/tests/app/template_cli_test.py index bf72a4420..0797859f5 100644 --- a/tests/app/template_cli_test.py +++ b/tests/app/template_cli_test.py @@ -13,8 +13,8 @@ def voila_args_extra(): return ['--template=test_template', '--VoilaTest.template_paths=[%r, %r]' % (path_test_template, path_default), '--VoilaExecutor.timeout=240'] -async def test_template_test(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_template_test(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') diff --git a/tests/app/template_config_file_test.py b/tests/app/template_config_file_test.py index fbc1fdb00..e520c01a4 100644 --- a/tests/app/template_config_file_test.py +++ b/tests/app/template_config_file_test.py @@ -13,8 +13,8 @@ def voila_args_extra(): return ['--template=test_template', '--Voila.nbconvert_template_paths=[%r, %r]' % (path_test_template, path_default), '--VoilaExecutor.timeout=240'] -async def test_template_test(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_template_test(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') diff --git a/tests/app/template_custom_test.py b/tests/app/template_custom_test.py index e395eba24..ff3e6d467 100644 --- a/tests/app/template_custom_test.py +++ b/tests/app/template_custom_test.py @@ -21,8 +21,8 @@ def config(app): return config -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') diff --git a/tests/app/template_sanity_test.py b/tests/app/template_sanity_test.py index 8aa934ecb..faa534046 100644 --- a/tests/app/template_sanity_test.py +++ b/tests/app/template_sanity_test.py @@ -11,8 +11,8 @@ def voila_args_extra(request): return [f'--template={request.param}'] -async def test_lists_extension(http_server_client, base_url, voila_app, wait_for_kernel): - await wait_for_kernel() +async def test_lists_extension(http_server_client, base_url, voila_app): + response = await http_server_client.fetch(base_url) assert response.code == 200 html_text = response.body.decode('utf-8') diff --git a/tests/app/timeout_test.py b/tests/app/timeout_test.py index c33d1b47f..472691310 100644 --- a/tests/app/timeout_test.py +++ b/tests/app/timeout_test.py @@ -13,8 +13,8 @@ def voila_args_extra(): return ['--VoilaExecutor.timeout=1', '--KernelManager.shutdown_wait_time=0.1'] -async def test_timeout(http_server_client, base_url, wait_for_kernel): - await wait_for_kernel() +async def test_timeout(http_server_client, base_url): + response = await http_server_client.fetch(base_url) html_text = response.body.decode('utf-8') assert 'Cell execution timed out' in html_text diff --git a/tests/voila.json b/tests/voila.json deleted file mode 100644 index 0b090e59e..000000000 --- a/tests/voila.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "VoilaKernelManager": { - "preheat_blacklist": [ - "notebooks/autokill.ipynb", - "notebooks/many_iopub_messages.ipynb", - "notebooks/sleep.ipynb", - "notebooks/sleep10seconds.ipynb" - ] - } -}