Input validation for collegeplan domain models.
validate_glide_path(glide_path)
Validate a glide path schedule.
Source code in src/collegeplan/validators.py
| def validate_glide_path(glide_path: GlidePath) -> None:
"""Validate a glide path schedule."""
if not glide_path.steps:
raise ValidationError("GlidePath must have at least one step")
for attr in ("equity_return", "bond_return", "short_term_return"):
val = getattr(glide_path, attr)
if not -0.05 <= val <= 0.30:
raise ValidationError(f"{attr} {val} is outside the plausible range [-0.05, 0.30]")
prev_yte: int | None = None
for step in glide_path.steps:
for pct_name in ("equity_pct", "bond_pct", "short_term_pct"):
pct = getattr(step, pct_name)
if not 0 <= pct <= 1:
raise ValidationError(
f"{pct_name} {pct} is outside [0, 1] "
f"at years_to_enrollment={step.years_to_enrollment}"
)
total = step.equity_pct + step.bond_pct + step.short_term_pct
if abs(total - 1.0) > 0.01:
raise ValidationError(
f"Allocation percentages sum to {total}, expected 1.0 "
f"at years_to_enrollment={step.years_to_enrollment}"
)
if prev_yte is not None and step.years_to_enrollment >= prev_yte:
raise ValidationError(
"GlidePath steps must be sorted descending by years_to_enrollment"
)
prev_yte = step.years_to_enrollment
|
validate_plan(children, assumptions, household_fund=None)
Validate all inputs for a projection or solver run.
Source code in src/collegeplan/validators.py
| def validate_plan(
children: list[Child],
assumptions: Assumptions,
household_fund: HouseholdFund | None = None,
) -> None:
"""Validate all inputs for a projection or solver run."""
if not children:
raise ValidationError("At least one child is required")
validate_assumptions(assumptions)
for child in children:
validate_child(child)
if household_fund is not None:
validate_household_fund(household_fund)
|