Skip to content

Commit

Permalink
enh: enforce info.json schema
Browse files Browse the repository at this point in the history
Adds a test that both:
  - ensures that LS_FIELD_CHOICES represents all info.json fields
  - ensure that info.json fields have not changed (which would require a
    version bump, and a change to the field transformations)
  • Loading branch information
asmacdo committed Feb 21, 2025
1 parent b7daaec commit 10615ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/con_duct/suite/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"num_samples",
"num_reports",
"stderr",
"stdout",
"cpu_total",
"logs_prefix",
"usage",
"info",
"prefix",
Expand Down Expand Up @@ -72,10 +75,14 @@ def load_duct_runs(
f"is below minimum schema version {MINIMUM_SCHEMA_VERSION}."
)
continue
if eval_filter is not None and not (eval_results := eval(
eval_filter, _flatten_dict(this), dict(re=re)
)):
lgr.debug("Filtering out %s due to filter results matching: %s", this, eval_results)
if eval_filter is not None and not (
eval_results := eval(eval_filter, _flatten_dict(this), dict(re=re))
):
lgr.debug(
"Filtering out %s due to filter results matching: %s",
this,
eval_results,
)
continue

loaded.append(this)
Expand Down
31 changes: 31 additions & 0 deletions test/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json
import os
from pathlib import Path
from con_duct.__main__ import Arguments, execute
from con_duct.suite.ls import LS_FIELD_CHOICES, _flatten_dict


def test_info_fields(temp_output_dir: str) -> None:
"""
Generate the list of fields users can request when viewing info files.
Fails when schema changes-- commit the new version and bump schema version
"""
args = Arguments.from_argv(
["echo", "hello", "world"],
sample_interval=4.0,
report_interval=60.0,
output_prefix=temp_output_dir,
clobber=True,
)
# Execute duct
assert execute(args) == 0 # exit_code
os.remove(Path(temp_output_dir, "stdout"))
os.remove(Path(temp_output_dir, "stderr"))
os.remove(Path(temp_output_dir, "usage.json"))

info_file = Path(temp_output_dir, "info.json")
actual_info_schema = _flatten_dict(json.loads(info_file.read_text())).keys()
os.remove(info_file)

assert set(actual_info_schema) == set(LS_FIELD_CHOICES)

0 comments on commit 10615ee

Please sign in to comment.