11from unittest .mock import MagicMock
22
3- from behave import then , given
3+ from behave import given , then
44
55from openfeature .exception import ErrorCode
66from openfeature .flag_evaluation import Reason
@@ -31,11 +31,8 @@ def step_impl_should_have_eval_details(context, hook_names):
3131 for row in context .table :
3232 flag_type , key , value = row
3333
34- value = convert_value_from_flag_type (value , flag_type )
35-
34+ value = convert_value_from_key_and_flag_type (value , key , flag_type )
3635 actual = hook .call_args [1 ]["details" ].__dict__ [key ]
37- if isinstance (actual , ErrorCode ) or isinstance (actual , Reason ):
38- actual = str (actual )
3936
4037 print ("expected" , value , "actual" , actual )
4138 print ("expected type" , type (value ), "actual type" , type (actual ))
@@ -55,13 +52,17 @@ def get_hook_from_name(context, hook_name):
5552 raise ValueError (str (hook_name ) + " is not a valid hook name" )
5653
5754
58- def convert_value_from_flag_type (value , flag_type ):
59- if value == "None" or value == "null" :
55+ def convert_value_from_key_and_flag_type (value , key , flag_type ):
56+ if value in ( "None" , "null" ) :
6057 return None
6158 if flag_type .lower () == "boolean" :
6259 return bool (value )
6360 elif flag_type .lower () == "integer" :
6461 return int (value )
6562 elif flag_type .lower () == "float" :
6663 return float (value )
64+ elif key == "reason" :
65+ return Reason (value )
66+ elif key == "error_code" :
67+ return ErrorCode (value )
6768 return value
0 commit comments