Coverage for venv1 / lib / python3.10 / site-packages / combinatrix / testintegration.py: 67%
43 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-04 09:41 +0100
1import os
2from combinatrix.core import fromcsv, fromjsonfile, load_matrix, CombinatrixException
5def load_parameter_sets(bundle_path, bundle_name, name_field, filters=None, newer_than_tolerance=5.0):
6 if bundle_path is None:
7 raise CombinatrixException("You must supply a bundle_path")
8 if bundle_name is None:
9 raise CombinatrixException("You must supply a bundle_name")
10 if name_field is None:
11 raise CombinatrixException("You must supply a name_field")
13 source_csv = os.path.join(bundle_path, bundle_name + ".settings.csv")
14 source_json = os.path.join(bundle_path, bundle_name + ".settings.json")
15 matrix_csv = os.path.join(bundle_path, bundle_name + ".matrix.csv")
17 parameters = None
19 if os.path.exists(source_csv):
20 parameters = fromcsv(source_csv, matrix_csv, source_json)
21 elif os.path.exists(source_json):
22 parameters = fromjsonfile(source_json, matrix_csv)
23 elif os.path.exists(matrix_csv):
24 parameters = load_matrix(matrix_csv)
26 """
27 source_csv_mod = None
28 if os.path.exists(source_csv):
29 source_csv_mod = os.path.getmtime(source_csv)
31 source_json_mod = None
32 if os.path.exists(source_json):
33 source_json_mod = os.path.getmtime(source_json)
35 matrix_csv_mod = None
36 if os.path.exists(matrix_csv):
37 matrix_csv_mod = os.path.getmtime(matrix_csv)
40 parameters = None
42 if source_csv_mod is not None:
43 if source_json_mod is not None and source_json_mod > source_csv_mod + newer_than_tolerance:
44 raise CombinatrixException("Both CSV and JSON settings are present, and the JSON is newer than the CSV")
45 if matrix_csv_mod is not None and matrix_csv_mod > source_csv_mod + newer_than_tolerance:
46 raise CombinatrixException("Both CSV and Matrix are present, and the matrix is newer than the CSV")
48 parameters = fromcsv(source_csv, matrix_csv, source_json)
50 if parameters is None:
51 if source_json_mod is not None:
52 if matrix_csv_mod is not None and matrix_csv_mod > source_json_mod + newer_than_tolerance:
53 raise CombinatrixException("Both JSON and Matrix are present, and the matrix is newer than the CSV")
55 parameters = fromjsonfile(source_json, matrix_csv)
57 if matrix_csv_mod is not None:
58 parameters = load_matrix(matrix_csv)
59 """
61 if parameters is None:
62 raise CombinatrixException("No viable build approach for bundle " + bundle_name + " at " + bundle_path)
64 # check that the name field we've been given exists
65 for p in parameters:
66 if p.get(name_field) is None:
67 raise CombinatrixException("At least one record does not contain the name_field")
69 if filters is None:
70 return [(p[name_field], p) for p in parameters]
72 filtered = []
73 for p in parameters:
74 counter = 0
75 for field, allowed_values in filters.items():
76 if len(allowed_values) == 0:
77 counter += 1
78 elif p[field] in allowed_values:
79 counter += 1
80 if counter == len(list(filters.keys())):
81 filtered.append((p[name_field], p))
83 return filtered
86def rel2abs(file, *args):
87 file = os.path.realpath(file)
88 if os.path.isfile(file):
89 file = os.path.dirname(file)
90 return os.path.abspath(os.path.join(file, *args))