Skip to content

Commit

Permalink
Move fixtures into their own module; complete review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpacer committed Jun 24, 2019
1 parent bbf64ab commit 74d15da
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 60 deletions.
62 changes: 62 additions & 0 deletions bookstore/tests/client/client_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest

from bookstore.client.nb_client import NotebookSession, KernelInfo, LiveNotebookRecord


@pytest.fixture
def notebook_server_dict():
notebook_server_dict = {
"base_url": "/",
"hostname": "localhost",
"notebook_dir": "/Users/username",
"password": False,
"pid": 20981,
"port": 8888,
"secure": False,
"token": "e5814788aeef225172364fcdf1240b90729169a2ced375c7",
"url": "http://localhost:8888/",
}
return notebook_server_dict


@pytest.fixture
def notebook_server_record(notebook_server_dict):
notebook_server_record = LiveNotebookRecord(**notebook_server_dict)
return notebook_server_record


@pytest.fixture(scope="module")
def kernel_info_dict():
info_dict = {
"id": 'f92b7c8b-0858-4d10-903c-b0631540fb36',
"name": 'dev',
"last_activity": '2019-03-14T23:38:08.137987Z',
"execution_state": 'idle',
"connections": 0,
}
return info_dict


@pytest.fixture(scope="module")
def kernel_info(kernel_info_dict):
kernel_info = KernelInfo(**kernel_info_dict)
return kernel_info


@pytest.fixture
def session_dict(kernel_info_dict):
session_dict = {
"id": '68d9c58f-c57d-4133-8b41-5ec2731b268d',
"path": 'Untitled38.ipynb',
"name": '',
"type": 'notebook',
"kernel": kernel_info_dict,
"notebook": {'path': 'Untitled38.ipynb', 'name': ''}, # deprecated API
}
return session_dict


@pytest.fixture
def notebook_session(session_dict):
notebook_session = NotebookSession(**session_dict)
return notebook_session
62 changes: 2 additions & 60 deletions bookstore/tests/client/test_nb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,7 @@
LiveNotebookRecord,
)


@pytest.fixture
def notebook_server_dict():
notebook_server_dict = {
"base_url": "/",
"hostname": "localhost",
"notebook_dir": "/Users/username",
"password": False,
"pid": 20981,
"port": 8888,
"secure": False,
"token": "e5814788aeef225172364fcdf1240b90729169a2ced375c7",
"url": "http://localhost:8888/",
}
return notebook_server_dict


@pytest.fixture
def notebook_server_record(notebook_server_dict):
notebook_server_record = LiveNotebookRecord(**notebook_server_dict)
return notebook_server_record


@pytest.fixture(scope="module")
def kernel_info_dict():
info_dict = {
"id": 'f92b7c8b-0858-4d10-903c-b0631540fb36',
"name": 'dev',
"last_activity": '2019-03-14T23:38:08.137987Z',
"execution_state": 'idle',
"connections": 0,
}
return info_dict


@pytest.fixture(scope="module")
def kernel_info(kernel_info_dict):
kernel_info = KernelInfo(**kernel_info_dict)
return kernel_info


@pytest.fixture
def session_dict(kernel_info_dict):
session_dict = {
"id": '68d9c58f-c57d-4133-8b41-5ec2731b268d',
"path": 'Untitled38.ipynb',
"name": '',
"type": 'notebook',
"kernel": kernel_info_dict,
"notebook": {'path': 'Untitled38.ipynb', 'name': ''}, # deprecated API
}
return session_dict


@pytest.fixture
def notebook_session(session_dict):
notebook_session = NotebookSession(**session_dict)
return notebook_session
from bookstore.tests.client.client_fixtures import *


def test_notebook_server_record(notebook_server_record, notebook_server_dict):
Expand All @@ -90,7 +33,6 @@ def test_kernel_info_class(kernel_info_dict, kernel_info):


def test_notebook_session_class(notebook_session, session_dict):
# assert notebook_session.id == session_dict['id'] # TODO: once id is re-added to NotebookSession's attributes readd this
assert notebook_session.path == session_dict["path"]
assert notebook_session.name == session_dict["name"]
assert notebook_session.type == session_dict['type']
Expand All @@ -113,4 +55,4 @@ def test_notebook_session_class(notebook_session, session_dict):
],
)
def test_extract_kernel_id(connection_file, expected_kernel_id):
assert expected_kernel_id == extract_kernel_id(connection_file)
assert extract_kernel_id(connection_file) == expected_kernel_id

0 comments on commit 74d15da

Please sign in to comment.