6Merge tests for multi-include semantics (no pytest), using neutral keys foo/bar.
9 python ConfigText_merge_unitTest.py --dir AnalysisAlgorithmsConfig
10 python ConfigText_merge_unitTest.py --case all --dir path/to/yamls
19from AnalysisAlgorithmsConfig.ConfigText
import combineConfigFiles, TextConfigWarning
23 with p.open(
"r")
as f:
24 return yaml.safe_load(f)
28 raise AssertionError(msg)
32 top = yaml.safe_load(yaml.safe_dump(top_cfg))
33 changed = combineConfigFiles(top, base_dir, fragment_key=
"include")
34 _assert(changed
is True,
"combineConfigFiles reported no changes")
35 _assert(
"include" not in top,
"include key should be removed after merging")
40 Nested include: earlier wins inside test_merge_mid, local overrides afterward.
42 top_cfg =
_load_yaml(base_dir /
"test_merge_top.yaml")
46 _assert(merged[
"a"] == 2,
"Expected 'a' == 2 from override.json")
49 _assert(merged[
"nested"][
"y"] == 20,
"Expected nested.y == 20 from override.json")
50 _assert(merged[
"nested"][
"x"] == 999,
"Local override of nested.x should win")
53 _assert(abs(merged[
"bar"][
"rate"] - 0.1) < 1e-12,
"Expected bar.rate from frag_a (0.1)")
54 _assert(merged[
"foo"][
"alpha"] == 1
and merged[
"foo"][
"beta"] ==
"A",
55 "Expected foo.{alpha,beta} from frag_a")
58 _assert(merged[
"bar"][
"size"] == 32,
"Local bar.size should override frag_a (32 vs 64)")
61 _assert(merged[
"local_only"]
is True,
"Local-only key should remain")
65 Direct include [frag_a, frag_b]: earlier (a) wins on scalar conflicts; lists concat.
68 "include": [
"test_merge_frag_a.yaml",
"test_merge_frag_b.yaml"]
73 _assert(merged[
"foo"][
"alpha"] == 1,
"Earlier frag_a should win foo.alpha")
74 _assert(merged[
"foo"][
"beta"] ==
"A",
"Earlier frag_a should win foo.beta")
75 _assert(abs(merged[
"bar"][
"rate"] - 0.1) < 1e-12,
"Earlier frag_a should win bar.rate")
78 _assert(merged[
"bar"][
"size"] == 64,
"bar.size should come from frag_a")
81 _assert(merged[
"nums"] == [1, 2, 3],
"Expected nums concatenation [1,2,3]")
84 _assert(merged[
"only_in_b"]
is True,
"Key unique to later fragment should be present")
87 """Lists concatenate without deduplication."""
88 top_cfg =
_load_yaml(base_dir /
"test_merge_list_top.yaml")
90 _assert(merged[
"items"] == [1, 2, 3],
"items should concatenate")
91 _assert(merged[
"dups"] == [1, 1, 1],
"dups should concatenate without dedup")
94 """Single-string include path is supported, but should warn for deprecation."""
95 top_cfg =
_load_yaml(base_dir /
"test_merge_single_top.yaml")
98 with warnings.catch_warnings(record=
True)
as w:
99 warnings.simplefilter(
"always", TextConfigWarning)
105 str(rec.message)
for rec
in w
106 if issubclass(rec.category, TextConfigWarning)
111 any(
"should be followed with a list of files" in m
for m
in msgs),
112 "Expected TextConfigWarning about include needing a list",
116 _assert(merged[
"foo"][
"alpha"] == 1,
"Single include should resolve frag_a (foo.alpha)")
117 _assert(merged[
"only_in_a"]
is True,
"Value from frag_a should appear")
121 "earlier_wins": case_earlier_wins,
122 "earlier_wins_between_fragments": case_earlier_wins_between_fragments,
123 "list_concat": case_list_concat,
124 "single_string_include": case_single_string_include,
128 print(f
"→ {k} ... ", end=
"", flush=
True)
134 traceback.print_exc()
137 if name
not in mapping:
138 sys.exit(f
"Unknown case '{name}'. Choose from: all, " +
", ".join(mapping))
139 print(f
"→ {name} ... ", end=
"", flush=
True)
140 mapping[name](base_dir)
144 ap = argparse.ArgumentParser()
145 ap.add_argument(
"--dir", dest=
"yamldir", required=
True,
146 help=
"Directory where the test_merge_*.yaml/json files live")
147 ap.add_argument(
"--case", default=
"all",
149 "all",
"earlier_wins",
"earlier_wins_between_fragments",
150 "list_concat",
"single_string_include"],
151 help=
"Which case to run (default: all)")
152 args = ap.parse_args()
155 os.environ[
"DATAPATH"] =
""
156 from PathResolver
import PathResolver
158 base_dir = pathlib.Path(base_dir)
159 if not base_dir.is_dir():
160 sys.exit(f
"--dir {base_dir} is not a directory")
164if __name__ ==
"__main__":
void print(char *figname, TCanvas *c1)
static std::string FindCalibDirectory(const std::string &logical_file_name)
case_earlier_wins_between_fragments(pathlib.Path base_dir)
_load_yaml(pathlib.Path p)
_run_merge(dict top_cfg, pathlib.Path base_dir)
case_earlier_wins(pathlib.Path base_dir)
run_case(str name, pathlib.Path base_dir)
case_list_concat(pathlib.Path base_dir)
case_single_string_include(pathlib.Path base_dir)