Skip to content

Commit 23c0dfb

Browse files
rwestclaude
andcommitted
Fix testKeysMatch: pop header metadata from both yamls, not just yaml1.
The previous union-of-pops version stripped 'date' only from ck2yaml output. Writer 1 also emits a 'date' header line so writer 1's date survived on yaml2, producing a spurious key mismatch. Switch to popping every known header field from both yamls in one loop. Also expand the assertion message to print the symmetric-difference key sets, so any future mismatch is self-diagnosing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f9e5d1f commit 23c0dfb

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

test/rmgpy/cantera_yaml_comparer.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,26 @@ def testGeneratorsAsExpected(self):
7373

7474
def testKeysMatch(self):
7575
"""Test that the top-level keys in both YAML files match, except those expected not to."""
76-
# Remove keys unique to each generator. dict.pop(key, None) is a no-op
77-
# when the key is absent, so it is safe to pop the union across both writers.
78-
self.yaml1.pop('input-files', None)
79-
self.yaml1.pop('cantera-version', None)
80-
self.yaml1.pop('date', None)
81-
self.yaml2.pop('cantera-version', None)
82-
self.yaml2.pop('description', None)
76+
# Strip header metadata that any of {ck2yaml, writer 1, writer 2} emits but
77+
# the others don't. Popping from both yamls (dict.pop(key, None) is a no-op
78+
# when absent) avoids per-writer special-casing and stays correct if a
79+
# writer later adds or drops one of these fields.
80+
metadata_keys = ('input-files', 'cantera-version', 'date', 'description')
81+
for key in metadata_keys:
82+
self.yaml1.pop(key, None)
83+
self.yaml2.pop(key, None)
8384
for model in [self.yaml1, self.yaml2]:
8485
for phase in model['phases']:
8586
for reactions_block in phase.get('reactions', []): # for multi-phase mechanisms, reactions are under each phase
8687
assert reactions_block in model, f"Expected reactions block '{reactions_block}' not found in YAML file."
8788
model.pop(reactions_block, None) # Remove reactions block to allow keys to match
88-
assert self.yaml1.keys() == self.yaml2.keys(), "YAML files have different top-level keys."
89+
only_in_yaml1 = set(self.yaml1) - set(self.yaml2)
90+
only_in_yaml2 = set(self.yaml2) - set(self.yaml1)
91+
assert not (only_in_yaml1 or only_in_yaml2), (
92+
f"YAML files have different top-level keys. "
93+
f"Only in yaml1 (ck2yaml): {sorted(only_in_yaml1)}; "
94+
f"only in yaml2 (RMG): {sorted(only_in_yaml2)}."
95+
)
8996

9097
def testPhasesMatch(self):
9198
"""Test that the phase definitions in both YAML files match."""

0 commit comments

Comments
 (0)