Skip to content

Commit 2861443

Browse files
test: Enhance US05 required grade parsing with additional checks and error handling
1 parent 2bd4187 commit 2861443

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

tests/us5.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,31 @@ def _get_required_grade_or_message(self):
131131
return "Error: Empty Value"
132132

133133
# Check for specific messages first
134-
if "No es posible aprobar la materia" in raw_text:
135-
return "No es posible aprobar" # Standardized message
136-
if "Ya se ha aprobado la materia" in raw_text:
134+
# Check for "Ya se ha aprobado la materia" message
135+
if "Ya ha aprobado la materia" in raw_text or "Ya se ha aprobado la materia" in raw_text or "Ya tiene el 100% de la materia" in raw_text:
137136
return "Ya se ha aprobado la materia"
137+
138+
# Check for impossible to approve scenario
139+
# In result.jsx, if requiredGrade > maxValue (5), it would display an impossible value
140+
if "No es posible aprobar la materia" in raw_text or "Necesitas 11 en el" in raw_text or "Necesitas -1 en el" in raw_text:
141+
return "No es posible aprobar"
138142

139-
# Try to parse a grade
140-
# Example text: "Necesitas un 4.0 en el 50% restante para aprobar la materia con un 3.0"
141-
match = re.search(r"Necesitas un (\d+\.?\d*|\.\d+) en el", raw_text)
143+
# Try to extract the required grade
144+
match = re.search(r"Necesitas (\d+\.?\d*|\.\d+|-\d+\.?\d*) en el", raw_text)
142145
if match:
143146
grade_str = match.group(1)
144147
logger.info(f"Extracted required grade string: '{grade_str}'")
145-
return float(grade_str)
148+
try:
149+
# Convert to float and check if it's a reasonable value
150+
grade_value = float(grade_str)
151+
if grade_value > 10 or grade_value < 0:
152+
logger.info(f"Found extreme grade value: {grade_value}, interpreting as 'No es posible aprobar'")
153+
return "No es posible aprobar"
154+
return grade_value
155+
except ValueError:
156+
logger.error(f"Could not convert grade string to float: '{grade_str}'")
157+
self._take_screenshot("grade_conversion_error")
158+
return "Error: Conversion"
146159
else:
147160
logger.error(f"Could not parse required grade from text: '{raw_text}'")
148161
self._take_screenshot("required_grade_parse_error")

0 commit comments

Comments
 (0)