-
-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathtest_located_error.py
More file actions
71 lines (51 loc) · 2.08 KB
/
Copy pathtest_located_error.py
File metadata and controls
71 lines (51 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from typing import Any, cast
from graphql.error import GraphQLError, located_error
from graphql.language import Source
def describe_located_error():
def throws_without_an_original_error():
e = located_error([], [], []).original_error # type: ignore
assert isinstance(e, TypeError)
assert str(e) == "Unexpected error value: []"
def passes_graphql_error_through():
path = ["path", 3, "to", "field"]
e = GraphQLError("msg", None, None, None, cast("Any", path))
assert located_error(e, [], []) == e
def passes_graphql_error_ish_through():
e = GraphQLError("I am a located GraphQL error")
e.path = []
assert located_error(e, [], []) is e
def does_not_pass_through_elasticsearch_like_errors():
e = Exception("I am from elasticsearch")
cast("Any", e).path = "/something/feed/_search"
assert located_error(e, [], []) is not e
def handles_lazy_error_messages():
class LazyString:
def __str__(self) -> str:
return "lazy"
class LazyError(Exception):
def __init__(self):
self.message = LazyString()
super().__init__()
assert str(located_error(LazyError())) == "lazy"
def handles_error_with_proper_source():
class CustomError(Exception):
source = Source("foo")
e = located_error(CustomError())
assert e.source
assert isinstance(e.source, Source)
assert e.source.body == "foo"
def handles_error_with_str_source():
class CustomError(Exception):
source = "foo"
e = located_error(CustomError())
assert e.source
assert isinstance(e.source, Source)
assert e.source.body == "foo"
def handles_error_with_non_source():
class CustomError(Exception):
source = Exception("Not a source")
e = located_error(CustomError())
assert e.source is None
def handles_error_without_source():
e = located_error(ValueError("No source"))
assert e.source is None