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

Test nb_client module #136

Merged
merged 9 commits into from
Jun 24, 2019
Merged

Test nb_client module #136

merged 9 commits into from
Jun 24, 2019

Conversation

mpacer
Copy link
Member

@mpacer mpacer commented Jun 15, 2019

This add unit tests for the record types and simple functions in nb_client.

It will either take some clever mocking or proper integration tests to properly handle the rest of the classes in this module.

Going through this made me wonder if we should split this module into an nb_types and and nb_client module… as this seemed to be a fairly clean delineation between the two types of functionality.

@mpacer mpacer requested a review from willingc June 15, 2019 03:01
@todo
Copy link

todo bot commented Jun 15, 2019

once id is re-added to NotebookSession's attributes readd this

# 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']
assert notebook_session.kernel == KernelInfo(**session_dict["kernel"])
assert notebook_session.notebook == session_dict["notebook"]


This comment was generated by todo based on a TODO comment in 60249b2 in #136. cc @mpacer.

@codecov
Copy link

codecov bot commented Jun 15, 2019

Codecov Report

Merging #136 into master will decrease coverage by 1.23%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #136      +/-   ##
==========================================
- Coverage   47.32%   46.09%   -1.24%     
==========================================
  Files          11       11              
  Lines         374      384      +10     
==========================================
  Hits          177      177              
- Misses        197      207      +10

@codecov
Copy link

codecov bot commented Jun 15, 2019

Codecov Report

Merging #136 into master will increase coverage by 18.34%.
The diff coverage is 81.81%.

@@            Coverage Diff             @@
##           master    #136       +/-   ##
==========================================
+ Coverage   50.25%   68.6%   +18.34%     
==========================================
  Files          11      10        -1     
  Lines         386     395        +9     
==========================================
+ Hits          194     271       +77     
+ Misses        192     124       -68

@todo
Copy link

todo bot commented Jun 15, 2019

once id is re-added to NotebookSession's attributes readd this

# 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']
assert notebook_session.kernel == KernelInfo(**session_dict["kernel"])
assert notebook_session.notebook == session_dict["notebook"]


This comment was generated by todo based on a TODO comment in 1c7a9b7 in #136. cc @mpacer.

@mpacer
Copy link
Member Author

mpacer commented Jun 15, 2019

There's always something super disappointing when you see a code coverage report for a testing PR that reports a drop in test coverage for some reason…

I don't get it — the tests get picked up by pytest-cov locally:

---------- coverage: platform darwin, python 3.6.8-final-0 -----------
Name                               Stmts   Miss  Cover
------------------------------------------------------
bookstore/__init__.py                 10      1    90%
bookstore/_version.py                 10      0   100%
bookstore/archive.py                  49     11    78%
bookstore/bookstore_config.py         17      0   100%
bookstore/client/__init__.py           1      0   100%
bookstore/client/nb_client.py        112     25    78%
bookstore/client/store_client.py      26     18    31%
bookstore/clone.py                    82     18    78%
bookstore/handlers.py                 28     14    50%
bookstore/publish.py                  38     25    34%
bookstore/s3_paths.py                  9      0   100%
bookstore/utils.py                    12      0   100%
bookstore/validation.py               12     12     0%
------------------------------------------------------
TOTAL                                406    124    69%

@todo
Copy link

todo bot commented Jun 15, 2019

once id is re-added to NotebookSession's attributes readd this

# 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']
assert notebook_session.kernel == KernelInfo(**session_dict["kernel"])
assert notebook_session.notebook == session_dict["notebook"]


This comment was generated by todo based on a TODO comment in 0bf64ab in #136. cc @mpacer.

Copy link
Member

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpacer the files are pretty small so I think it is fine to leave type and client together for now.

I would move the test files under the bookstore/tests/client directory instead of keeping with client. It keeps the tests together.

It tends to be more common in tests to have assert actual expected pattern though the opposite is technically valid. It's slightly more readable to do the first. For example:

assert extract_kernel_id(connection_file) == expected_kernel_id

would read from left to right as: If I test the extract_kernel_id function with a connection file, I would expect to receive this expected kernel id. It also makes it a bit easier for the reviewer to scan down the left of the page to see the commands executed.

@@ -0,0 +1,116 @@
import pytest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving the client tests to bookstore/tests/client/test_nb_client.py so all tests are kept together.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

bookstore/client/nb_client.py Outdated Show resolved Hide resolved
@@ -78,16 +78,29 @@ def __init__(self, *args, id, name, last_activity, execution_state, connections)
def __repr__(self):
return json.dumps(self.model, indent=2)

def __eq__(self, other):
if isinstance(other, KernelInfo):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job checking the object is a KernelInfo instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

bookstore/client/nb_client.py Outdated Show resolved Hide resolved
)


@pytest.fixture
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving all fixtures into their own file and importing that file. This makes the tests more visible and the test setup more reusable in other tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good



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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the comments in this file and the other and instead open an issue to track.

Copy link
Member Author

@mpacer mpacer Jun 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #135

],
)
def test_extract_kernel_id(connection_file, expected_kernel_id):
assert expected_kernel_id == extract_kernel_id(connection_file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps flip the assert statement. assert <test_result> <expected result>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

tox.ini Outdated
@@ -73,7 +73,7 @@ deps =
depends =
py36: clean
commands =
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always bookstore/tests/
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be inclined to leave the directory here and move the client tests to bookstore/tests/client/...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

tox.ini Outdated
@@ -73,7 +73,7 @@ deps =
depends =
py36: clean
commands =
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always bookstore/tests/
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be inclined to leave the directory here and move the client tests to bookstore/tests/client/...

tox.ini Outdated
@@ -73,7 +73,7 @@ deps =
depends =
py36: clean
commands =
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always bookstore/tests/
pytest -v --maxfail=2 --cov-config=.coveragerc --cov=bookstore -W always
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be inclined to leave the directory here and move the client tests to bookstore/tests/client/...

@todo
Copy link

todo bot commented Jun 24, 2019

once id is re-added to NotebookSession's attributes readd this

# 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']
assert notebook_session.kernel == KernelInfo(**session_dict["kernel"])
assert notebook_session.notebook == session_dict["notebook"]


This comment was generated by todo based on a TODO comment in f72a1bd in #136. cc @mpacer.

1 similar comment
@todo
Copy link

todo bot commented Jun 24, 2019

once id is re-added to NotebookSession's attributes readd this

# 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']
assert notebook_session.kernel == KernelInfo(**session_dict["kernel"])
assert notebook_session.notebook == session_dict["notebook"]


This comment was generated by todo based on a TODO comment in f72a1bd in #136. cc @mpacer.

@mpacer
Copy link
Member Author

mpacer commented Jun 24, 2019

Thank you for the reviews @willingc! I think I addressed them all, please let me know if not.

@willingc
Copy link
Member

Fantastic @mpacer. Happy to merge.

@willingc willingc merged commit 57f46e8 into nteract:master Jun 24, 2019
@mpacer mpacer added this to the 2.3 milestone Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants