Skip to content

Commit

Permalink
Reset Jupyter iPython kernel client after updating sklearn
Browse files Browse the repository at this point in the history
  • Loading branch information
ckunki committed Aug 15, 2024
1 parent 8966b63 commit 744024a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 10 additions & 1 deletion test/notebooks/nbtest_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def test_regression(notebook_runner) -> None:
current_dir = os.getcwd()
try:
notebook_runner('main_config.ipynb')
os.chdir('./sklearn')
notebook_runner('sklearn_fix_version.ipynb')
os.chdir('..')
#
notebook_runner('main_config.ipynb', reset_kernel_client=True)
os.chdir('./data')
notebook_runner('data_abalone.ipynb')
os.chdir('../sklearn')
notebook_runner('sklearn_fix_version.ipynb')
notebook_runner('sklearn_predict_udf.ipynb')
notebook_runner('sklearn_train_abalone.ipynb')
notebook_runner('sklearn_predict_abalone.ipynb')
Expand All @@ -36,6 +40,11 @@ def test_classification(notebook_runner) -> None:
current_dir = os.getcwd()
try:
notebook_runner('main_config.ipynb')
os.chdir('./sklearn')
notebook_runner('sklearn_fix_version.ipynb')
os.chdir('..')
#
notebook_runner('main_config.ipynb', reset_kernel_client=True)
os.chdir('./data')
notebook_runner('data_telescope.ipynb')
os.chdir('../sklearn')
Expand Down
15 changes: 11 additions & 4 deletions test/notebooks/notebook_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,25 @@ def cell_match(nb_cell, ins_tag: str) -> bool:
nb.cells.insert(cell_no + 1, hack_cell)


def run_notebook(notebook_file: str, store_file: str, store_password: str,
timeout: int = -1, hacks: Optional[List[Tuple[str, str]]] = None) -> None:
def run_notebook(
notebook_file: str,
store_file: str,
store_password: str,
timeout: int = -1,
hacks: Optional[List[Tuple[str, str]]] = None,
reset_kernel_client: bool =False,
) -> None:
"""
Executes notebook with added access to the configuration store.
Parameters:
notebook_file: Notebook file.
store_file: Configuration store file.
store_password: Configuration store password.
timeout: Optional timeout in seconds
timeout: Optional timeout in seconds.
hacks: Optional hacks to be inserted into the notebook
before running it.
reset_kernel_client: If True, then restart the kernel before running it.
"""

nb = nbformat.read(notebook_file, as_version=4)
Expand All @@ -113,7 +120,7 @@ def init_notebook_test():

# Execute the notebook object, expecting to get no exceptions.
nb_client = NotebookClient(nb, timeout=timeout, kernel_name='python3')
nb_client.execute()
nb_client.execute(reset_kc=reset_kernel_client)



Expand Down

0 comments on commit 744024a

Please sign in to comment.