Skip to content

Commit 9c768b2

Browse files
committed
Test exception type in test_serialization
1 parent 35cf7d2 commit 9c768b2

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

tests/type/test_serialization.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,41 @@ def serializes_output_as_int():
3737
assert str(exc_info.value) == "Int cannot represent non-integer value: '-1.1'"
3838
# Maybe a safe JavaScript int, but bigger than 2^32, so not
3939
# representable as a GraphQL Int
40-
with raises(Exception) as exc_info:
40+
with raises(TypeError) as exc_info:
4141
GraphQLInt.serialize(9876504321)
4242
assert str(exc_info.value) == (
4343
"Int cannot represent non 32-bit signed integer value: 9876504321"
4444
)
45-
with raises(Exception) as exc_info:
45+
with raises(TypeError) as exc_info:
4646
GraphQLInt.serialize(-9876504321)
4747
assert str(exc_info.value) == (
4848
"Int cannot represent non 32-bit signed integer value: -9876504321"
4949
)
5050
# Too big to represent as an Int in JavaScript or GraphQL
51-
with raises(Exception) as exc_info:
51+
with raises(TypeError) as exc_info:
5252
GraphQLInt.serialize(1e100)
5353
assert str(exc_info.value) == (
5454
"Int cannot represent non 32-bit signed integer value: 1e+100"
5555
)
56-
with raises(Exception) as exc_info:
56+
with raises(TypeError) as exc_info:
5757
GraphQLInt.serialize(-1e100)
5858
assert str(exc_info.value) == (
5959
"Int cannot represent non 32-bit signed integer value: -1e+100"
6060
)
61-
with raises(Exception) as exc_info:
61+
with raises(TypeError) as exc_info:
6262
GraphQLInt.serialize("one")
6363
assert str(exc_info.value) == "Int cannot represent non-integer value: 'one'"
6464
# Doesn't represent number
65-
with raises(Exception) as exc_info:
65+
with raises(TypeError) as exc_info:
6666
GraphQLInt.serialize("")
6767
assert str(exc_info.value) == "Int cannot represent non-integer value: ''"
68-
with raises(Exception) as exc_info:
68+
with raises(TypeError) as exc_info:
6969
GraphQLInt.serialize(nan)
7070
assert str(exc_info.value) == "Int cannot represent non-integer value: nan"
71-
with raises(Exception) as exc_info:
71+
with raises(TypeError) as exc_info:
7272
GraphQLInt.serialize(inf)
7373
assert str(exc_info.value) == "Int cannot represent non-integer value: inf"
74-
with raises(Exception) as exc_info:
74+
with raises(TypeError) as exc_info:
7575
GraphQLInt.serialize([5])
7676
assert str(exc_info.value) == "Int cannot represent non-integer value: [5]"
7777

@@ -87,21 +87,21 @@ def serializes_output_as_float():
8787
assert GraphQLFloat.serialize(False) == 0
8888
assert GraphQLFloat.serialize(True) == 1
8989

90-
with raises(Exception) as exc_info:
90+
with raises(TypeError) as exc_info:
9191
GraphQLFloat.serialize(nan)
9292
assert str(exc_info.value) == "Float cannot represent non numeric value: nan"
93-
with raises(Exception) as exc_info:
93+
with raises(TypeError) as exc_info:
9494
GraphQLFloat.serialize(inf)
9595
assert str(exc_info.value) == "Float cannot represent non numeric value: inf"
96-
with raises(Exception) as exc_info:
96+
with raises(TypeError) as exc_info:
9797
GraphQLFloat.serialize("one")
9898
assert str(exc_info.value) == (
9999
"Float cannot represent non numeric value: 'one'"
100100
)
101-
with raises(Exception) as exc_info:
101+
with raises(TypeError) as exc_info:
102102
GraphQLFloat.serialize("")
103103
assert str(exc_info.value) == "Float cannot represent non numeric value: ''"
104-
with raises(Exception) as exc_info:
104+
with raises(TypeError) as exc_info:
105105
GraphQLFloat.serialize([5])
106106
assert str(exc_info.value) == "Float cannot represent non numeric value: [5]"
107107

@@ -118,15 +118,15 @@ def __str__(self):
118118

119119
assert GraphQLString.serialize(StringableObjValue()) == "something useful"
120120

121-
with raises(Exception) as exc_info:
121+
with raises(TypeError) as exc_info:
122122
GraphQLString.serialize(nan)
123123
assert str(exc_info.value) == "String cannot represent value: nan"
124124

125-
with raises(Exception) as exc_info:
125+
with raises(TypeError) as exc_info:
126126
GraphQLString.serialize([1])
127127
assert str(exc_info.value) == "String cannot represent value: [1]"
128128

129-
with raises(Exception) as exc_info:
129+
with raises(TypeError) as exc_info:
130130
GraphQLString.serialize({})
131131
assert str(exc_info.value) == "String cannot represent value: {}"
132132

@@ -136,31 +136,31 @@ def serializes_output_as_boolean():
136136
assert GraphQLBoolean.serialize(True) is True
137137
assert GraphQLBoolean.serialize(False) is False
138138

139-
with raises(Exception) as exc_info:
139+
with raises(TypeError) as exc_info:
140140
GraphQLBoolean.serialize(nan)
141141
assert str(exc_info.value) == (
142142
"Boolean cannot represent a non boolean value: nan"
143143
)
144144

145-
with raises(Exception) as exc_info:
145+
with raises(TypeError) as exc_info:
146146
GraphQLBoolean.serialize("")
147147
assert str(exc_info.value) == (
148148
"Boolean cannot represent a non boolean value: ''"
149149
)
150150

151-
with raises(Exception) as exc_info:
151+
with raises(TypeError) as exc_info:
152152
GraphQLBoolean.serialize("True")
153153
assert str(exc_info.value) == (
154154
"Boolean cannot represent a non boolean value: 'True'"
155155
)
156156

157-
with raises(Exception) as exc_info:
157+
with raises(TypeError) as exc_info:
158158
GraphQLBoolean.serialize([False])
159159
assert str(exc_info.value) == (
160160
"Boolean cannot represent a non boolean value: [False]"
161161
)
162162

163-
with raises(Exception) as exc_info:
163+
with raises(TypeError) as exc_info:
164164
GraphQLBoolean.serialize({})
165165
assert str(exc_info.value) == (
166166
"Boolean cannot represent a non boolean value: {}"
@@ -184,18 +184,18 @@ def __str__(self):
184184
obj_value = ObjValue(123)
185185
assert GraphQLID.serialize(obj_value) == "123"
186186

187-
with raises(Exception) as exc_info:
187+
with raises(TypeError) as exc_info:
188188
GraphQLID.serialize(True)
189189
assert str(exc_info.value) == "ID cannot represent value: True"
190190

191-
with raises(Exception) as exc_info:
191+
with raises(TypeError) as exc_info:
192192
GraphQLID.serialize(3.14)
193193
assert str(exc_info.value) == ("ID cannot represent value: 3.14")
194194

195-
with raises(Exception) as exc_info:
195+
with raises(TypeError) as exc_info:
196196
GraphQLID.serialize({})
197197
assert str(exc_info.value) == ("ID cannot represent value: {}")
198198

199-
with raises(Exception) as exc_info:
199+
with raises(TypeError) as exc_info:
200200
GraphQLID.serialize(["abc"])
201201
assert str(exc_info.value) == ("ID cannot represent value: ['abc']")

0 commit comments

Comments
 (0)