11from collections .abc import AsyncIterator , Callable , Iterator
22from contextlib import asynccontextmanager , contextmanager
33from crystal .app_preferences import app_prefs
4- from crystal .browser import MainWindow as RealMainWindow
4+ from crystal .browser . main_window import MainWindow as RealMainWindow
55from crystal .browser .tasktree import TaskTreeNode
66from crystal .model import (
77 Project , ProjectReadOnlyError , Resource , ResourceGroup , RootResource ,
@@ -330,7 +330,7 @@ async def test_when_dirty_untitled_project_closed_then_prompts_to_save() -> None
330330 assert mw .main_window .OSXIsModified ()
331331
332332 # Close the project, expect a prompt to save, and save to the specified path
333- with patch ('crystal.browser.ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_YES )), \
333+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_YES )), \
334334 file_dialog_returning (save_path ):
335335 await mw .close ()
336336 assert os .path .exists (save_path )
@@ -341,7 +341,7 @@ async def test_when_clean_untitled_project_closed_then_does_not_prompt_to_save()
341341 assert not project .is_dirty
342342
343343 # Close project. Ensure no prompt to save.
344- with patch ('crystal.browser.ShowModal' ) as mock_show_modal :
344+ with patch ('crystal.browser.main_window. ShowModal' ) as mock_show_modal :
345345 await mw .close ()
346346 mock_show_modal .assert_not_called ()
347347
@@ -407,7 +407,7 @@ def _ensure_logout_vetoed_and_return_yes(dialog: wx.Dialog) -> int:
407407 return wx .ID_YES
408408
409409 # Start logout. Expect a prompt to save. Save.
410- with patch ('crystal.browser.ShowModal' , mocked_show_modal (
410+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
411411 'cr-save-changes-dialog' ,
412412 _ensure_logout_vetoed_and_return_yes )), \
413413 file_dialog_returning (save_path ):
@@ -435,7 +435,7 @@ async def test_given_os_logout_with_dirty_untitled_project_and_prompts_to_save_w
435435 assert project .is_dirty
436436
437437 # Start logout. Expect a prompt to save. Cancel.
438- with patch ('crystal.browser.ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_CANCEL )):
438+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_CANCEL )):
439439 logout_event = _simulate_os_logout ()
440440
441441 # Verify the logout was vetoed
@@ -446,7 +446,7 @@ async def test_given_os_logout_with_dirty_untitled_project_and_prompts_to_save_w
446446 assert project .is_untitled
447447
448448 # Now close the project without saving
449- with patch ('crystal.browser.ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_NO )):
449+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_NO )):
450450 await mw .close ()
451451
452452
@@ -460,7 +460,7 @@ async def test_given_os_logout_with_dirty_untitled_project_and_prompts_to_save_w
460460 assert project .is_dirty
461461
462462 # Start logout. Expect a prompt to save. Do not save.
463- with patch ('crystal.browser.ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_NO )):
463+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal ('cr-save-changes-dialog' , wx .ID_NO )):
464464 _simulate_os_logout ()
465465
466466 # Ensure project was closed
@@ -476,7 +476,7 @@ async def test_when_close_untitled_prompt_and_user_does_not_save_then_project_mo
476476
477477 with patch ('crystal.filesystem.LocalFilesystem.send2trash' , wraps = send2trash .send2trash ) as send2trash_spy , \
478478 patch (
479- 'crystal.browser.ShowModal' ,
479+ 'crystal.browser.main_window. ShowModal' ,
480480 mocked_show_modal ('cr-save-changes-dialog' , wx .ID_NO )):
481481 await mw .close ()
482482
@@ -820,7 +820,7 @@ def spy_execute(self, command: str, *args, **kwargs):
820820
821821 # Run the save operation
822822 with patch .object (DatabaseCursor , 'execute' , spy_execute ), \
823- patch ('crystal.browser.ShowModal' , mocked_show_modal (
823+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
824824 'cr-save-error-dialog' , wx .ID_OK )):
825825 await save_as_with_ui (rmw , save_path )
826826
@@ -857,7 +857,7 @@ def raise_disk_full_error() -> Never:
857857
858858 # Run the save operation
859859 with _file_object_write_mocked_to (raise_disk_full_error ), \
860- patch ('crystal.browser.ShowModal' , mocked_show_modal (
860+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
861861 'cr-save-error-dialog' , wx .ID_OK )):
862862 await save_as_with_ui (rmw , save_path )
863863
@@ -904,7 +904,7 @@ def raise_destination_filesystem_gone_error() -> Never:
904904
905905 # Run the save operation
906906 with _file_object_write_mocked_to (raise_destination_filesystem_gone_error ), \
907- patch ('crystal.browser.ShowModal' , mocked_show_modal (
907+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
908908 'cr-save-error-dialog' , wx .ID_OK )):
909909 await save_as_with_ui (rmw , save_path )
910910
@@ -981,7 +981,7 @@ async def test_when_save_as_project_and_old_project_fails_to_close_then_handles_
981981 # Patch the scheduler join timeout to 0 to force immediate timeout
982982 with patch .object (Project , '_SCHEDULER_JOIN_TIMEOUT' , 0 ):
983983 # Mock error dialog to acknowledge the timeout error
984- with patch ('crystal.browser.ShowModal' , mocked_show_modal (
984+ with patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
985985 'cr-save-error-dialog' , wx .ID_OK )):
986986 await save_as_with_ui (rmw , save_path )
987987
@@ -1029,7 +1029,7 @@ def raise_database_corruption_error(*args, **kwargs):
10291029
10301030 # Run the save operation
10311031 with patch ('sqlite3.connect' , side_effect = raise_database_corruption_error ), \
1032- patch ('crystal.browser.ShowModal' , mocked_show_modal (
1032+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
10331033 'cr-save-error-dialog' , wx .ID_OK )):
10341034 await save_as_with_ui (rmw , save_path )
10351035
@@ -1071,7 +1071,7 @@ def fake_reopen(self):
10711071 f .truncate (size // 2 )
10721072 return original_reopen (self )
10731073 with patch .object (Project , '_reopen' , fake_reopen ), \
1074- patch ('crystal.browser.ShowModal' , mocked_show_modal (
1074+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
10751075 'cr-save-error-dialog' , wx .ID_OK )) as show_modal_method :
10761076 await save_as_with_ui (rmw , save_path )
10771077 assert 1 == show_modal_method .call_count , \
@@ -1119,7 +1119,7 @@ def fake_reopen(self):
11191119 return original_reopen (self )
11201120
11211121 with patch .object (Project , '_reopen' , fake_reopen ), \
1122- patch ('crystal.browser.ShowModal' , mocked_show_modal (
1122+ patch ('crystal.browser.main_window. ShowModal' , mocked_show_modal (
11231123 'cr-save-error-dialog' , wx .ID_OK )) as show_modal_method :
11241124 await save_as_with_ui (rmw , save_path )
11251125 assert 1 == show_modal_method .call_count , \
@@ -1506,7 +1506,7 @@ def SaveAsProgressDialogSpy(*args, **kwargs) -> SaveAsProgressDialog: # wraps r
15061506 return instance
15071507
15081508 try :
1509- with patch ('crystal.browser.SaveAsProgressDialog' , SaveAsProgressDialogSpy ):
1509+ with patch ('crystal.browser.main_window. SaveAsProgressDialog' , SaveAsProgressDialogSpy ):
15101510 async with wait_for_save_as_to_complete (project ):
15111511 # 1. Tell caller to start a Save As operation
15121512 # 2. Yield a placeholder for spies that will be updated when the dialog is created
@@ -1537,7 +1537,7 @@ def SaveAsProgressDialogSpy(*args, **kwargs): # wraps real constructor
15371537 try :
15381538 old_project_dirpath = project .path # capture
15391539 assert os .path .exists (old_project_dirpath )
1540- with patch ('crystal.browser.SaveAsProgressDialog' , SaveAsProgressDialogSpy ):
1540+ with patch ('crystal.browser.main_window. SaveAsProgressDialog' , SaveAsProgressDialogSpy ):
15411541 async with wait_for_save_as_to_complete (project ):
15421542 yield
15431543
0 commit comments