@@ -327,6 +327,42 @@ async def test_update_config_only(self, k: Kernel) -> None:
327327 ]
328328 )
329329
330+ async def test_update_code_skips_formatting_when_disabled (
331+ self , k : Kernel
332+ ) -> None :
333+ await k .run ([ExecuteCellCommand (cell_id = CellId_t ("0" ), code = "x = 1" )])
334+
335+ with (
336+ patch .dict (k .user_config ["save" ], {"format_on_save" : False }),
337+ patch (
338+ "marimo._code_mode._context.DefaultFormatter.format" ,
339+ new_callable = AsyncMock ,
340+ ) as mock_format ,
341+ ):
342+ with _ctx (k ) as ctx :
343+ async with ctx as nb :
344+ nb .edit_cell ("0" , code = "x= 42" )
345+
346+ mock_format .assert_not_awaited ()
347+ assert _graph_codes (k ) == {"0" : "x= 42" }
348+
349+ async def test_update_code_formats_when_enabled (self , k : Kernel ) -> None :
350+ await k .run ([ExecuteCellCommand (cell_id = CellId_t ("0" ), code = "x = 1" )])
351+
352+ with (
353+ patch .dict (k .user_config ["save" ], {"format_on_save" : True }),
354+ patch (
355+ "marimo._code_mode._context.DefaultFormatter.format" ,
356+ new = AsyncMock (return_value = {"0" : "x = 42" }),
357+ ) as mock_format ,
358+ ):
359+ with _ctx (k ) as ctx :
360+ async with ctx as nb :
361+ nb .edit_cell ("0" , code = "x= 42" )
362+
363+ mock_format .assert_awaited_once ()
364+ assert _graph_codes (k ) == {"0" : "x = 42" }
365+
330366
331367class TestCombined :
332368 async def test_delete_and_add (self , k : Kernel ) -> None :
0 commit comments