@@ -29,7 +29,25 @@ def test_constructor(self):
29
29
self .assertEqual (status .description , "unavailable" )
30
30
31
31
def test_invalid_description (self ):
32
- with self .assertLogs (level = WARNING ):
32
+ with self .assertLogs (level = WARNING ) as warning :
33
33
status = Status (description = {"test" : "val" }) # type: ignore
34
34
self .assertIs (status .status_code , StatusCode .UNSET )
35
35
self .assertEqual (status .description , None )
36
+ self .assertIn ("Invalid status description type, expected str" , warning .output [0 ])
37
+
38
+ def test_description_and_non_error_status (self ):
39
+ with self .assertLogs (level = WARNING ) as warning :
40
+ status = Status (status_code = StatusCode .OK , description = "status description" )
41
+ self .assertIs (status .status_code , StatusCode .OK )
42
+ self .assertEqual (status .description , None )
43
+ self .assertIn ("description should only be set when status_code is set to StatusCode.ERROR" , warning .output [0 ])
44
+
45
+ with self .assertLogs (level = WARNING ) as warning :
46
+ status = Status (status_code = StatusCode .UNSET , description = "status description" )
47
+ self .assertIs (status .status_code , StatusCode .UNSET )
48
+ self .assertEqual (status .description , None )
49
+ self .assertIn ("description should only be set when status_code is set to StatusCode.ERROR" , warning .output [0 ])
50
+
51
+ status = Status (status_code = StatusCode .ERROR , description = "status description" )
52
+ self .assertIs (status .status_code , StatusCode .ERROR )
53
+ self .assertEqual (status .description , "status description" )
0 commit comments