Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Aug 18, 2022
1 parent 3f94a14 commit a42b59c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
6 changes: 2 additions & 4 deletions panel/_templates/kernel_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@
<fast-design-system-provider id="header-design-provider" use-defaults background-color="#000000">
<section class="header">
<div class="header-grid">
<h1>
<fast-anchor id="title" href="https://panel.holoviz.org" appearance="neutral" target="_self"><img id="panel-logo" src="https://panel.holoviz.org/_static/logo_horizontal.png"/></fast-anchor>
<fast-tooltip anchor="title">Click to visit the Panel web site</fast-tooltip>
</h1>
<fast-anchor id="title" href="https://panel.holoviz.org" appearance="neutral" target="_self"><img id="panel-logo" src="https://panel.holoviz.org/_static/logo_horizontal.png"/></fast-anchor>
<fast-tooltip anchor="title">Click to visit the Panel web site</fast-tooltip>
<h1>Kernel Error: {{ error }}</h1>
</div>
</section>
Expand Down
28 changes: 28 additions & 0 deletions panel/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import re
import shutil
import tempfile
import time

from contextlib import contextmanager
from subprocess import PIPE, Popen

import pytest

Expand Down Expand Up @@ -250,3 +252,29 @@ def threads():
yield 4
finally:
config.nthreads = None

@pytest.fixture
def change_test_dir(request):
os.chdir(request.fspath.dirname)
yield
os.chdir(request.config.invocation_dir)

@pytest.fixture
def jupyter_server(port, change_test_dir):
process = Popen(['jupyter', 'server', '--port', str(port)], stdout=PIPE, stderr=PIPE, bufsize=1, encoding='utf-8')
os.set_blocking(process.stderr.fileno(), False)
while True:
for _ in range(2):
line = process.stderr.readline()
time.sleep(0.02)
if "http://127.0.0.1:" in line:
url = "http://127.0.0.1:"
break
if "http://localhost:" in line:
url = "http://localhost:"
break
port = int(line.split(url)[-1][:4])
PORT[0] = port
process.args[-1] = str(port)
yield process
process.kill()
12 changes: 12 additions & 0 deletions panel/tests/ui/io/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import panel as pn

button = pn.widgets.Button(name='Click')

string = pn.pane.Str(object=0, css_classes=['string'])

def cb(event):
string.object += 1

button.on_click(cb)

pn.Row(button, string).servable()
42 changes: 42 additions & 0 deletions panel/tests/ui/io/test_jupyter_server_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import sys
import time

import pytest

pytestmark = pytest.mark.ui

not_windows = pytest.mark.skipif(sys.platform=='win32', reason="Does not work on Windows")

@not_windows
def test_jupyter_server(page, jupyter_server):
port = jupyter_server.args[-1]

page.goto(f"http://localhost:{port}/panel-preview/render/app.py")

assert page.text_content('.bk.string') == '0'

page.click('.bk.bk-btn')
time.sleep(0.1)

assert page.text_content('.bk.string') == '1'

page.click('.bk.bk-btn')
time.sleep(0.1)

assert page.text_content('.bk.string') == '2'

@not_windows
def test_jupyter_server_kernel_error(page, jupyter_server):
port = jupyter_server.args[-1]

page.goto(f"http://localhost:{port}/panel-preview/render/app.py?kernel=blah")

assert page.text_content('h1') == 'Kernel Error: No such kernel blah'

page.select_option('select#kernel-select', 'python3')

assert page.text_content('.bk.string') == '0'
page.click('.bk.bk-btn')
time.sleep(0.1)

assert page.text_content('.bk.string') == '1'

0 comments on commit a42b59c

Please sign in to comment.