/ tests / utils / test_exception.py
test_exception.py
 1  import json
 2  
 3  from mlflow.exceptions import ExecutionException, RestException
 4  from mlflow.protos.databricks_pb2 import RESOURCE_DOES_NOT_EXIST, ErrorCode
 5  
 6  
 7  def test_execution_exception_string_repr():
 8      exc = ExecutionException("Uh oh")
 9      assert str(exc) == "Uh oh"
10      json.loads(exc.serialize_as_json())
11  
12  
13  def test_rest_exception_default_error_code():
14      exc = RestException({"message": "something important."})
15      assert "something important." in str(exc)
16  
17  
18  def test_rest_exception_error_code_is_not_none():
19      error_string = "something important."
20      exc = RestException({"message": error_string})
21      assert "None" not in error_string
22      assert "None" not in str(exc)
23      json.loads(exc.serialize_as_json())
24  
25  
26  def test_rest_exception_without_message():
27      exc = RestException({"my_property": "something important."})
28      assert "something important." in str(exc)
29      json.loads(exc.serialize_as_json())
30  
31  
32  def test_rest_exception_error_code_and_no_message():
33      exc = RestException({
34          "error_code": ErrorCode.Name(RESOURCE_DOES_NOT_EXIST),
35          "messages": "something important.",
36      })
37      assert "something important." in str(exc)
38      assert "RESOURCE_DOES_NOT_EXIST" in str(exc)
39      json.loads(exc.serialize_as_json())