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

Implemented decorator pattern with notebook_loader #19

Merged
merged 10 commits into from
May 3, 2020

Conversation

rohitsanj
Copy link
Member

@rohitsanj rohitsanj commented Apr 27, 2020

Implements #5

  1. Created a class called notebook_loader which encapsulates the contextmanager and decorator pattern of setting up tests.
  • contextmanager pattern:
from testbook import notebook_loader

def test_foo():
    with notebook_loader('/path/to/notebook.ipynb', prerun=[0, 1]) as notebook:
        notebook.execute(['test1', 'test2'])
        assert notebook.cell_output_text('test2') == 'foobar'
  • decorator pattern:
from testbook import notebook_loader

@notebook_loader('/path/to/notebook.ipynb', prerun=[0, 1])
def test_foo(notebook):
    notebook.execute(['test1', 'test2'])
    assert notebook.cell_output_text('test2') == 'foobar'
  1. Added prerun argument to notebook_loader

testbook/execute.py Outdated Show resolved Hide resolved
return self.client

def __exit__(self, *args):
self.client._cleanup_kernel()
Copy link
Member

Choose a reason for hiding this comment

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

We should maybe make nbclient change the name to cleanup_kernel since it's needed to manage kernel states

self.client = client

def _start_kernel(self):
if self.client.km is None:
Copy link
Member

Choose a reason for hiding this comment

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

We should maybe make nbclient have a startup_kernel since it's needed to manage kernel states

testbook/execute.py Show resolved Hide resolved
@MSeal MSeal merged commit 423a904 into nteract:master May 3, 2020
@rohitsanj rohitsanj deleted the decorator-pattern branch June 17, 2020 12:49
@rohitsanj rohitsanj added this to the 0.1.0 milestone Jun 18, 2020
@rohitsanj rohitsanj added the GSoC-2020 Part of Google Summer of Code 2020 label Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC-2020 Part of Google Summer of Code 2020
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants