-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* simplify tests for jupyter plugin * Run jupyter tests separately with proper dependencies
- Loading branch information
1 parent
cf7ed63
commit 50fdb2a
Showing
6 changed files
with
77 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ pytest | |
pytest-xdist | ||
pytest-cov | ||
sphinx-rtd-theme | ||
|
||
# jupyter | ||
jupyter_server | ||
nest_asyncio |
Empty file.
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 |
---|---|---|
@@ -1,74 +1,20 @@ | ||
import sys | ||
from multiprocessing.shared_memory import SharedMemory | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture() | ||
def replace_modules(): | ||
mocked_modules = {} | ||
|
||
def replace(modules: dict): | ||
for module, mock in modules.items(): | ||
assert module not in sys.modules | ||
sys.modules[module] = mock | ||
mocked_modules[module] = mock | ||
|
||
yield replace | ||
for m in mocked_modules: | ||
sys.modules.pop(m) | ||
|
||
|
||
@pytest.fixture() | ||
def tornado_mock(replace_modules): | ||
replace_modules({"tornado.web": MagicMock(authenticated=lambda x: x)}) | ||
|
||
|
||
@pytest.fixture() | ||
def jupyter_module_mock(replace_modules, tornado_mock): | ||
jupyter_mock = MagicMock() | ||
utils = jupyter_mock.utils | ||
serverapp = jupyter_mock.serverapp | ||
base_handlers = jupyter_mock.base.handlers | ||
|
||
utils.url_path_join = lambda *args: "/".join(args) | ||
base_handlers.APIHandler = object | ||
|
||
replace_modules( | ||
{ | ||
"jupyter_server.base.handlers": base_handlers, | ||
"jupyter_server.serverapp": serverapp, | ||
"jupyter_server.utils": utils, | ||
} | ||
) | ||
return jupyter_mock | ||
|
||
|
||
@pytest.fixture() | ||
def nest_asyncio_mock(replace_modules): | ||
mock = MagicMock() | ||
mock.authenticated = lambda x: x | ||
replace_modules({"nest_asyncio": mock}) | ||
return mock | ||
from boa.integrations.jupyter.browser import _generate_token | ||
from boa.integrations.jupyter.constants import SHARED_MEMORY_LENGTH | ||
|
||
|
||
@pytest.fixture() | ||
def shared_memory_length(nest_asyncio_mock): | ||
from boa.integrations.jupyter.constants import SHARED_MEMORY_LENGTH | ||
|
||
return SHARED_MEMORY_LENGTH | ||
|
||
|
||
@pytest.fixture() | ||
def token(nest_asyncio_mock, jupyter_module_mock): | ||
from boa.integrations.jupyter.browser import _generate_token | ||
|
||
def token(): | ||
return _generate_token() | ||
|
||
|
||
@pytest.fixture() | ||
def shared_memory(token, shared_memory_length): | ||
memory = SharedMemory(name=token, create=True, size=shared_memory_length) | ||
yield memory | ||
memory.unlink() | ||
def shared_memory(token): | ||
memory = SharedMemory(name=token, create=True, size=SHARED_MEMORY_LENGTH) | ||
try: | ||
yield memory | ||
finally: | ||
memory.unlink() |
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
Oops, something went wrong.