Skip to content

Commit b24d8b7

Browse files
author
OutlyingWest
committed
minimal working version
1 parent 41851aa commit b24d8b7

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

tests/test_kernel.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ def check_from_file(self, filename):
5454
self.check_stream_output(code, expected_output)
5555

5656
def check_from_notebook(self, notebook_path: str):
57-
nb = nbformat.read(open(notebook_path), as_version=4)
58-
from pprint import pprint
59-
# pprint(nb.cells)
57+
with open(notebook_path, encoding="utf-8") as f:
58+
nb = nbformat.read(f, as_version=4)
6059

6160
for idx, cell in enumerate(nb.cells):
6261
if cell.cell_type != "code":
@@ -69,17 +68,9 @@ def check_from_notebook(self, notebook_path: str):
6968
expected_outputs = self.extract_notebook_cell_outputs(cell_outputs)
7069
kernel_outputs = self.extract_kernel_executed_outputs(output_messages)
7170

72-
# print(idx)
73-
# pprint(expected_outputs)
74-
# print('---------------------------------')
75-
# pprint(kernel_outputs)
76-
# print()
77-
78-
# with self.subTest(cell=idx, code_line=cell_code.splitlines()[0] if cell_code.strip() else "<empty>"):
79-
# self.assertListEqual()
71+
with self.subTest(cell=idx+1, code_starts=cell_code.splitlines()[0]):
72+
self.assertListEqual(kernel_outputs, expected_outputs)
8073

81-
# with self.subTest(cell=idx, code_line=code.splitlines()[0] if code.strip() else "<empty>"):
82-
# self.check_stream_output(code, expected_outputs)
8374

8475
@staticmethod
8576
def extract_notebook_cell_outputs(cell_outputs: list) -> list:
@@ -93,9 +84,10 @@ def extract_notebook_cell_outputs(cell_outputs: list) -> list:
9384
message_text = "\n".join(output["traceback"])
9485
else:
9586
message_text = ''
96-
message_text = message_text.strip()
97-
print(f'{message_text=}')
98-
expected_outputs.append(message_text)
87+
88+
split_message_text = [line.strip() for line in message_text.splitlines()]
89+
expected_outputs.extend(split_message_text)
90+
9991
return expected_outputs
10092

10193
@staticmethod
@@ -110,13 +102,13 @@ def extract_kernel_executed_outputs(output_messages: list) -> list:
110102
message_text = ''
111103

112104
if '\x00' not in message_text and '\r' not in message_text:
113-
kernel_outputs.append(message_text.strip())
105+
kernel_outputs.extend(message_text.splitlines())
114106

115107
return kernel_outputs
116108

117109
# Enumerate tests to ensure proper execution order
118110
def test_00_scorep_env(self):
119-
self.check_from_notebook("tests/kernel/test_scorep_kernel.ipynb")
111+
self.check_from_notebook("tests/kernel/test_scorep_kernel_1.ipynb")
120112

121113
def test_01_scorep_pythonargs(self):
122114
self.check_from_file("tests/kernel/scorep_pythonargs.yaml")

0 commit comments

Comments
 (0)