forked from voila-dashboards/voila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for multiple notebooks case
- Loading branch information
1 parent
9de5fdc
commit c69c70b
Showing
7 changed files
with
143 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import pytest | ||
import time | ||
import asyncio | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
NOTEBOOK_EXECUTION_TIME = 2 | ||
NUMBER_PREHEATED_KERNEL = 2 | ||
|
||
|
||
@pytest.fixture | ||
def voila_config_file_paths_arg(): | ||
path = os.path.join(BASE_DIR, '..', 'configs', 'preheat') | ||
return '--VoilaTest.config_file_paths=[%r]' % path | ||
|
||
|
||
@pytest.fixture | ||
def preheat_mode(): | ||
return True | ||
|
||
|
||
@pytest.fixture | ||
def voila_notebook(notebook_directory): | ||
return os.path.join(notebook_directory, 'preheat') | ||
|
||
|
||
async def send_request(sc, url, wait=0): | ||
await asyncio.sleep(wait) | ||
real_time = time.time() | ||
response = await sc.fetch(url) | ||
real_time = time.time() - real_time | ||
html_text = response.body.decode("utf-8") | ||
return real_time, html_text | ||
|
||
|
||
async def test_render_notebook_with_heated_kernel(http_server_client, base_url): | ||
await asyncio.sleep(NUMBER_PREHEATED_KERNEL*NOTEBOOK_EXECUTION_TIME + 1) | ||
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 | ||
|
||
|
||
async def test_render_blacklisted_notebook_with_nornal_kernel(http_server_client, base_url): | ||
await asyncio.sleep(NUMBER_PREHEATED_KERNEL*NOTEBOOK_EXECUTION_TIME + 1) | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7efe3e8f-4b8d-4fd3-99d1-b06d79b88ae2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import time\n", | ||
"time.sleep(2)\n", | ||
"print('hello world')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "782377cd-2bc0-4d0d-8b63-74dcb7e9d645", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.getenv('foo')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0e689ec5-708c-4cac-98ba-02b00411e41d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters