Coverage for backend/django/idaes_factory/adapters/convert_expression.py: 88%
24 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
1import re
3def convert_expression(expression: str | None) -> str:
4 if expression is None: 4 ↛ 5line 4 didn't jump to line 5 because the condition on line 4 was never true
5 raise ValueError("Unexpected null expression")
7 def replacer(match):
8 id = match.group(1) # Get the id from the match
9 if id.startswith("prop"):
10 # Convert "prop5000" to "id_5000"
11 return "id_" + id[4:]
13 # Ignore ids that don't start with "prop"
14 return ""
16 # Regex to match @[Display Text](id)
17 pattern = r"@\[[^\]]+\]\(([^)]+)\)"
18 transformed_expression = re.sub(pattern, replacer, expression)
20 # Clean up any extra spaces or operators left behind
21 return transformed_expression
23def get_expression_dependencies(expression: str | None) -> set[int]:
24 if expression is None: 24 ↛ 25line 24 didn't jump to line 25 because the condition on line 24 was never true
25 raise ValueError("Unexpected null expression")
27 dependencies = set()
29 def replacer(match):
30 id = match.group(1) # Get the id from the match
31 if id.startswith("prop"):
32 # Extract the numeric part of the id and add to dependencies
33 dependencies.add(int(id[4:]))
35 # Ignore ids that don't start with "prop"
36 return ""
38 # Regex to match @[Display Text](id)
39 pattern = r"@\[[^\]]+\]\(([^)]+)\)"
40 re.sub(pattern, replacer, expression)
42 return dependencies