def test_single_save_with_nested_context_manager(mock_save_to_disk: MagicMock, option: Options): # Setup option._output_directory = Path("start") # Run with option: option.output_directory = Path("end") with option: pass # Assert mock_save_to_disk.assert_called_once_with(option)
def test_save_with_context_manager(mock_save_to_disk: MagicMock, option: Options): # Setup settings_changed = MagicMock() option._output_directory = Path("start") option.on_options_changed = settings_changed # Run with option: option.output_directory = Path("end") # Assert mock_save_to_disk.assert_called_once_with(option) settings_changed.assert_called_once_with()
def test_edit_during_options_changed(tmpdir): # Setup option = Options(Path(tmpdir)) option._output_directory = Path("start") def on_changed(): with option: option.output_directory = Path("final") option.on_options_changed = on_changed # Run with option: option.output_directory = Path("middle") second_option = Options(Path(tmpdir)) second_option.load_from_disk() # Assert assert option.output_directory == Path("final") assert option.output_directory == second_option.output_directory