File: test_located_error.py

package info (click to toggle)
graphql-core 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,384 kB
  • sloc: python: 45,812; makefile: 26; sh: 13
file content (37 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download
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
from typing import cast, Any

from graphql.error import GraphQLError, located_error


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"