Skip to content

Commit f4fb319

Browse files
author
Dylan Huang
committed
fix tests + add more
1 parent b322bda commit f4fb319

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

eval_protocol/models.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ def rollout_finished(
143143
details.append(ErrorInfo.termination_reason(termination_reason).to_aip193_format())
144144
if extra_info:
145145
details.append(ErrorInfo.extra_info(extra_info).to_aip193_format())
146-
return cls(code=cls.Code.FINISHED, message="Rollout finished", details=details)
146+
return cls.finished("Rollout finished", details)
147+
148+
@classmethod
149+
def finished(cls, message: str, details: Optional[List[Dict[str, Any]]] = None) -> "Status":
150+
"""Create a status indicating the rollout finished."""
151+
return cls(code=cls.Code.FINISHED, message=message, details=details or [])
147152

148153
@classmethod
149154
def rollout_error(cls, error_message: str, extra_info: Optional[Dict[str, Any]] = None) -> "Status":
@@ -156,7 +161,7 @@ def rollout_error(cls, error_message: str, extra_info: Optional[Dict[str, Any]]
156161
@classmethod
157162
def error(cls, error_message: str, details: Optional[List[Dict[str, Any]]] = None) -> "Status":
158163
"""Create a status indicating the rollout failed with an error."""
159-
return cls(code=cls.Code.INTERNAL, message=error_message, details=details)
164+
return cls(code=cls.Code.INTERNAL, message=error_message, details=details or [])
160165

161166
def is_running(self) -> bool:
162167
"""Check if the status indicates the rollout is running."""

tests/test_logs_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def test_should_update_status_not_running(self):
265265
eval_metadata=EvalMetadata(
266266
name="test_eval", num_runs=1, aggregation_method="mean", status=Status.rollout_finished()
267267
),
268+
rollout_status=RolloutStatus.rollout_finished(),
268269
pid=12345,
269270
)
270271

tests/test_status_model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ def test_large_metadata(self):
345345
assert len(status.details) == 1
346346
assert status.details[0]["metadata"] == large_metadata
347347

348+
def test_empty_details_error(self):
349+
"""Test Status with empty details and error message."""
350+
status = Status.error("Test error")
351+
assert status.is_error()
352+
353+
def test_empty_details_error_finished(self):
354+
"""Test Status with empty details and error message."""
355+
status = Status.finished("Test error")
356+
assert status.is_finished()
357+
348358

349359
if __name__ == "__main__":
350360
pytest.main([__file__])

0 commit comments

Comments
 (0)