• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MrThearMan / undine / 16081423623

04 Jul 2025 09:57PM UTC coverage: 97.685%. First build
16081423623

Pull #33

github

web-flow
Merge 6eb57167c into 784a68391
Pull Request #33: Add Subscriptions

1798 of 1841 branches covered (97.66%)

Branch coverage included in aggregate %.

1009 of 1176 new or added lines in 36 files covered. (85.8%)

26853 of 27489 relevant lines covered (97.69%)

8.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.43
/tests/test_converters/test_convert_to_entrypoint_subscription.py
1
from __future__ import annotations
9✔
2

3
from typing import AsyncGenerator, AsyncIterable, AsyncIterator, Generator, Self
9✔
4

5
from example_project.app.models import Project, Task
9✔
6
from undine import Entrypoint, InterfaceType, MutationType, QueryType, RootType, UnionType
9✔
7
from undine.converters import convert_to_entrypoint_subscription
9✔
8
from undine.relay import Connection, Node
9✔
9
from undine.resolvers import FunctionSubscriptionResolver
9✔
10

11

12
def test_convert_to_entrypoint_subscription__async_generator() -> None:
9✔
13
    async def func() -> AsyncGenerator[int, None]:  # noqa: RUF029
9✔
NEW
14
        for i in range(2):
×
NEW
15
            yield i
×
16

17
    class Subscription(RootType):
9✔
18
        fn = Entrypoint(func)
9✔
19

20
    resolver = FunctionSubscriptionResolver(func=func, entrypoint=Subscription.fn)
9✔
21

22
    assert convert_to_entrypoint_subscription(func, caller=Subscription.fn) == resolver
9✔
23

24

25
def test_convert_to_entrypoint_subscription__coroutine_returning_async_iterator() -> None:
9✔
26
    class ExampleIterator:
9✔
27
        def __init__(self) -> None:
9✔
NEW
28
            self.values = list(range(2))
×
NEW
29
            self.index = 0
×
30

31
        def __aiter__(self) -> Self:
9✔
NEW
32
            return self
×
33

34
        async def __anext__(self) -> int:
9✔
NEW
35
            if self.index >= len(self.values):
×
NEW
36
                raise StopAsyncIteration
×
NEW
37
            value = self.values[self.index]
×
NEW
38
            self.index += 1
×
NEW
39
            return value
×
40

41
    async def func() -> AsyncIterator[int]:  # noqa: RUF029
9✔
NEW
42
        return ExampleIterator()
×
43

44
    class Subscription(RootType):
9✔
45
        fn = Entrypoint(func)
9✔
46

47
    resolver = FunctionSubscriptionResolver(func=func, entrypoint=Subscription.fn)
9✔
48

49
    assert convert_to_entrypoint_subscription(func, caller=Subscription.fn) == resolver
9✔
50

51

52
def test_convert_to_entrypoint_subscription__coroutine_returning_async_iterable() -> None:
9✔
53
    class ExampleIterable:
9✔
54
        def __aiter__(self) -> AsyncIterator[int]:
9✔
NEW
55
            return self.gen()
×
56

57
        async def gen(self) -> AsyncGenerator[int, None]:
9✔
NEW
58
            for i in range(2):
×
NEW
59
                yield i
×
60

61
    async def func() -> AsyncIterable[int]:  # noqa: RUF029
9✔
NEW
62
        return ExampleIterable()
×
63

64
    class Subscription(RootType):
9✔
65
        fn = Entrypoint(func)
9✔
66

67
    resolver = FunctionSubscriptionResolver(func=func, entrypoint=Subscription.fn)
9✔
68

69
    assert convert_to_entrypoint_subscription(func, caller=Subscription.fn) == resolver
9✔
70

71

72
def test_convert_to_entrypoint_subscription__regular_function() -> None:
9✔
73
    def func() -> int:
9✔
NEW
74
        return 1
×
75

76
    class Subscription(RootType):
9✔
77
        fn = Entrypoint(func)
9✔
78

79
    assert convert_to_entrypoint_subscription(func, caller=Subscription.fn) is None
9✔
80

81

82
def test_convert_to_entrypoint_subscription__generator_function() -> None:
9✔
83
    def func() -> Generator[int, None, None]:
9✔
NEW
84
        for i in range(2):
×
NEW
85
            yield i
×
86

87
    class Subscription(RootType):
9✔
88
        fn = Entrypoint(func)
9✔
89

90
    assert convert_to_entrypoint_subscription(func, caller=Subscription.fn) is None
9✔
91

92

93
def test_convert_to_entrypoint_subscription__query_type() -> None:
9✔
94
    class TaskType(QueryType[Task]): ...
9✔
95

96
    class Subscription(RootType):
9✔
97
        tasks = Entrypoint(TaskType)
9✔
98

99
    assert convert_to_entrypoint_subscription(TaskType, caller=Subscription.tasks) is None
9✔
100

101

102
def test_convert_to_entrypoint_subscription__mutation_type() -> None:
9✔
103
    class CreateTaskMutation(MutationType[Task]): ...
9✔
104

105
    class Subscription(RootType):
9✔
106
        create_task = Entrypoint(CreateTaskMutation)
9✔
107

108
    assert convert_to_entrypoint_subscription(CreateTaskMutation, caller=Subscription.create_task) is None
9✔
109

110

111
def test_convert_to_entrypoint_subscription__union_type() -> None:
9✔
112
    class TaskType(QueryType[Task]): ...
9✔
113

114
    class ProjectType(QueryType[Project]): ...
9✔
115

116
    class Commentable(UnionType[TaskType, ProjectType]): ...
9✔
117

118
    class Subscription(RootType):
9✔
119
        commentable = Entrypoint(Commentable)
9✔
120

121
    assert convert_to_entrypoint_subscription(Commentable, caller=Subscription.commentable) is None
9✔
122

123

124
def test_convert_to_entrypoint_subscription__node() -> None:
9✔
125
    class Subscription(RootType):
9✔
126
        node = Entrypoint(Node)
9✔
127

128
    assert convert_to_entrypoint_subscription(Node, caller=Subscription.node) is None
9✔
129

130

131
def test_convert_to_entrypoint_subscription__interface_type() -> None:
9✔
132
    class MyInterface(InterfaceType): ...
9✔
133

134
    class Subscription(RootType):
9✔
135
        inter = Entrypoint(MyInterface)
9✔
136

137
    assert convert_to_entrypoint_subscription(MyInterface, caller=Subscription.inter) is None
9✔
138

139

140
def test_convert_to_entrypoint_subscription__connection() -> None:
9✔
141
    class TaskType(QueryType[Task]): ...
9✔
142

143
    class Subscription(RootType):
9✔
144
        tasks = Entrypoint(Connection(TaskType))
9✔
145

146
    assert convert_to_entrypoint_subscription(TaskType, caller=Subscription.tasks) is None
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc