from pathlib import Path from pygui.backend.data.file_browser import FileBrowser def _write_csv(path, wafer_id="P00001"): path.write_text( f"Wafer ID={wafer_id}\n" "Acquisition Date=03/26/2025\n" "Label,1,2,3\n" "X (mm),0,10,-10\n" "Y (mm),10,-10,-10\n" "data\n" "0.0,149.0,148.5,150.6\n" ) def test_recorded_live_file_flagged_as_recording(qapp, tmp_path): """Files named live__.csv (SessionController.startRecording) must be distinguishable in the browser from read-memory dumps.""" _write_csv(tmp_path / "live_P00001_20260706_143022.csv") _write_csv(tmp_path / "P00002-20260706_143500.csv") browser = FileBrowser() browser._set_current_directory(tmp_path) browser.refreshFiles() files_by_name = {Path(row["fileName"]).name: row for row in browser.files} assert files_by_name["live_P00001_20260706_143022.csv"]["isRecording"] is True assert files_by_name["P00002-20260706_143500.csv"]["isRecording"] is False def test_set_current_directory_updates_dir_and_refreshes(qapp, tmp_path): """setCurrentDirectory (no native dialog) is how the Status tab's save-dir picker keeps the Source panel pointed at the same folder.""" _write_csv(tmp_path / "P00003-20260706_143500.csv") browser = FileBrowser() browser.setCurrentDirectory(str(tmp_path)) assert browser.currentDirectory == str(tmp_path) assert len(browser.files) == 1 assert Path(browser.files[0]["fileName"]).name == "P00003-20260706_143500.csv"