scaffold.write_unit(spec, module, pace, risk)
Write the draft of scaffold_unit to disk, reload it and check it.
This is the sequence behind spotregen new-unit without --dry-run: draft the record, write it to regen/units/, load the file that now exists and run the unit check on it, so the caller sees at once what is still open.
Parameters
spec
RegenSpec
The loaded spec.
required
module
str
Dotted module name, with or without the package prefix.
required
pace
str
fast, medium or slow.
required
risk
str
low, medium or high.
required
Returns
tuple [Path , list [Finding ]]
tuple[Path, list[Finding]]: The path of the new record and the findings of spotregen.check_unit on it. A fresh draft always has UNIT06.
Raises
SpecError
If the module already has a unit record, pace or risk is unknown or the written file does not load.
FileNotFoundError
If the module has no file below the source directory.
Examples
from pathlib import Path
from tempfile import TemporaryDirectory
from spotregen import load_spec, make_sample_repo, write_unit
with TemporaryDirectory() as tmp:
root = make_sample_repo(Path(tmp) / "demo" )
(root / "regen/units/core.calc.toml" ).unlink()
target, findings = write_unit(load_spec(root), "core.calc" , "slow" , "high" )
print (target.relative_to(root))
print ([f.code for f in findings])
regen/units/core.calc.toml
['UNIT06']