Debian Codegraph @

tests/error/test_located_error.py

raw
1 from typing import cast, Any
2
3 from graphql.error import GraphQLError, located_error
4
5
6 def describe_located_error():
7 def throws_without_an_original_error():
8 e = located_error([], [], []).original_error # type: ignore
9 assert isinstance(e, TypeError)
10 assert str(e) == "Unexpected error value: []"
11
12 def passes_graphql_error_through():
13 path = ["path", 3, "to", "field"]
14 e = GraphQLError("msg", None, None, None, cast(Any, path))
15 assert located_error(e, [], []) == e
16
17 def passes_graphql_error_ish_through():
18 e = GraphQLError("I am a located GraphQL error")
19 e.path = []
20 assert located_error(e, [], []) is e
21
22 def does_not_pass_through_elasticsearch_like_errors():
23 e = Exception("I am from elasticsearch")
24 cast(Any, e).path = "/something/feed/_search"
25 assert located_error(e, [], []) is not e
26
27 def handles_lazy_error_messages():
28 class LazyString:
29 def __str__(self) -> str:
30 return "lazy"
31
32 class LazyError(Exception):
33 def __init__(self):
34 self.message = LazyString()
35 super().__init__()
36
37 assert str(located_error(LazyError())) == "lazy"