77import itertools
88
99
10+ # Run pipeline in test mode, this is done once per test session
1011@pytest .fixture (scope = "session" , autouse = True )
11- def result_dir (tmpdir_factory ):
12+ def run_pipeline (tmpdir_factory ):
1213 result_dir = tmpdir_factory .mktemp ("results" )
1314 subprocess .run (
1415 [
@@ -25,46 +26,65 @@ def result_dir(tmpdir_factory):
2526 yield result_dir
2627
2728
29+ # Returns directory where pipeline results have been written.
30+ # All tests use this folder as input, veryfing that reports
31+ # have been generated as expected.
2832@pytest .fixture
29- def flowcell_report_dir ( result_dir ):
30- return os . path . join ( result_dir , "flowcell_report" )
33+ def result_dir ( run_pipeline ):
34+ return run_pipeline
3135
3236
33- @ pytest . fixture
34- def project_reports_dir (result_dir ):
35- return os .path .join (result_dir , "projects" )
37+ def test_results_dirs_exist ( result_dir ):
38+ flowcell_dir = os . path . join (result_dir , "flowcell_report" )
39+ projects_dir = os .path .join (result_dir , "projects" )
3640
41+ assert os .path .isdir (flowcell_dir )
42+ assert os .path .isdir (projects_dir )
3743
38- @pytest .fixture
39- def projects ():
40- return ["Zymo" , "Qiagen" , "NoProject" ]
4144
45+ def test_project_dirs_exist (result_dir ):
46+ projects_dir = os .path .join (result_dir , "projects" )
47+ projects = ["Zymo" , "Qiagen" , "NoProject" ]
4248
43- @pytest .fixture
44- def flowcell_report (flowcell_report_dir ):
45- return os .path .join (
46- flowcell_report_dir , "210510_M03910_0104_000000000-JHGJL_multiqc_report.html"
49+ for project in projects :
50+ assert os .path .isdir (os .path .join (projects_dir , project ))
51+
52+
53+ def test_flowcell_report_exist (result_dir ):
54+ flowcell_dir = os .path .join (result_dir , "flowcell_report" )
55+ report_path = os .path .join (
56+ flowcell_dir , "210510_M03910_0104_000000000-JHGJL_multiqc_report.html"
4757 )
4858
59+ assert os .path .isfile (report_path )
60+
61+
62+ def test_project_reports_exist (result_dir ):
63+ projects_dir = os .path .join (result_dir , "projects" )
64+ projects = ["Zymo" , "Qiagen" , "NoProject" ]
4965
50- @pytest .fixture
51- def project_reports (project_reports_dir , projects ):
52- report_list = []
5366 for project in projects :
54- report_list .append (
55- os .path .join (
56- project_reports_dir ,
57- project ,
58- "210510_M03910_0104_000000000-JHGJL_"
59- + project
60- + "_multiqc_report.html" ,
61- )
67+ report_path = os .path .join (
68+ projects_dir ,
69+ project ,
70+ "210510_M03910_0104_000000000-JHGJL_" + project + "_multiqc_report.html" ,
6271 )
63- return report_list
72+ assert os . path . isfile ( report_path )
6473
6574
66- @pytest .fixture
67- def flowcell_report_sections ():
75+ def check_sections_in_report (report_path , sections ):
76+ with open (report_path , "r" ) as html_file :
77+ parser = BeautifulSoup (html_file .read (), "lxml" )
78+ for section in sections :
79+ hits = parser .find_all (href = "#" + section )
80+ assert len (hits ) > 0
81+
82+
83+ def test_all_sections_included_in_flowcell_report (result_dir ):
84+ flowcell_dir = os .path .join (result_dir , "flowcell_report" )
85+ report_path = os .path .join (
86+ flowcell_dir , "210510_M03910_0104_000000000-JHGJL_multiqc_report.html"
87+ )
6888 sections = [
6989 "general_stats" ,
7090 "rrna" ,
@@ -74,47 +94,25 @@ def flowcell_report_sections():
7494 "fastq_screen" ,
7595 "fastqc" ,
7696 ]
77- return sections
7897
98+ check_sections_in_report (report_path , sections )
7999
80- @pytest .fixture
81- def project_report_sections ():
100+
101+ def test_all_sections_included_in_project_reports (result_dir ):
102+ projects_dir = os .path .join (result_dir , "projects" )
103+ projects = ["Zymo" , "Qiagen" , "NoProject" ]
82104 sections = [
83105 "general_stats" ,
84106 "rrna" ,
85107 "sequencing_metadata" ,
86108 "fastq_screen" ,
87109 "fastqc" ,
88110 ]
89- return sections
90-
91-
92- def test_results_dirs_exist (flowcell_report_dir , project_reports_dir ):
93- assert os .path .isdir (flowcell_report_dir )
94- assert os .path .isdir (project_reports_dir )
95-
96111
97- def test_project_dirs_exist (project_reports_dir , projects ):
98112 for project in projects :
99- assert os .path .isdir (os .path .join (project_reports_dir , project ))
100-
101-
102- def test_reports_exist (flowcell_report , project_reports ):
103- reports = project_reports + [flowcell_report ]
104- for report in reports :
105- assert os .path .isfile (report )
106-
107-
108- def test_all_sections_included (
109- flowcell_report , flowcell_report_sections , project_reports , project_report_sections
110- ):
111- def check_sections_in_reports (reports , sections ):
112- for report_path in reports :
113- with open (report_path , "r" ) as html_file :
114- parser = BeautifulSoup (html_file .read (), "lxml" )
115- for section in sections :
116- hits = parser .find_all (href = "#" + section )
117- assert len (hits ) > 0
118-
119- check_sections_in_reports ([flowcell_report ], flowcell_report_sections )
120- check_sections_in_reports (project_reports , project_report_sections )
113+ report_path = os .path .join (
114+ projects_dir ,
115+ project ,
116+ "210510_M03910_0104_000000000-JHGJL_" + project + "_multiqc_report.html" ,
117+ )
118+ check_sections_in_report (report_path , sections )
0 commit comments