@@ -39,50 +39,60 @@ def test_database_duplicate(monkeypatch, qtbot, basic_database):
3939 assert dup_db in bd .databases
4040
4141
42- def test_database_export_excel (monkeypatch , qtbot , basic_database ):
42+ def test_database_export_excel (monkeypatch , qtbot , basic_database , tmp_path ):
4343 """Test exporting a database to Excel format."""
44+ from activity_browser .actions .database .database_export_excel import ExportExcelSetup
45+
4446 # Mock the file dialog to return a path
45- test_path = "test_export.xlsx"
47+ test_path = str ( tmp_path / "test_export.xlsx" )
4648 monkeypatch .setattr (
4749 QtWidgets .QFileDialog ,
4850 "getSaveFileName" ,
4951 staticmethod (lambda * args , ** kwargs : (test_path , "" )),
5052 )
5153
52- # Mock the confirmation dialog
53- monkeypatch .setattr (
54- QtWidgets .QMessageBox ,
55- "question" ,
56- staticmethod (lambda * args , ** kwargs : QtWidgets .QMessageBox .Yes ),
57- )
58-
54+ # Call the action
5955 actions .DatabaseExportExcel .run ([basic_database .name ])
6056
61- # The export happens in a thread, so we need to wait for it
62- # For now, just check that no error was raised
57+ # Find the wizard dialog and wait for the export thread to finish
58+ wizard = application .main_window .findChild (ExportExcelSetup )
59+ assert wizard is not None
60+
61+ # Wait for the export thread to finish
62+ export_page = wizard .currentPage ()
63+ with qtbot .waitSignal (export_page .thread .finished , timeout = 10 * 1000 ):
64+ pass
65+
66+ # Close the wizard
67+ wizard .close ()
6368
6469
65- def test_database_export_bw2package (monkeypatch , qtbot , basic_database ):
70+ def test_database_export_bw2package (monkeypatch , qtbot , basic_database , tmp_path ):
6671 """Test exporting a database to BW2Package format."""
72+ from activity_browser .actions .database .database_export_bw2package import ExportBW2PackageSetup
73+
6774 # Mock the file dialog to return a path
68- test_path = "test_export.bw2package"
75+ test_path = str ( tmp_path / "test_export.bw2package" )
6976 monkeypatch .setattr (
7077 QtWidgets .QFileDialog ,
7178 "getSaveFileName" ,
7279 staticmethod (lambda * args , ** kwargs : (test_path , "" )),
7380 )
7481
75- # Mock the confirmation dialog
76- monkeypatch .setattr (
77- QtWidgets .QMessageBox ,
78- "question" ,
79- staticmethod (lambda * args , ** kwargs : QtWidgets .QMessageBox .Yes ),
80- )
81-
82+ # Call the action
8283 actions .DatabaseExportBW2Package .run ([basic_database .name ])
8384
84- # The export happens in a thread, so we need to wait for it
85- # For now, just check that no error was raised
85+ # Find the wizard dialog and wait for the export thread to finish
86+ wizard = application .main_window .findChild (ExportBW2PackageSetup )
87+ assert wizard is not None
88+
89+ # Wait for the export thread to finish
90+ export_page = wizard .currentPage ()
91+ with qtbot .waitSignal (export_page .thread .finished , timeout = 10 * 1000 ):
92+ pass
93+
94+ # Close the wizard
95+ wizard .close ()
8696
8797
8898def test_database_new (monkeypatch , basic_database ):
0 commit comments