1+ import logging
12import re
23from pathlib import Path
34from typing import Dict , List , Union
45
5- from nf_core .utils import load_tools_config
6+ from nf_core .utils import load_tools_config , run_cmd
7+
8+ log = logging .getLogger (__name__ )
69
710
811def nf_test_content (self ) -> Dict [str , List [str ]]:
@@ -120,6 +123,27 @@ def nf_test_content(self) -> Dict[str, List[str]]:
120123
121124 # Content of nextflow.config file
122125 conf_fn = Path (self .wf_path , "tests" , "nextflow.config" )
126+
127+ # Get the CPU, memory and time values defined in the test profile configuration.
128+ cmd = f"config -profile test -flat { self .wf_path } "
129+ result = run_cmd ("nextflow" , cmd )
130+ config_values = {"cpus" : "4" , "memory" : "15.GB" , "time" : "1.h" }
131+ if result is not None :
132+ stdout , _ = result
133+ for config_line in stdout .splitlines ():
134+ ul = config_line .decode ("utf-8" )
135+ try :
136+ k , v = ul .split (" = " , 1 )
137+ if k == "cpus" :
138+ config_values ["cpus" ] = v .strip ("'\" " )
139+ elif k == "memory" :
140+ config_values ["memory" ] = v .strip ("'\" " )
141+ elif k == "time" :
142+ config_values ["time" ] = v .strip ("'\" " )
143+ except ValueError :
144+ log .debug (f"Couldn't find key=value config pair:\n { ul } " )
145+ pass
146+
123147 config_checks : Dict [str , Dict [str , str ]] = {
124148 "modules_testdata_base_path" : {
125149 "pattern" : "modules_testdata_base_path" ,
@@ -130,16 +154,16 @@ def nf_test_content(self) -> Dict[str, List[str]]:
130154 "description" : "`pipelines_testdata_base_path`" ,
131155 },
132156 "cpus" : {
133- "pattern" : "cpus: *[\" ']?4 [\" ']?" ,
134- "description" : "correct CPU resource limits. Should be 4 " ,
157+ "pattern" : f "cpus: *[\" ']?{ config_values [ 'cpus' ] } [\" ']?" ,
158+ "description" : f "correct CPU resource limits. Should be { config_values [ 'cpus' ] } " ,
135159 },
136160 "memory" : {
137- "pattern" : "memory: *[\" ']?15\.GB [\" ']?" ,
138- "description" : "correct memory resource limits. Should be 15.GB " ,
161+ "pattern" : f "memory: *[\" ']?{ config_values [ 'memory' ] } [\" ']?" ,
162+ "description" : f "correct memory resource limits. Should be { config_values [ 'memory' ] } " ,
139163 },
140164 "time" : {
141- "pattern" : "time: *[\" ']?1\.h [\" ']?" ,
142- "description" : "correct time resource limits. Should be 1.h " ,
165+ "pattern" : f "time: *[\" ']?{ config_values [ 'time' ] } [\" ']?" ,
166+ "description" : f "correct time resource limits. Should be { config_values [ 'time' ] } " ,
143167 },
144168 }
145169
0 commit comments