@@ -32,6 +32,7 @@ import {
3232 ICell ,
3333 IDataScienceErrorHandler ,
3434 IJupyterExecution ,
35+ INotebookEditor ,
3536 INotebookEditorProvider ,
3637 INotebookExporter ,
3738 ITrustService
@@ -2445,6 +2446,69 @@ df.head()`;
24452446 }
24462447 } ;
24472448
2449+ suite ( 'Stop On Error' , ( ) => {
2450+ let notebookEditor : { editor : INotebookEditor ; mount : IMountedWebView } ;
2451+ setup ( async ( ) => {
2452+ await initIoc ( ) ;
2453+
2454+ // Set up a file where the second cell throws an exception
2455+ addMockData ( ioc , 'print("hello")' , 'hello' ) ;
2456+ addMockData ( ioc , 'raise Exception("stop")' , undefined , undefined , 'error' ) ;
2457+ addMockData ( ioc , 'print("world")' , 'world' ) ;
2458+
2459+ const errorFile = [
2460+ { id : 'NotebookImport#0' , data : { source : 'print("hello")' } } ,
2461+ { id : 'NotebookImport#1' , data : { source : 'raise Exception("stop")' } } ,
2462+ { id : 'NotebookImport#2' , data : { source : 'print("world")' } }
2463+ ] ;
2464+ const runAllCells = errorFile . map ( ( cell ) => {
2465+ return createFileCell ( cell , cell . data ) ;
2466+ } ) ;
2467+ const notebook = await ioc
2468+ . get < INotebookExporter > ( INotebookExporter )
2469+ . translateToNotebook ( runAllCells , undefined ) ;
2470+ notebookEditor = await openEditor ( ioc , JSON . stringify ( notebook ) ) ;
2471+ } ) ;
2472+
2473+ test ( 'Stop On Error On' , async ( ) => {
2474+ const ne = notebookEditor ;
2475+
2476+ const runAllButton = findButton ( ne . mount . wrapper , NativeEditor , 0 ) ;
2477+ // The render method needs to be executed 3 times for three cells.
2478+ const threeCellsUpdated = waitForMessage ( ioc , InteractiveWindowMessages . ExecutionRendered , {
2479+ numberOfTimes : 3
2480+ } ) ;
2481+ runAllButton ! . simulate ( 'click' ) ;
2482+ await threeCellsUpdated ;
2483+
2484+ verifyHtmlOnCell ( ne . mount . wrapper , 'NativeCell' , `hello` , 0 ) ;
2485+ // There should be no output on the third cell as it's blocked by the exception on the second cell
2486+ assert . throws ( ( ) => verifyHtmlOnCell ( ne . mount . wrapper , 'NativeCell' , `world` , 2 ) ) ;
2487+ } ) ;
2488+
2489+ test ( 'Stop On Error Off' , async ( ) => {
2490+ const ne = notebookEditor ;
2491+
2492+ // Force our settings to not stop on error
2493+ ioc . forceSettingsChanged ( undefined , ioc . getSettings ( ) . pythonPath , {
2494+ ...ioc . getSettings ( ) . datascience ,
2495+ stopOnError : false
2496+ } ) ;
2497+
2498+ const runAllButton = findButton ( ne . mount . wrapper , NativeEditor , 0 ) ;
2499+ // The render method needs to be executed 3 times for three cells.
2500+ const threeCellsUpdated = waitForMessage ( ioc , InteractiveWindowMessages . ExecutionRendered , {
2501+ numberOfTimes : 3
2502+ } ) ;
2503+ runAllButton ! . simulate ( 'click' ) ;
2504+ await threeCellsUpdated ;
2505+
2506+ verifyHtmlOnCell ( ne . mount . wrapper , 'NativeCell' , `hello` , 0 ) ;
2507+ // There should be output on the third cell, even with an error on the second
2508+ verifyHtmlOnCell ( ne . mount . wrapper , 'NativeCell' , `world` , 2 ) ;
2509+ } ) ;
2510+ } ) ;
2511+
24482512 suite ( 'Update Metadata' , ( ) => {
24492513 setup ( async function ( ) {
24502514 await initIoc ( ) ;
0 commit comments