From 298d0af1e41b56ae2d3e35ff470edb94d248f5e2 Mon Sep 17 00:00:00 2001 From: "h0an.le" Date: Thu, 26 Sep 2024 13:57:48 +0200 Subject: [PATCH] add script for test_2_loading_saved_files --- app/visualisation.py | 2 +- examples/ex_loading_saved_files.py | 33 +++++++++++++++++++++++++++++ tests/test_2.py | 6 ------ tests/test_2_loading_saved_files.py | 11 ++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 examples/ex_loading_saved_files.py delete mode 100644 tests/test_2.py create mode 100644 tests/test_2_loading_saved_files.py diff --git a/app/visualisation.py b/app/visualisation.py index e36637e..6bdc5f8 100644 --- a/app/visualisation.py +++ b/app/visualisation.py @@ -793,7 +793,7 @@ def load(self, file_path): self.original_dfs[k] = pd.read_csv(StringIO(csv_data)) self.update_dfs_list() - + # Load plots plots_data = load.get('plots', {}) for graph_id, graph_data in plots_data.items(): diff --git a/examples/ex_loading_saved_files.py b/examples/ex_loading_saved_files.py new file mode 100644 index 0000000..709cd79 --- /dev/null +++ b/examples/ex_loading_saved_files.py @@ -0,0 +1,33 @@ +import sys +import os +from pathlib import Path + +from PySide6.QtWidgets import QApplication +from PySide6.QtGui import QIcon + +from app.main import Main + +def ex_loading_saved_files(run_app=True): + """Example of reading different supported .CSV and .txt data formats""" + + DATA_DIR = Path(__file__).parent + file_paths = [str(file) for ext in ['*.maps', '*.spectra'] for file in DATA_DIR.glob(ext)] + + app = QApplication.instance() or QApplication([]) + window = Main() + app.setStyle("Fusion") + + if file_paths is None or len(file_paths) == 0: + raise ValueError("No valid file paths provided.") + try: + window.open(file_paths=file_paths) + except Exception as e: + raise RuntimeError(f"Failed to open files: {e}") + + window.ui.show() + + if run_app: + sys.exit(app.exec()) + +if __name__ == "__main__": + ex_loading_saved_files() \ No newline at end of file diff --git a/tests/test_2.py b/tests/test_2.py deleted file mode 100644 index 087febb..0000000 --- a/tests/test_2.py +++ /dev/null @@ -1,6 +0,0 @@ -import pytest - -def test_2(): - print('test pytest') - - \ No newline at end of file diff --git a/tests/test_2_loading_saved_files.py b/tests/test_2_loading_saved_files.py new file mode 100644 index 0000000..229b2a6 --- /dev/null +++ b/tests/test_2_loading_saved_files.py @@ -0,0 +1,11 @@ +# Test_1 +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) + +import pytest +from examples.ex_loading_saved_files import ex_loading_saved_files + +def test_loading_saved_files(qtbot): + ex_loading_saved_files(run_app=False)