Skip to content

Commit

Permalink
Add testing frameworks for notebooks, update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun571 committed Jun 10, 2024
1 parent edd830f commit 7cef4df
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/source/debug.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ These steps are performed using the GNU Debugger (GDB), so ensure it is installe

.. code-block:: bash
cd build
cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_PREFIX_PATH=$CONDA_PREFIX -D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX -D CMAKE_INSTALL_LIBDIR=lib ..
In the same folder, run the command and copy the JSON displayed in the terminal.
Expand All @@ -34,5 +35,5 @@ Testing

The source code for the c++ tests is located in `test/test_interpreter.cpp`. The source code for the python tests is located in `test/test_xcpp_kernel.py`.
Write the necessary tests and build the project as described in the repository's README or contributing guidelines.
Then, execute `build/test/test_xeus_cpp` from the top level directory to verify if the c++ tests were successful,
and `pytest -sv build/test/test_xcpp_kernel.py` to execute the python tests.
Then, execute `build/test/test_xeus_cpp` from the top level directory to verify if the c++ tests were successful.
and in the test directory run `pytest -sv build/test/test_xcpp_kernel.py` to execute the python tests.
2 changes: 2 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ dependencies:
# Test dependencies
- pytest
- jupyter_kernel_test>=0.5,<0.6
- papermill
- nbformat
- nbval
- pytest-rerunfailures
- doctest
66 changes: 66 additions & 0 deletions test/Notebooks/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "5b32725b-d7df-4756-b179-68ed3c429d3f",
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "cbf10f24-99a1-434d-b71a-4f8920e5ebb6",
"metadata": {},
"outputs": [],
"source": [
"int a = 12;"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f269cf5a-b365-4a1a-9a79-44f2222e6829",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"12"
]
}
],
"source": [
"std::cout<<a;"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1650dcc-0728-4d0f-a156-b8ee0c8b40e3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "cpp 20 (xcpp)",
"language": "cpp",
"name": "xcpp"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "C++",
"version": "20"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
40 changes: 39 additions & 1 deletion test/test_xcpp_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import unittest
import jupyter_kernel_test
import platform

import papermill as pm
import nbformat

class XCppCompleteTests(jupyter_kernel_test.KernelTests):

Expand Down Expand Up @@ -132,6 +133,43 @@ class XCppTests(jupyter_kernel_test.KernelTests):
}
]

#Helper function to execute the notebooks
def execute_notebook(inp, out):

# Execute the notebook
executed_notebook = pm.execute_notebook(
inp,
out,
log_output=True,
kernel_name='xcpp20'
)

# Read the input and output notebooks
with open(inp) as f:
input_nb = nbformat.read(f, as_version=4)
with open(out) as f:
output_nb = nbformat.read(f, as_version=4)

check = True

# Iterate over the cells in the input and output notebooks
for input_cell, output_cell in zip(input_nb.cells, output_nb.cells):
if input_cell.cell_type == 'code' and output_cell.cell_type == 'code':
# Check the outputs of the cells
for input_output, output_output in zip(input_cell.outputs, output_cell.outputs):
if input_output.get('text') != output_output.get('text'):
check = False
break

return check

# Tests for Notebooks
class XCppNotebookTests(unittest.TestCase):

def test_simple_notebook(self):
self.assertEqual(execute_notebook('Notebooks/Untitled.ipynb', 'Notebooks/Untitled_output.ipynb'), True)



class XCppTests2(jupyter_kernel_test.KernelTests):

Expand Down

0 comments on commit 7cef4df

Please sign in to comment.