Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Mar 15, 2019
1 parent 932c37c commit 08b75cf
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 7 deletions.
Empty file added tests/app/__init__.py
Empty file.
12 changes: 8 additions & 4 deletions tests/conftest.py → tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ def voila_config():


@pytest.fixture
def voila_notebook():
return os.path.join(BASE_DIR, 'notebooks/print.ipynb')
def voila_notebook(voila_notebook_dir):
return os.path.join(voila_notebook_dir, 'print.ipynb')

@pytest.fixture
def voila_notebook_dir():
return os.path.join(BASE_DIR, '../notebooks')


@pytest.fixture
Expand All @@ -38,8 +42,8 @@ def voila_app(voila_args, voila_config):
voila_app.initialize(voila_args)
voila_config(voila_app)
voila_app.start()
return voila_app

yield voila_app
voila_app.clear_instance()

@pytest.fixture
def app(voila_app):
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions tests/app/nbextensions_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# tests programmatic config of template sytem
import pytest
import os

BASE_DIR = os.path.dirname(__file__)

@pytest.fixture
def voila_config():
def config(app):
pass
os.environ['JUPYTER_CONFIG_DIR'] = os.path.join(BASE_DIR, '../configs/general')
yield config
del os.environ['JUPYTER_CONFIG_DIR']


@pytest.mark.gen_test
def test_lists_extension(http_client, base_url):
response = yield http_client.fetch(base_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
assert 'Hi Voila' in html_text
assert 'ipytest/extension.js' in html_text
14 changes: 14 additions & 0 deletions tests/app/serve_directory_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# test serving a notebook
import pytest

@pytest.fixture
def voila_args(voila_notebook_dir, voila_args_extra):
return ['--VoilaApp.root_dir=%r' % voila_notebook_dir, voila_notebook_dir, '--VoilaApp.log_level=DEBUG'] + voila_args_extra


@pytest.mark.gen_test
def test_hello_world(http_client, base_url):
response = yield http_client.fetch(base_url + 'voila/render/print')
assert response.code == 200
assert 'Hi Voila' in response.body.decode('utf-8')

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def voila_args_extra():
@pytest.fixture
def voila_config():
def config(app):
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../share/jupyter/voila/template/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../share/jupyter/voila/template/default/nbconvert_templates'))
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/default/nbconvert_templates'))
app.nbconvert_template_paths = [path_gridstack, path_default]
path = os.path.abspath(os.path.join(BASE_DIR, '../share/jupyter/voila/template/default/templates'))
path = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/default/templates'))
app.template_paths = [path]

return config
Expand Down
File renamed without changes.
Empty file added tests/server/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions tests/server/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os

import pytest
from jupyter_server.serverapp import ServerApp
from tornado import httpserver


BASE_DIR = os.path.dirname(__file__)


@pytest.fixture
def jupyter_server_config():
return lambda app: None


@pytest.fixture
def jupyter_server_notebook():
return os.path.join(BASE_DIR, '../notebooks')


@pytest.fixture
def jupyter_server_args_extra():
return []


@pytest.fixture
def print_notebook_url(base_url):
return base_url + "/voila/render/print"


@pytest.fixture
def jupyter_server_args(jupyter_server_notebook, jupyter_server_args_extra):
debug_args = ['--ServerApp.log_level=DEBUG'] if os.environ.get('VOILA_TEST_DEBUG', False) else []
default_args = ['--ServerApp.token=""']
return [jupyter_server_notebook] + jupyter_server_args_extra + debug_args + default_args


@pytest.fixture
def jupyter_server_app(jupyter_server_args, jupyter_server_config):
jupyter_server_app = ServerApp.instance()
# we monkey patch
old_listen = httpserver.HTTPServer.listen
httpserver.HTTPServer.listen = lambda *x, **y: None
# NOTE: in voila's conftest.py we call config after initialize
jupyter_server_config(jupyter_server_app)
jupyter_server_app.initialize(jupyter_server_args)
yield jupyter_server_app
httpserver.HTTPServer.listen = old_listen
ServerApp.clear_instance()




@pytest.fixture
def app(jupyter_server_app):
return jupyter_server_app.web_app


20 changes: 20 additions & 0 deletions tests/server/execute_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# test basics of voila running a notebook
import pytest
import tornado.web
import tornado.gen
import re
import json

try:
from unittest import mock
except:
import mock


@pytest.mark.gen_test
def test_hello_world(http_client, print_notebook_url):
response = yield http_client.fetch(print_notebook_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
assert 'Hi Voila' in html_text
assert 'gridstack.css' not in html_text, "gridstack should not be the default"
22 changes: 22 additions & 0 deletions tests/server/nbextensions_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# tests programmatic config of template sytem
import pytest
import os

BASE_DIR = os.path.dirname(__file__)

@pytest.fixture
def jupyter_server_config():
def config(app):
pass
os.environ['JUPYTER_CONFIG_DIR'] = os.path.join(BASE_DIR, 'configs', 'general')
yield config
del os.environ['JUPYTER_CONFIG_DIR']

@pytest.mark.xfail(reason='needs to be fixed')
@pytest.mark.gen_test
def test_lists_extension(http_client, print_notebook_url):
response = yield http_client.fetch(print_notebook_url)
assert response.code == 200
html_text = response.body.decode('utf-8')
assert 'Hi Voila' in html_text
assert 'ipytest/extension.js' in html_text

0 comments on commit 08b75cf

Please sign in to comment.