Coverage for backend/django/core/auxiliary/formula_units.py: 67%
8 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-22 05:22 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-22 05:22 +0000
1from __future__ import annotations
4def formula_unit_expression(unit: str) -> str | None:
5 """Render a project unit string in the syntax accepted by formula expressions."""
7 cleaned = unit.strip()
8 if not cleaned: 8 ↛ 9line 8 didn't jump to line 9 because the condition on line 8 was never true
9 return ""
10 if not all(char.isalnum() or char in {"_", "/", "*", "^", ".", " "} for char in cleaned): 10 ↛ 11line 10 didn't jump to line 11 because the condition on line 10 was never true
11 return None
12 return cleaned.replace("^", "**").replace("/", " / ")