Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch fixtures to use those in pytest-jupyter to avoid collisions #335

Merged
merged 5 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
"pywin32>=1.0 ; sys_platform == 'win32'"
],
extras_require = {
'test': ['nose', 'coverage', 'requests', 'nose_warnings_filters',
'pytest', 'pytest-cov', 'pytest-tornasync',
'test': ['coverage', 'requests',
'pytest', 'pytest-cov', 'pytest-jupyter',
'pytest-console-scripts', 'ipykernel'],
'test:sys_platform == "win32"': ['nose-exclude'],
},
python_requires = '>=3.6',
entry_points = {
Expand Down
1 change: 0 additions & 1 deletion tests/conftest.py

This file was deleted.

12 changes: 6 additions & 6 deletions tests/extension/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@


@pytest.fixture
def mock_template(template_dir):
index = template_dir.joinpath('index.html')
def mock_template(jp_template_dir):
index = jp_template_dir.joinpath('index.html')
index.write_text(mock_html)


@pytest.fixture
def extension_manager(serverapp):
return serverapp.extension_manager
def extension_manager(jp_serverapp):
return jp_serverapp.extension_manager


@pytest.fixture
def config_file(config_dir):
def config_file(jp_config_dir):
""""""
f = config_dir.joinpath("jupyter_mockextension_config.py")
f = jp_config_dir.joinpath("jupyter_mockextension_config.py")
f.write_text("c.MockExtensionApp.mock_trait ='config from file'")
return f
19 changes: 10 additions & 9 deletions tests/extension/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@pytest.fixture
def server_config(template_dir):
def jp_server_config(jp_template_dir):
config = {
"ServerApp": {
"jpserver_extensions": {
Expand All @@ -12,7 +12,7 @@ def server_config(template_dir):
},
"MockExtensionApp": {
"template_paths": [
str(template_dir)
str(jp_template_dir)
],
"log_level": 'DEBUG'
}
Expand All @@ -29,40 +29,41 @@ def mock_extension(extension_manager):
return app


def test_initialize(serverapp, template_dir, mock_extension):
def test_initialize(jp_serverapp, jp_template_dir, mock_extension):
# Check that settings and handlers were added to the mock extension.
assert isinstance(mock_extension.serverapp, ServerApp)
assert len(mock_extension.handlers) > 0
assert mock_extension.loaded
assert mock_extension.template_paths == [str(template_dir)]
assert mock_extension.template_paths == [str(jp_template_dir)]


@pytest.mark.parametrize(
'trait_name, trait_value, argv',
'trait_name, trait_value, jp_argv',
(
[
'mock_trait',
'test mock trait',
['--MockExtensionApp.mock_trait="test mock trait"']
['--MockExtensionApp.mock_trait=test mock trait']
],
)
)
def test_instance_creation_with_argv(
trait_name,
trait_value,
jp_argv,
mock_extension,
):
assert getattr(mock_extension, trait_name) == trait_value


def test_extensionapp_load_config_file(
config_file,
serverapp,
jp_serverapp,
mock_extension,
):
# Assert default config_file_paths is the same in the app and extension.
assert mock_extension.config_file_paths == serverapp.config_file_paths
assert mock_extension.config_dir == serverapp.config_dir
assert mock_extension.config_file_paths == jp_serverapp.config_file_paths
assert mock_extension.config_dir == jp_serverapp.config_dir
assert mock_extension.config_file_name == 'jupyter_mockextension_config'
# Assert that the trait is updated by config file
assert mock_extension.mock_trait == 'config from file'
6 changes: 3 additions & 3 deletions tests/extension/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# Use ServerApps environment because it monkeypatches
# jupyter_core.paths and provides a config directory
# that's not cross contaminating the user config directory.
pytestmark = pytest.mark.usefixtures("environ")
pytestmark = pytest.mark.usefixtures("jp_environ")


@pytest.fixture
def configd(env_config_path):
def configd(jp_env_config_path):
"""A pathlib.Path object that acts like a jupyter_server_config.d folder."""
configd = env_config_path.joinpath('jupyter_server_config.d')
configd = jp_env_config_path.joinpath('jupyter_server_config.d')
configd.mkdir()
return configd

Expand Down
2 changes: 1 addition & 1 deletion tests/extension/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pytestmark = pytest.mark.script_launch_mode('subprocess')


def test_server_extension_list(environ, script_runner):
def test_server_extension_list(jp_environ, script_runner):
ret = script_runner.run(
'jupyter',
'server',
Expand Down
32 changes: 16 additions & 16 deletions tests/extension/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


@pytest.fixture
def server_config(template_dir):
def jp_server_config(jp_template_dir):
return {
"ServerApp": {
"jpserver_extensions": {
Expand All @@ -11,31 +11,31 @@ def server_config(template_dir):
},
"MockExtensionApp": {
"template_paths": [
str(template_dir)
str(jp_template_dir)
]
}
}


async def test_handler(fetch):
r = await fetch(
async def test_handler(jp_fetch):
r = await jp_fetch(
'mock',
method='GET'
)
assert r.code == 200
assert r.body.decode() == 'mock trait'


async def test_handler_template(fetch, mock_template):
r = await fetch(
async def test_handler_template(jp_fetch, mock_template):
r = await jp_fetch(
'mock_template',
method='GET'
)
assert r.code == 200


@pytest.mark.parametrize(
'server_config',
'jp_server_config',
[
{
"ServerApp": {
Expand All @@ -51,9 +51,9 @@ async def test_handler_template(fetch, mock_template):
}
]
)
async def test_handler_setting(fetch):
async def test_handler_setting(jp_fetch):
# Test that the extension trait was picked up by the webapp.
r = await fetch(
r = await jp_fetch(
'mock',
method='GET'
)
Expand All @@ -62,11 +62,11 @@ async def test_handler_setting(fetch):


@pytest.mark.parametrize(
'argv', (['--MockExtensionApp.mock_trait="test mock trait"'],)
'jp_argv', (['--MockExtensionApp.mock_trait=test mock trait'],)
)
async def test_handler_argv(fetch):
async def test_handler_argv(jp_fetch):
# Test that the extension trait was picked up by the webapp.
r = await fetch(
r = await jp_fetch(
'mock',
method='GET'
)
Expand All @@ -75,7 +75,7 @@ async def test_handler_argv(fetch):


@pytest.mark.parametrize(
'server_config',
'jp_server_config',
[
{
"ServerApp": {
Expand All @@ -93,17 +93,17 @@ async def test_handler_argv(fetch):
}
]
)
async def test_base_url(fetch):
async def test_base_url(jp_fetch):
# Test that the extension's handlers were properly prefixed
r = await fetch(
r = await jp_fetch(
'test_prefix', 'mock',
method='GET'
)
assert r.code == 200
assert r.body.decode() == 'test mock trait'

# Test that the static namespace was prefixed by base_url
r = await fetch(
r = await jp_fetch(
'test_prefix',
'static', 'mockextension', 'mock.txt',
method='GET'
Expand Down
6 changes: 3 additions & 3 deletions tests/extension/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Use ServerApps environment because it monkeypatches
# jupyter_core.paths and provides a config directory
# that's not cross contaminating the user config directory.
pytestmark = pytest.mark.usefixtures("environ")
pytestmark = pytest.mark.usefixtures("jp_environ")


def test_extension_point_api():
Expand Down Expand Up @@ -76,9 +76,9 @@ def test_extension_manager_api():
assert "tests.extension.mockextensions" in manager.extensions


def test_extension_manager_linked_extensions(serverapp):
def test_extension_manager_linked_extensions(jp_serverapp):
name = "tests.extension.mockextensions"
manager = ExtensionManager()
manager.add_extension(name, enabled=True)
manager.link_extension(name, serverapp)
manager.link_extension(name, jp_serverapp)
assert name in manager.linked_extensions
26 changes: 13 additions & 13 deletions tests/extension/test_serverextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Use ServerApps environment because it monkeypatches
# jupyter_core.paths and provides a config directory
# that's not cross contaminating the user config directory.
pytestmark = pytest.mark.usefixtures("environ")
pytestmark = pytest.mark.usefixtures("jp_environ")


def test_help_output():
Expand All @@ -29,13 +29,13 @@ def get_config(sys_prefix=True):
return data.get("ServerApp", {}).get("jpserver_extensions", {})


def test_enable(env_config_path, extension_environ):
def test_enable(jp_env_config_path, jp_extension_environ):
toggle_server_extension_python('mock1', True)
config = get_config()
assert config['mock1']


def test_disable(env_config_path, extension_environ):
def test_disable(jp_env_config_path, jp_extension_environ):
toggle_server_extension_python('mock1', True)
toggle_server_extension_python('mock1', False)

Expand All @@ -44,9 +44,9 @@ def test_disable(env_config_path, extension_environ):


def test_merge_config(
env_config_path,
configurable_serverapp,
extension_environ
jp_env_config_path,
jp_configurable_serverapp,
jp_extension_environ
):
# Toggle each extension module with a JSON config file
# at the sys-prefix config dir.
Expand Down Expand Up @@ -80,8 +80,8 @@ def test_merge_config(
)

# Enable the last extension, mockext_py, using the CLI interface.
app = configurable_serverapp(
config_dir=str(env_config_path),
app = jp_configurable_serverapp(
config_dir=str(jp_env_config_path),
argv=[arg]
)
# Verify that extensions are enabled and merged in proper order.
Expand All @@ -94,7 +94,7 @@ def test_merge_config(


@pytest.mark.parametrize(
'server_config',
'jp_server_config',
[
{
"ServerApp": {
Expand All @@ -106,7 +106,7 @@ def test_merge_config(
}
]
)
def test_load_ordered(serverapp):
assert serverapp.mockII is True, "Mock II should have been loaded"
assert serverapp.mockI is True, "Mock I should have been loaded"
assert serverapp.mock_shared == 'II', "Mock II should be loaded after Mock I"
def test_load_ordered(jp_serverapp):
assert jp_serverapp.mockII is True, "Mock II should have been loaded"
assert jp_serverapp.mockI is True, "Mock I should have been loaded"
assert jp_serverapp.mock_shared == 'II', "Mock II should be loaded after Mock I"
2 changes: 1 addition & 1 deletion tests/extension/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Use ServerApps environment because it monkeypatches
# jupyter_core.paths and provides a config directory
# that's not cross contaminating the user config directory.
pytestmark = pytest.mark.usefixtures("environ")
pytestmark = pytest.mark.usefixtures("jp_environ")


def test_validate_extension():
Expand Down
Loading