The dissmodel.executor.testing module provides ExecutorTestHarness, a
contract validator for ModelExecutor subclasses. It is designed to run
in Jupyter before opening a PR — the same checks are reused in CI via pytest,
so a passing notebook guarantees a passing pipeline.
ExecutorTestHarness — MyExecutor
────────────────────────────────────────────────────
✅ name attribute exists
✅ name is a non-empty string
✅ name has no whitespace
✅ load() is implemented
✅ run() is implemented
✅ save() is implemented
✅ run() signature is correct
✅ save() signature is correct
────────────────────────────────────────────────────
All 8 checks passed ✅
The run() signature is correct check validates that the executor uses the
0.4.0 signature run(self, data, record). Executors still using the old
run(self, record) form will fail here with a clear message:
❌ run() signature is correct: run() must accept exactly two parameters
(data, record), got ['record']. Did you update to the 0.4.0 signature?
Validates that an executor fulfills the ModelExecutor contract.
Designed to run in Jupyter before opening a PR — the same checks
are reused in CI via pytest parametrize, so a passing notebook
guarantees a passing pipeline.
Usage
harness = ExecutorTestHarness(MyExecutor)
harness.run_contract_tests() # structural — no data needed
harness.run_with_sample_data(record) # full cycle with real data
classExecutorTestHarness:""" Validates that an executor fulfills the ModelExecutor contract. Designed to run in Jupyter before opening a PR — the same checks are reused in CI via pytest parametrize, so a passing notebook guarantees a passing pipeline. Usage ----- harness = ExecutorTestHarness(MyExecutor) harness.run_contract_tests() # structural — no data needed harness.run_with_sample_data(record) # full cycle with real data """def__init__(self,executor_cls:type[ModelExecutor])->None:self.executor_cls=executor_clsself.executor=executor_cls()self._passed:list[str]=[]self._failed:list[str]=[]# ── Public interface ──────────────────────────────────────────────────────defrun_contract_tests(self)->bool:""" Run structural checks — no data required. Returns True if all checks pass. """self._passed.clear()self._failed.clear()self._check("name attribute exists",self._check_name_exists)self._check("name is a non-empty string",self._check_name_type)self._check("name has no whitespace",self._check_name_format)self._check("load() is implemented",self._check_load)self._check("run() is implemented",self._check_run)self._check("save() is implemented",self._check_save)self._check("run() signature is correct",self._check_run_signature)self._check("save() signature is correct",self._check_save_signature)self._print_report()returnlen(self._failed)==0defrun_with_sample_data(self,record:ExperimentRecord|None=None)->bool:""" Run the full executor lifecycle with real or synthetic data. Calls validate → load → run(data, record) → save in sequence. Returns True if the cycle completes without error. """ifrecordisNone:record=self._minimal_record()print(" No record provided — using minimal synthetic record")print(f"\n▶ Running {self.executor_cls.name}...")try:print(" validate()...")self.executor.validate(record)print(" load()...")data=self.executor.load(record)print(" run()...")result=self.executor.run(data,record)print(" save()...")completed=self.executor.save(result,record)ifcompleted.status!="completed":print(f" ⚠ save() returned status='{completed.status}' — expected 'completed'")returnFalseifnotcompleted.output_sha256:print(" ⚠ save() did not set output_sha256")returnFalseprint(f" ✅ Cycle OK — status={completed.status} sha256={completed.output_sha256[:12]}...")returnTrueexceptNotImplementedError:print(" ⚠ Some methods are not yet implemented")returnFalseexceptException:# noqa: BLE001 — test harness: any model failure must be reported, not crash the run; traceback is printed aboveprint(f" ❌ Error during execution:\n{traceback.format_exc()}")returnFalse# ── Individual checks ─────────────────────────────────────────────────────def_check_name_exists(self)->None:asserthasattr(self.executor_cls,"name"), \
"Class must define a 'name' class attribute"def_check_name_type(self)->None:assertisinstance(self.executor_cls.name,str)andself.executor_cls.name, \
f"'name' must be a non-empty string, got {self.executor_cls.name!r}"def_check_name_format(self)->None:assert" "notinself.executor_cls.name, \
f"'name' must not contain whitespace: {self.executor_cls.name!r}"def_check_load(self)->None:assertnot_is_abstract(self.executor,"load"), \
"load() must be implemented"def_check_run(self)->None:assertnot_is_abstract(self.executor,"run"), \
"run() must be implemented"def_check_save(self)->None:assertnot_is_abstract(self.executor,"save"), \
"save() must be implemented"def_check_run_signature(self)->None:sig=inspect.signature(self.executor.run)params=[pforpinsig.parameters.values()ifp.name!="self"]assertlen(params)==2,(f"run() must accept exactly two parameters (data, record), "f"got {[p.nameforpinparams]}. "f"Did you update to the 0.4.0 signature?")def_check_save_signature(self)->None:sig=inspect.signature(self.executor.save)params=[pforpinsig.parameters.values()ifp.name!="self"]assertlen(params)==2, \
f"save() must accept exactly two parameters (result, record), got {[p.nameforpinparams]}"# ── Helpers ───────────────────────────────────────────────────────────────def_check(self,label:str,fn)->None:try:fn()self._passed.append(label)exceptAssertionErrorasexc:self._failed.append(f"{label}: {exc}")exceptExceptionasexc:# noqa: BLE001 — test harness: any check failure must be recorded, not crash the run; message is captured aboveself._failed.append(f"{label}: unexpected error — {exc}")def_print_report(self)->None:print(f"\nExecutorTestHarness — {self.executor_cls.__name__}")print("─"*52)forlabelinself._passed:print(f" ✅ {label}")forlabelinself._failed:print(f" ❌ {label}")print("─"*52)ifself._failed:print(f" {len(self._passed)} passed, {len(self._failed)} failed\n")else:print(f" All {len(self._passed)} checks passed ✅\n")def_minimal_record(self)->ExperimentRecord:"""Synthetic record for contract testing without real data."""returnExperimentRecord(model_name=getattr(self.executor_cls,"name","unknown"),model_commit="local-test",code_version="dev",resolved_spec={"model":{"class":getattr(self.executor_cls,"name",""),"parameters":{}}},source=DataSource(type="local",uri=""),)
defrun_contract_tests(self)->bool:""" Run structural checks — no data required. Returns True if all checks pass. """self._passed.clear()self._failed.clear()self._check("name attribute exists",self._check_name_exists)self._check("name is a non-empty string",self._check_name_type)self._check("name has no whitespace",self._check_name_format)self._check("load() is implemented",self._check_load)self._check("run() is implemented",self._check_run)self._check("save() is implemented",self._check_save)self._check("run() signature is correct",self._check_run_signature)self._check("save() signature is correct",self._check_save_signature)self._print_report()returnlen(self._failed)==0
defrun_with_sample_data(self,record:ExperimentRecord|None=None)->bool:""" Run the full executor lifecycle with real or synthetic data. Calls validate → load → run(data, record) → save in sequence. Returns True if the cycle completes without error. """ifrecordisNone:record=self._minimal_record()print(" No record provided — using minimal synthetic record")print(f"\n▶ Running {self.executor_cls.name}...")try:print(" validate()...")self.executor.validate(record)print(" load()...")data=self.executor.load(record)print(" run()...")result=self.executor.run(data,record)print(" save()...")completed=self.executor.save(result,record)ifcompleted.status!="completed":print(f" ⚠ save() returned status='{completed.status}' — expected 'completed'")returnFalseifnotcompleted.output_sha256:print(" ⚠ save() did not set output_sha256")returnFalseprint(f" ✅ Cycle OK — status={completed.status} sha256={completed.output_sha256[:12]}...")returnTrueexceptNotImplementedError:print(" ⚠ Some methods are not yet implemented")returnFalseexceptException:# noqa: BLE001 — test harness: any model failure must be reported, not crash the run; traceback is printed aboveprint(f" ❌ Error during execution:\n{traceback.format_exc()}")returnFalse