Skip to content

Commit 0a76d4b

Browse files
committed
Run kernel tests for all c++ kernels
1 parent 27a9f21 commit 0a76d4b

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

test/test_xcpp_kernel.py

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
import nbformat
1313
import papermill as pm
1414

15-
class XCppCompleteTests(jupyter_kernel_test.KernelTests):
16-
17-
kernel_name = 'xcpp20'
18-
15+
class BaseXCppCompleteTests(jupyter_kernel_test.KernelTests):
16+
__test__ = False
17+
1918
# language_info.name in a kernel_info_reply should match this
2019
language_name = 'C++'
2120

@@ -64,12 +63,22 @@ def test_continuation(self) -> None:
6463
self.assertEqual(str(reply["content"]["indent"]), "")
6564
self.assertEqual(reply["content"]["status"], "complete")
6665

66+
kernel_names = ['xcpp17', 'xcpp20', 'xcpp23']
6767

68-
if platform.system() != 'Windows':
69-
class XCppTests(jupyter_kernel_test.KernelTests):
70-
71-
kernel_name = 'xcpp20'
68+
for name in kernel_names:
69+
class_name = f"XCppCompleteTests_{name}"
70+
globals()[class_name] = type(
71+
class_name,
72+
(BaseXCppCompleteTests,),
73+
{
74+
'kernel_name': name,
75+
'__test__': True
76+
}
77+
)
7278

79+
if platform.system() != 'Windows':
80+
class BaseXCppTests(jupyter_kernel_test.KernelTests):
81+
__test__ = False
7382
# language_info.name in a kernel_info_reply should match this
7483
language_name = 'C++'
7584

@@ -130,9 +139,20 @@ class XCppTests(jupyter_kernel_test.KernelTests):
130139
}
131140
]
132141

133-
# Tests for Notebooks
134-
class XCppNotebookTests(unittest.TestCase):
142+
for name in kernel_names:
143+
class_name = f"XCppTests_{name}"
144+
globals()[class_name] = type(
145+
class_name,
146+
(BaseXCppTests,),
147+
{
148+
'kernel_name': name,
149+
'__test__': True
150+
}
151+
)
135152

153+
# Tests for Notebooks
154+
class BaseXCppNotebookTests(unittest.TestCase):
155+
__test__ = False
136156
notebook_names = [
137157
'xeus-cpp'
138158
# Add more notebook names as needed
@@ -153,7 +173,7 @@ def test_notebooks(self):
153173
inp,
154174
out,
155175
log_output=True,
156-
kernel_name='xcpp20'
176+
kernel_name=self.kernel_name
157177
)
158178

159179
if executed_notebook is None: # Explicit check for None or any other condition
@@ -174,17 +194,36 @@ def test_notebooks(self):
174194
if input_cell.outputs != output_cell.outputs:
175195
self.fail(f"{input_output.get('text')} != {output_output.get('text')} Cell {i} in notebook {name} has mismatched output type")
176196

197+
for name in kernel_names:
198+
class_name = f"XCppNotebookTests_{name}"
199+
globals()[class_name] = type(
200+
class_name,
201+
(BaseXCppNotebookTests,),
202+
{
203+
'kernel_name': name,
204+
'__test__': True
205+
}
206+
)
177207

178-
class XCppTests2(jupyter_kernel_test.KernelTests):
179-
180-
kernel_name = 'xcpp20'
208+
class BaseXCppTests2(jupyter_kernel_test.KernelTests):
209+
__test__ = False
181210

182211
# language_info.name in a kernel_info_reply should match this
183212
language_name = 'C++'
184213

185214
# Code that should write the exact string `hello, world` to STDOUT
186215
code_hello_world = '#include <stdio.h>\nprintf("hello, world");'
187216

217+
for name in kernel_names:
218+
class_name = f"XCppTests2_{name}"
219+
globals()[class_name] = type(
220+
class_name,
221+
(BaseXCppTests2,),
222+
{
223+
'kernel_name': name,
224+
'__test__': True
225+
}
226+
)
188227

189228
if __name__ == '__main__':
190-
unittest.main()
229+
unittest.main()

0 commit comments

Comments
 (0)