diff --git a/simpleaudit/results.py b/simpleaudit/results.py index 72012e6..f7e7e37 100644 --- a/simpleaudit/results.py +++ b/simpleaudit/results.py @@ -247,6 +247,7 @@ def summary(self): def to_dict(self) -> Dict: return { + "version": "1.0", "timestamp": self.timestamp, "summary": { "total_scenarios": len(self.results), diff --git a/tests/test_audit_flow.py b/tests/test_audit_flow.py index 988c94b..5ad53f5 100644 --- a/tests/test_audit_flow.py +++ b/tests/test_audit_flow.py @@ -297,6 +297,28 @@ def test_save_produces_valid_json(self): finally: os.unlink(filepath) + def test_saved_json_carries_format_version(self): + """The export names its format version, as RepeatedExperimentResults does.""" + results = AuditResults([_make_audit_result()]) + assert results.to_dict()["version"] == "1.0" + + with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as f: + filepath = f.name + + try: + results.save(filepath) + with open(filepath) as f: + data = json.load(f) + assert data["version"] == "1.0" + + # Files written before the key existed still load. + del data["version"] + with open(filepath, "w") as f: + json.dump(data, f) + assert len(AuditResults.load(filepath)) == 1 + finally: + os.unlink(filepath) + # --- Plot smoke test ---