@@ -923,51 +923,56 @@ def test_notebook_export_json_with_output():
923923 _ip .history_manager .reset ()
924924 _ip .colors = "neutral"
925925
926- commands = [
927- "display('test')" ,
928- "1+1" ,
929- "display('a'), display('b')" ,
930- "1/0" ,
931- "print('test')" ,
932- "import sys\n print('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\n print('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+ print (f"\n { _ip .history_manager .outputs } \n " )
956+
957+ with TemporaryDirectory () as td :
958+ outfile = os .path .join (td , "nb.ipynb" )
959+ _ip .run_cell (f"%notebook { outfile } " , store_history = True )
960+ sleep (2 )
961+ actual_nb = nbformat .read (outfile , as_version = 4 )
962+
963+ assert len (actual_nb ["cells" ]) == len (commands )
964+ assert len (expected_nb ["cells" ]) == len (commands )
965+
966+ for i , command in enumerate (commands ):
967+ actual = actual_nb ["cells" ][i ]
968+ expected = expected_nb ["cells" ][i ]
969+ assert expected ["source" ] == command
970+ assert actual ["source" ] == expected ["source" ]
971+ assert (
972+ actual ["outputs" ] == expected ["outputs" ]
973+ ), f"Outputs do not match for cell { i + 1 } with source { command !r} "
974+ finally :
975+ _ip .colors = "nocolor"
971976
972977
973978class TestEnv (TestCase ):
0 commit comments