Skip to content

Commit 23ef9c8

Browse files
committed
Update notebook test
1 parent 7cef4df commit 23ef9c8

3 files changed

Lines changed: 165 additions & 76 deletions

File tree

test/Notebooks/Untitled.ipynb

Lines changed: 0 additions & 66 deletions
This file was deleted.

test/Notebooks/test.ipynb

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "5b32725b-d7df-4756-b179-68ed3c429d3f",
7+
"metadata": {
8+
"execution": {
9+
"iopub.execute_input": "2024-06-11T15:06:09.483843Z",
10+
"iopub.status.busy": "2024-06-11T15:06:09.483585Z",
11+
"iopub.status.idle": "2024-06-11T15:06:09.895880Z",
12+
"shell.execute_reply": "2024-06-11T15:06:09.895789Z"
13+
},
14+
"papermill": {
15+
"duration": 0.430933,
16+
"end_time": "2024-06-11T15:06:09.897095",
17+
"exception": false,
18+
"start_time": "2024-06-11T15:06:09.466162",
19+
"status": "completed"
20+
},
21+
"tags": [],
22+
"vscode": {
23+
"languageId": "c++"
24+
}
25+
},
26+
"outputs": [],
27+
"source": [
28+
"#include <iostream>"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 2,
34+
"id": "cbf10f24-99a1-434d-b71a-4f8920e5ebb6",
35+
"metadata": {
36+
"execution": {
37+
"iopub.execute_input": "2024-06-11T15:06:09.908413Z",
38+
"iopub.status.busy": "2024-06-11T15:06:09.908325Z",
39+
"iopub.status.idle": "2024-06-11T15:06:09.909283Z",
40+
"shell.execute_reply": "2024-06-11T15:06:09.909198Z"
41+
},
42+
"papermill": {
43+
"duration": 0.008123,
44+
"end_time": "2024-06-11T15:06:09.910249",
45+
"exception": false,
46+
"start_time": "2024-06-11T15:06:09.902126",
47+
"status": "completed"
48+
},
49+
"tags": [],
50+
"vscode": {
51+
"languageId": "c++"
52+
}
53+
},
54+
"outputs": [],
55+
"source": [
56+
"int a = 12;"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 3,
62+
"id": "f269cf5a-b365-4a1a-9a79-44f2222e6829",
63+
"metadata": {
64+
"execution": {
65+
"iopub.execute_input": "2024-06-11T15:06:09.922051Z",
66+
"iopub.status.busy": "2024-06-11T15:06:09.921942Z",
67+
"iopub.status.idle": "2024-06-11T15:06:09.926437Z",
68+
"shell.execute_reply": "2024-06-11T15:06:09.926399Z"
69+
},
70+
"papermill": {
71+
"duration": 0.012832,
72+
"end_time": "2024-06-11T15:06:09.928333",
73+
"exception": false,
74+
"start_time": "2024-06-11T15:06:09.915501",
75+
"status": "completed"
76+
},
77+
"tags": [],
78+
"vscode": {
79+
"languageId": "c++"
80+
}
81+
},
82+
"outputs": [
83+
{
84+
"name": "stdout",
85+
"output_type": "stream",
86+
"text": [
87+
"12"
88+
]
89+
}
90+
],
91+
"source": [
92+
"std::cout<<a;"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": null,
98+
"id": "b1650dcc-0728-4d0f-a156-b8ee0c8b40e3",
99+
"metadata": {
100+
"papermill": {
101+
"duration": 0.004358,
102+
"end_time": "2024-06-11T15:06:09.937921",
103+
"exception": false,
104+
"start_time": "2024-06-11T15:06:09.933563",
105+
"status": "completed"
106+
},
107+
"tags": [],
108+
"vscode": {
109+
"languageId": "c++"
110+
}
111+
},
112+
"outputs": [],
113+
"source": []
114+
}
115+
],
116+
"metadata": {
117+
"kernelspec": {
118+
"display_name": "cpp 20 (xcpp)",
119+
"language": "cpp",
120+
"name": "xcpp"
121+
},
122+
"language_info": {
123+
"codemirror_mode": "text/x-c++src",
124+
"file_extension": ".cpp",
125+
"mimetype": "text/x-c++src",
126+
"name": "C++",
127+
"version": "20"
128+
},
129+
"papermill": {
130+
"default_parameters": {},
131+
"duration": 1.001358,
132+
"end_time": "2024-06-11T15:06:10.061526",
133+
"environment_variables": {},
134+
"exception": null,
135+
"input_path": "Notebooks/test.ipynb",
136+
"output_path": "Notebooks/test_output.ipynb",
137+
"parameters": {},
138+
"start_time": "2024-06-11T15:06:09.060168",
139+
"version": "2.6.0"
140+
}
141+
},
142+
"nbformat": 4,
143+
"nbformat_minor": 5
144+
}

test/test_xcpp_kernel.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class XCppTests(jupyter_kernel_test.KernelTests):
136136
#Helper function to execute the notebooks
137137
def execute_notebook(inp, out):
138138

139+
with open(inp) as f:
140+
input_nb = nbformat.read(f, as_version=4)
141+
139142
# Execute the notebook
140143
executed_notebook = pm.execute_notebook(
141144
inp,
@@ -144,9 +147,6 @@ def execute_notebook(inp, out):
144147
kernel_name='xcpp20'
145148
)
146149

147-
# Read the input and output notebooks
148-
with open(inp) as f:
149-
input_nb = nbformat.read(f, as_version=4)
150150
with open(out) as f:
151151
output_nb = nbformat.read(f, as_version=4)
152152

@@ -155,19 +155,30 @@ def execute_notebook(inp, out):
155155
# Iterate over the cells in the input and output notebooks
156156
for input_cell, output_cell in zip(input_nb.cells, output_nb.cells):
157157
if input_cell.cell_type == 'code' and output_cell.cell_type == 'code':
158-
# Check the outputs of the cells
159-
for input_output, output_output in zip(input_cell.outputs, output_cell.outputs):
160-
if input_output.get('text') != output_output.get('text'):
161-
check = False
162-
break
158+
# If one cell has output and the other doesn't, set check to False
159+
if bool(input_cell.outputs) != bool(output_cell.outputs):
160+
check = False
161+
break
162+
else:
163+
for input_output, output_output in zip(input_cell.outputs, output_cell.outputs):
164+
if input_output.get('text') != output_output.get('text'):
165+
check = False
166+
break
163167

164168
return check
165169

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

169-
def test_simple_notebook(self):
170-
self.assertEqual(execute_notebook('Notebooks/Untitled.ipynb', 'Notebooks/Untitled_output.ipynb'), True)
173+
notebook_pairs = [
174+
('Notebooks/test.ipynb', 'Notebooks/test_output.ipynb'),
175+
# Add more pairs as needed
176+
]
177+
178+
def test_notebooks(self):
179+
for inp, out in self.notebook_pairs:
180+
with self.subTest(inp=inp, out=out):
181+
self.assertEqual(execute_notebook(inp, out), True)
171182

172183

173184

0 commit comments

Comments
 (0)