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