-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
test_yaml.py
53 lines (43 loc) · 1.67 KB
/
test_yaml.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
"""Consistency check between yaml files and script files.
Authors
* Mirco Ravanelli 2022
"""
import os
import csv
from tests.consistency.test_recipe import __skip_list
from tests.utils.check_yaml import check_yaml_vs_script
def test_yaml_script_consistency(recipe_folder="tests/recipes"):
"""This test checks the consistency between yaml files (used to specify
hyperparameters) and script files (that implement the training recipe).
Arguments
---------
recipe_folder : path
Path of the folder with csv files containing the training scripts with their coupled
yaml files (with colums called 'Hparam_file', 'Script_file', 'Data_prep_file')
"""
# Use this list to itemize special yaml for which we do not have to test
avoid_check = []
check = True
# Loop over all recipe CSVs
for recipe_csvfile in os.listdir(recipe_folder):
if recipe_csvfile in __skip_list:
continue
with open(
os.path.join(recipe_folder, recipe_csvfile), newline=""
) as csvfile:
reader = csv.DictReader(
csvfile, delimiter=",", skipinitialspace=True
)
for row in reader:
# Avoid checks
if row["Hparam_file"] in avoid_check:
continue
# Check yaml-script consistency
if not (
check_yaml_vs_script(row["Hparam_file"], row["Script_file"])
):
check = False
# Check module variables
# if not (check_module_vars(row["Hparam_file"], row["Script_file"])):
# check = False
assert check