@@ -31,11 +31,10 @@ def validate_all_tests(config, request, config_file_model_version):
3131 elif config_file_model_version is not None :
3232 _from_command_line = request .config .getoption ("--model_version" )
3333 _from_config_file = config_file_model_version
34- if _from_command_line == _from_config_file :
35- validate_application_output (config )
34+ validate_application_output (config , _from_command_line , _from_config_file )
3635
3736
38- def validate_application_output (config ):
37+ def validate_application_output (config , from_command_line = None , from_config_file = None ):
3938 """
4039 Validate application output against expected output.
4140
@@ -45,31 +44,50 @@ def validate_application_output(config):
4544 ----------
4645 config: dict
4746 dictionary with the configuration for the application test.
47+ from_command_line: str
48+ Model version from the command line.
49+ from_config_file: str
50+ Model version from the configuration file.
4851
4952 """
5053 if "INTEGRATION_TESTS" not in config :
5154 return
5255
5356 for integration_test in config ["INTEGRATION_TESTS" ]:
5457 _logger .info (f"Testing application output: { integration_test } " )
55- if "REFERENCE_OUTPUT_FILE" in integration_test :
56- _validate_reference_output_file (config , integration_test )
57-
58- if "TEST_OUTPUT_FILES" in integration_test :
59- _validate_output_path_and_file (config , integration_test ["TEST_OUTPUT_FILES" ])
60- if "OUTPUT_FILE" in integration_test :
61- _validate_output_path_and_file (
62- config ,
63- [{"PATH_DESCRIPTOR" : "OUTPUT_PATH" , "FILE" : integration_test ["OUTPUT_FILE" ]}],
64- )
6558
66- if "FILE_TYPE" in integration_test :
67- assert assertions .assert_file_type (
68- integration_test ["FILE_TYPE" ],
69- Path (config ["CONFIGURATION" ]["OUTPUT_PATH" ]).joinpath (
70- config ["CONFIGURATION" ]["OUTPUT_FILE" ]
71- ),
72- )
59+ if from_command_line == from_config_file :
60+ if "REFERENCE_OUTPUT_FILE" in integration_test :
61+ _validate_reference_output_file (config , integration_test )
62+
63+ if "TEST_OUTPUT_FILES" in integration_test :
64+ _validate_output_path_and_file (config , integration_test ["TEST_OUTPUT_FILES" ])
65+
66+ if "OUTPUT_FILE" in integration_test :
67+ _validate_output_path_and_file (
68+ config ,
69+ [{"PATH_DESCRIPTOR" : "OUTPUT_PATH" , "FILE" : integration_test ["OUTPUT_FILE" ]}],
70+ )
71+
72+ if "FILE_TYPE" in integration_test :
73+ assert assertions .assert_file_type (
74+ integration_test ["FILE_TYPE" ],
75+ Path (config ["CONFIGURATION" ]["OUTPUT_PATH" ]).joinpath (
76+ config ["CONFIGURATION" ]["OUTPUT_FILE" ]
77+ ),
78+ )
79+ _test_simtel_cfg_files (config , integration_test , from_command_line , from_config_file )
80+
81+
82+ def _test_simtel_cfg_files (config , integration_test , from_command_line , from_config_file ):
83+ """Test simtel cfg files."""
84+ if "TEST_SIMTEL_CFG_FILES" in integration_test :
85+ if from_command_line :
86+ test_simtel_cfg_file = integration_test ["TEST_SIMTEL_CFG_FILES" ].get (from_command_line )
87+ else :
88+ test_simtel_cfg_file = integration_test ["TEST_SIMTEL_CFG_FILES" ].get (from_config_file )
89+ if test_simtel_cfg_file :
90+ _validate_simtel_cfg_files (config , test_simtel_cfg_file )
7391
7492
7593def _validate_reference_output_file (config , integration_test ):
@@ -238,3 +256,66 @@ def generate_mask(table, column, condition):
238256 return False
239257
240258 return True
259+
260+
261+ def _validate_simtel_cfg_files (config , simtel_cfg_file ):
262+ """
263+ Check sim_telarray configuration files and compare with reference file.
264+
265+ Note the finetuned naming of configuration files by simtools.
266+
267+ """
268+ reference_file = Path (simtel_cfg_file )
269+ test_file = Path (config ["CONFIGURATION" ]["OUTPUT_PATH" ]) / reference_file .name .replace (
270+ "_test" , f"_{ config ['CONFIGURATION' ]['LABEL' ]} "
271+ )
272+ _logger .info (
273+ f"Comparing simtel cfg files: { reference_file } and { test_file } "
274+ f"for model version { config ['CONFIGURATION' ]['MODEL_VERSION' ]} "
275+ )
276+ return _compare_simtel_cfg_files (reference_file , test_file )
277+
278+
279+ def _compare_simtel_cfg_files (reference_file , test_file ):
280+ """
281+ Compare two sim_telarray configuration files.
282+
283+ Line-by-line string comparison. Requires similar sequence of
284+ parameters in the files. Ignore lines containing 'config_release'
285+ (as it contains the simtools package version).
286+
287+ Parameters
288+ ----------
289+ reference_file: Path
290+ Reference sim_telarray configuration file.
291+ test_file: Path
292+ Test sim_telarray configuration file.
293+
294+ Returns
295+ -------
296+ bool
297+ True if the files are equal.
298+
299+ """
300+ with open (reference_file , encoding = "utf-8" ) as f1 , open (test_file , encoding = "utf-8" ) as f2 :
301+ reference_cfg = [line .rstrip () for line in f1 if line .strip ()]
302+ test_cfg = [line .rstrip () for line in f2 if line .strip ()]
303+
304+ if len (reference_cfg ) != len (test_cfg ):
305+ _logger .error (
306+ f"Line counts differ: { reference_file } ({ len (reference_cfg )} lines), "
307+ f"{ test_file } ({ len (test_cfg )} lines)."
308+ )
309+ return False
310+
311+ for ref_line , test_line in zip (reference_cfg , test_cfg ):
312+ if any (ignore in ref_line for ignore in ("config_release" , "Label" )):
313+ continue
314+ if ref_line != test_line :
315+ _logger .error (
316+ f"Configuration files { reference_file } and { test_file } do not match: "
317+ f"'{ ref_line } ' and '{ test_line } '"
318+ )
319+ return False
320+
321+ return True
0 commit comments