@@ -36,10 +36,13 @@ def is_a_class_and_is_a_subclass_of_exception():
3636 assert isinstance (GraphQLError ("str" ), Exception )
3737 assert isinstance (GraphQLError ("str" ), GraphQLError )
3838
39- def has_a_name_message_and_stack_trace ():
39+ def has_a_name_message_extensions_and_stack_trace ():
4040 e = GraphQLError ("msg" )
4141 assert e .__class__ .__name__ == "GraphQLError"
4242 assert e .message == "msg"
43+ assert e .extensions == {}
44+ assert e .__traceback__ is None
45+ assert str (e ) == "msg"
4346
4447 def uses_the_stack_of_an_original_error ():
4548 try :
@@ -126,18 +129,27 @@ def converts_source_and_positions_to_locations():
126129 assert e .positions == [6 ]
127130 assert e .locations == [(2 , 5 )]
128131
129- def serializes_to_include_message ():
130- e = GraphQLError ("msg" )
131- assert str (e ) == "msg"
132- assert repr (e ) == "GraphQLError('msg')"
133-
134- def serializes_to_include_message_and_locations ():
135- e = GraphQLError ("msg" , field_node )
136- assert "msg" in str (e )
137- assert ":2:3" in str (e )
138- assert repr (e ) == (
139- "GraphQLError('msg', locations=[SourceLocation(line=2, column=3)])"
132+ def serializes_to_include_all_standard_fields ():
133+ e_short = GraphQLError ("msg" )
134+ assert str (e_short ) == "msg"
135+ assert repr (e_short ) == "GraphQLError('msg')"
136+
137+ path : List [Union [str , int ]] = ["path" , 2 , "field" ]
138+ extensions = {"foo" : "bar " }
139+ e_full = GraphQLError ("msg" , field_node , None , None , path , None , extensions )
140+ assert str (e_full ) == (
141+ "msg\n \n GraphQL request:2:3\n " "1 | {\n 2 | field\n | ^\n 3 | }"
142+ )
143+ assert repr (e_full ) == (
144+ "GraphQLError('msg', locations=[SourceLocation(line=2, column=3)],"
145+ " path=['path', 2, 'field'], extensions={'foo': 'bar '})"
140146 )
147+ assert e_full .formatted == {
148+ "message" : "msg" ,
149+ "locations" : [{"line" : 2 , "column" : 3 }],
150+ "path" : ["path" , 2 , "field" ],
151+ "extensions" : {"foo" : "bar " },
152+ }
141153
142154 def repr_includes_extensions ():
143155 e = GraphQLError ("msg" , extensions = {"foo" : "bar" })
0 commit comments