File: test_deferred_annotations.py

package info (click to toggle)
strawberry-graphql 0.306.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,176 kB
  • sloc: javascript: 178,052; python: 65,643; sh: 33; makefile: 25
file content (37 lines) | stat: -rw-r--r-- 736 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 sys import modules
from types import ModuleType

import strawberry

deferred_module_source = """
from __future__ import annotations

import strawberry

@strawberry.type
class User:
    username: str
    email: str

@strawberry.interface
class UserContent:
    created_by: User
"""


def test_deferred_other_module():
    mod = ModuleType("tests.deferred_module")
    modules[mod.__name__] = mod

    try:
        exec(deferred_module_source, mod.__dict__)  # noqa: S102

        @strawberry.type
        class Post(mod.UserContent):
            title: str
            body: str

        definition = Post.__strawberry_definition__
        assert definition.fields[0].type == mod.User
    finally:
        del modules[mod.__name__]