@@ -29,7 +29,40 @@ 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 (
37
+ "Invalid status description type, expected str" ,
38
+ warning .output [0 ],
39
+ )
40
+
41
+ def test_description_and_non_error_status (self ):
42
+ with self .assertLogs (level = WARNING ) as warning :
43
+ status = Status (
44
+ status_code = StatusCode .OK , description = "status description"
45
+ )
46
+ self .assertIs (status .status_code , StatusCode .OK )
47
+ self .assertEqual (status .description , None )
48
+ self .assertIn (
49
+ "description should only be set when status_code is set to StatusCode.ERROR" ,
50
+ warning .output [0 ],
51
+ )
52
+
53
+ with self .assertLogs (level = WARNING ) as warning :
54
+ status = Status (
55
+ status_code = StatusCode .UNSET , description = "status description"
56
+ )
57
+ self .assertIs (status .status_code , StatusCode .UNSET )
58
+ self .assertEqual (status .description , None )
59
+ self .assertIn (
60
+ "description should only be set when status_code is set to StatusCode.ERROR" ,
61
+ warning .output [0 ],
62
+ )
63
+
64
+ status = Status (
65
+ status_code = StatusCode .ERROR , description = "status description"
66
+ )
67
+ self .assertIs (status .status_code , StatusCode .ERROR )
68
+ self .assertEqual (status .description , "status description" )
0 commit comments