-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathtest_gui.py
134 lines (114 loc) · 4.28 KB
/
test_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from streamlit.testing.v1 import AppTest
import pytest
from src import fileupload
import json
from pathlib import Path
import shutil
@pytest.fixture
def launch(request):
test = AppTest.from_file(request.param)
## Initialize session state ##
with open("settings.json", "r") as f:
test.session_state.settings = json.load(f)
test.session_state.settings["test"] = True
test.secrets["workspace"] = "test"
return test
# Test launching of all pages
@pytest.mark.parametrize(
"launch",
(
# "content/quickstart.py", # NOTE: this page does not work due to streamlit.errors.StreamlitPageNotFoundError error
"content/documentation.py",
"content/topp_workflow_file_upload.py",
"content/topp_workflow_parameter.py",
"content/topp_workflow_execution.py",
"content/topp_workflow_results.py",
"content/file_upload.py",
"content/raw_data_viewer.py",
"content/run_example_workflow.py",
"content/download_section.py",
"content/simple_workflow.py",
"content/run_subprocess.py",
),
indirect=True,
)
def test_launch(launch):
"""Test if all pages can be launched without errors."""
launch.run(timeout=30) # Increased timeout from 10 to 30 seconds
assert not launch.exception
########### PAGE SPECIFIC TESTS ############
@pytest.mark.parametrize(
"launch,selection",
[
("content/documentation.py", "User Guide"),
("content/documentation.py", "Installation"),
(
"content/documentation.py",
"Developers Guide: How to build app based on this template",
),
("content/documentation.py", "Developers Guide: TOPP Workflow Framework"),
("content/documentation.py", "Developer Guide: Windows Executables"),
("content/documentation.py", "Developers Guide: Deployment"),
],
indirect=["launch"],
)
def test_documentation(launch, selection):
launch.run()
launch.selectbox[0].select(selection).run()
assert not launch.exception
@pytest.mark.parametrize("launch", ["content/file_upload.py"], indirect=True)
def test_file_upload_load_example(launch):
launch.run()
for i in launch.tabs:
if i.label == "Example Data":
i.button[0].click().run()
assert not launch.exception
# NOTE: All tabs are automatically checked
@pytest.mark.parametrize(
"launch,example",
[
("content/raw_data_viewer.py", "Blank.mzML"),
("content/raw_data_viewer.py", "Treatment.mzML"),
("content/raw_data_viewer.py", "Pool.mzML"),
("content/raw_data_viewer.py", "Control.mzML"),
],
indirect=["launch"],
)
def test_view_raw_ms_data(launch, example):
launch.run(timeout=30) # Increased timeout from 10 to 30 seconds
## Load Example file, based on implementation of fileupload.load_example_mzML_files() ###
mzML_dir = Path(launch.session_state.workspace, "mzML-files")
# Copy files from example-data/mzML to workspace mzML directory, add to selected files
for f in Path("example-data", "mzML").glob("*.mzML"):
shutil.copy(f, mzML_dir)
launch.run()
## TODO: Figure out a way to select a spectrum to be displayed
launch.selectbox[0].select(example).run()
assert not launch.exception
@pytest.mark.parametrize(
"launch,example",
[
("content/run_example_workflow.py", ["Blank"]),
("content/run_example_workflow.py", ["Treatment"]),
("content/run_example_workflow.py", ["Pool"]),
("content/run_example_workflow.py", ["Control"]),
("content/run_example_workflow.py", ["Control", "Blank"]),
],
indirect=["launch"],
)
def test_run_workflow(launch, example):
launch.run()
## Load Example file, based on implementation of fileupload.load_example_mzML_files() ###
mzML_dir = Path(launch.session_state.workspace, "mzML-files")
# Copy files from example-data/mzML to workspace mzML directory, add to selected files
for f in Path("example-data", "mzML").glob("*.mzML"):
shutil.copy(f, mzML_dir)
launch.run()
## Select experiments to process
for e in example:
launch.multiselect[0].select(e)
launch.run()
assert not launch.exception
# Press the "Run Workflow" button
launch.button[1].click().run(timeout=60)
assert not launch.exception