Skip to content

Commit faa3464

Browse files
committed
fix-test
1 parent 88791e2 commit faa3464

3 files changed

Lines changed: 46 additions & 45 deletions

File tree

tests/test_magic.py

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -923,51 +923,54 @@ def test_notebook_export_json_with_output():
923923
_ip.history_manager.reset()
924924
_ip.colors = "neutral"
925925

926-
commands = [
927-
"print('test')",
928-
"1/0",
929-
"display('test')",
930-
"1+1",
931-
"display('a'), display('b')",
932-
"import sys\nprint('test', file=sys.stderr)",
933-
]
934-
935-
clean_nb = nbformat.v4.new_notebook(
936-
cells=[nbformat.v4.new_code_cell(source=cmd) for cmd in commands]
937-
)
938-
939-
with TemporaryDirectory() as td:
940-
outfile = os.path.join(td, "nb.ipynb")
941-
client = NotebookClient(
942-
clean_nb,
943-
timeout=600,
944-
kernel_name="python3",
945-
resources={"metadata": {"path": td}},
946-
allow_errors=True,
926+
try:
927+
commands = [
928+
"1/0",
929+
"print('test')",
930+
"display('test')",
931+
"1+1",
932+
"display('a'), display('b')",
933+
"import sys\nprint('test', file=sys.stderr)",
934+
]
935+
936+
clean_nb = nbformat.v4.new_notebook(
937+
cells=[nbformat.v4.new_code_cell(source=cmd) for cmd in commands]
947938
)
948-
client.execute()
949-
nbformat.write(clean_nb, outfile)
950-
expected_nb = nbformat.read(outfile, as_version=4)
951-
952-
for cmd in commands:
953-
_ip.run_cell(cmd, store_history=True, silent=False)
954939

955-
with TemporaryDirectory() as td:
956-
outfile = os.path.join(td, "nb.ipynb")
957-
_ip.run_cell(f"%notebook {outfile}", store_history=True)
958-
actual_nb = nbformat.read(outfile, as_version=4)
959-
960-
assert len(actual_nb["cells"]) == len(commands)
961-
assert len(expected_nb["cells"]) == len(commands)
962-
963-
for i, command in enumerate(commands):
964-
actual = actual_nb["cells"][i]
965-
expected = expected_nb["cells"][i]
966-
assert expected["source"] == command
967-
assert actual["source"] == expected["source"]
968-
assert (
969-
actual["outputs"] == expected["outputs"]
970-
), f"Outputs do not match for cell {i+1} with source {command!r}"
940+
with TemporaryDirectory() as td:
941+
outfile = os.path.join(td, "nb.ipynb")
942+
client = NotebookClient(
943+
clean_nb,
944+
timeout=600,
945+
kernel_name="python3",
946+
resources={"metadata": {"path": td}},
947+
allow_errors=True,
948+
)
949+
client.execute()
950+
nbformat.write(clean_nb, outfile)
951+
expected_nb = nbformat.read(outfile, as_version=4)
952+
953+
for cmd in commands:
954+
_ip.run_cell(cmd, store_history=True, silent=False)
955+
956+
with TemporaryDirectory() as td:
957+
outfile = os.path.join(td, "nb.ipynb")
958+
_ip.run_cell(f"%notebook {outfile}", store_history=True)
959+
actual_nb = nbformat.read(outfile, as_version=4)
960+
961+
assert len(actual_nb["cells"]) == len(commands)
962+
assert len(expected_nb["cells"]) == len(commands)
963+
964+
for i, command in enumerate(commands):
965+
actual = actual_nb["cells"][i]
966+
expected = expected_nb["cells"][i]
967+
assert expected["source"] == command
968+
assert actual["source"] == expected["source"]
969+
assert (
970+
actual["outputs"] == expected["outputs"]
971+
), f"Outputs do not match for cell {i+1} with source {command!r}"
972+
finally:
973+
_ip.colors = "nocolor"
971974

972975

973976
class TestEnv(TestCase):

tests/test_magic_terminal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def test_paste_echo(self):
189189
b = 200"""
190190
try:
191191
# ip.disable_capturing_tee = True
192-
ip.colors = "nocolor"
193192
self.paste(code, "")
194193
out = w.getvalue()
195194
finally:

tests/test_oinspect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ def prop(self, v):
523523
self._prop = v
524524
"""
525525
# ip.disable_capturing_tee = True
526-
ip.colors = "nocolor"
527526
ip.run_cell(obj_def)
528527

529528
ip.run_cell("b = Bar()")

0 commit comments

Comments
 (0)