Skip to content

Commit d18194f

Browse files
committed
More complex handling of open_browser from extension applications
1 parent d07853e commit d18194f

File tree

10 files changed

+50
-10
lines changed

10 files changed

+50
-10
lines changed

.github/workflows/python-linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ jobs:
4545
- name: Run the tests
4646
if: ${{ matrix.python-version != 'pypy3' }}
4747
run: |
48-
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
48+
pytest -vv jupyter_server --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
4949
- name: Run the tests on pypy
5050
if: ${{ matrix.python-version == 'pypy3' }}
5151
run: |
52-
pytest -vv
52+
pytest -vv jupyter_server
5353
- name: Install the Python dependencies for the examples
5454
run: |
5555
cd examples/simple && pip install -e .

.github/workflows/python-macos.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ jobs:
4545
- name: Run the tests
4646
if: ${{ matrix.python-version != 'pypy3' }}
4747
run: |
48-
pytest -vv --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
48+
pytest -vv jupyter_server --cov jupyter_server --cov-branch --cov-report term-missing:skip-covered
4949
- name: Run the tests on pypy
5050
if: ${{ matrix.python-version == 'pypy3' }}
5151
run: |
52-
pytest -vv
52+
pytest -vv jupyter_server
5353
- name: Install the Python dependencies for the examples
5454
run: |
5555
cd examples/simple && pip install -e .

.github/workflows/python-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
# the file descriptions opened by the asyncio IOLoop.
5050
# This leads to a nasty, flaky race condition that we haven't
5151
# been able to solve.
52-
pytest -vv -s
52+
pytest -vv jupyter_server -s
5353
- name: Install the Python dependencies for the examples
5454
run: |
5555
cd examples/simple && pip install -e .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Launch with:
3838
To test an installed `jupyter_server`, run the following:
3939

4040
$ pip install jupyter_server[test]
41-
$ pytest --pyargs jupyter_server
41+
$ pytest jupyter_server
4242

4343
## Contributing
4444

jupyter_server/extension/application.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class method. This method can be set as a entry_point in
154154
# the default value to False if they don't offer a browser
155155
# based frontend.
156156
open_browser = Bool(
157-
True,
158157
help="""Whether to open in a browser after starting.
159158
The specific browser used is platform dependent and
160159
determined by the python standard library `webbrowser`
@@ -163,6 +162,10 @@ class method. This method can be set as a entry_point in
163162
"""
164163
).tag(config=True)
165164

165+
@default('open_browser')
166+
def _default_open_browser(self):
167+
return self.serverapp.config["ServerApp"].get("open_browser", True)
168+
166169
# The extension name used to name the jupyter config
167170
# file, jupyter_{name}_config.
168171
# This should also match the jupyter subcommand used to launch

jupyter_server/pytest_plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,9 @@ def inner(nbpath):
426426
nbtext = nbformat.writes(nb, version=4)
427427
nbpath.write_text(nbtext)
428428
return inner
429+
430+
431+
@pytest.fixture(autouse=True)
432+
def jp_server_cleanup():
433+
yield
434+
ServerApp.clear_instance()

jupyter_server/tests/extension/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from .mockextensions.app import MockExtensionApp
23

34

45
mock_html = """
@@ -41,4 +42,10 @@ def config_file(jp_config_dir):
4142
""""""
4243
f = jp_config_dir.joinpath("jupyter_mockextension_config.py")
4344
f.write_text("c.MockExtensionApp.mock_trait ='config from file'")
44-
return f
45+
return f
46+
47+
48+
@pytest.fixture(autouse=True)
49+
def jp_mockextension_cleanup():
50+
yield
51+
MockExtensionApp.clear_instance()

jupyter_server/tests/extension/mockextensions/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
4747
mock_trait = Unicode('mock trait', config=True)
4848
loaded = False
4949

50+
@staticmethod
51+
def get_extension_package():
52+
return "jupyter_server.tests.extension.mockextensions"
53+
5054
def initialize_handlers(self):
5155
self.handlers.append(('/mock', MockExtensionHandler))
5256
self.handlers.append(('/mock_template', MockExtensionTemplateHandler))

jupyter_server/tests/extension/test_app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
2+
from traitlets.config import Config
23
from jupyter_server.serverapp import ServerApp
4+
from .mockextensions.app import MockExtensionApp
35

46

57
@pytest.fixture
@@ -67,3 +69,23 @@ def test_extensionapp_load_config_file(
6769
assert mock_extension.config_file_name == 'jupyter_mockextension_config'
6870
# Assert that the trait is updated by config file
6971
assert mock_extension.mock_trait == 'config from file'
72+
73+
74+
OPEN_BROWSER_COMBINATIONS = (
75+
(True, {}),
76+
(True, {'ServerApp': {'open_browser': True}}),
77+
(False, {'ServerApp': {'open_browser': False}}),
78+
(True, {'MockExtensionApp': {'open_browser': True}}),
79+
(False, {'MockExtensionApp': {'open_browser': False}}),
80+
(True, {'ServerApp': {'open_browser': True}, 'MockExtensionApp': {'open_browser': True}}),
81+
(False, {'ServerApp': {'open_browser': True}, 'MockExtensionApp': {'open_browser': False}}),
82+
(True, {'ServerApp': {'open_browser': False}, 'MockExtensionApp': {'open_browser': True}}),
83+
(False, {'ServerApp': {'open_browser': False}, 'MockExtensionApp': {'open_browser': False}}),
84+
)
85+
86+
@pytest.mark.parametrize(
87+
'expected_value, config', OPEN_BROWSER_COMBINATIONS
88+
)
89+
def test_browser_open(monkeypatch, jp_environ, config, expected_value):
90+
serverapp = MockExtensionApp.initialize_server(config=Config(config))
91+
assert serverapp.open_browser == expected_value

pytest.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
[pytest]
22
# Exclude the example tests.
33
norecursedirs = examples/*
4-
# Work around for https://github.com/pytest-dev/pytest/issues/4039
5-
addopts = --pyargs jupyter_server

0 commit comments

Comments
 (0)