-
Notifications
You must be signed in to change notification settings - Fork 2
/
conftest.py
207 lines (159 loc) · 5.55 KB
/
conftest.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import pytest
import aiohttp
from trellis_dag.node import Node
from trellis_dag import DAG
class DummyNode(Node):
def __init__(self, name: str) -> None:
super().__init__(name)
async def execute(self) -> dict[str : type]:
pass
class ReadFromFileTool(Node):
def __init__(
self,
name: str,
input_s: dict[str, type] = dict,
output_s: dict[str, type] = {"file_contents": str},
file_path: str = "data.txt",
*args,
**kwargs,
) -> None:
super().__init__(name, input_s, output_s, *args, **kwargs)
self.file_path = file_path
async def execute(self) -> dict:
with open(
self.execute_args["kwargs"].get("file_path", "tests/data.txt"), "r"
) as f:
self.output = {"file_contents": f.read()}
return self.output
class CatFactsAPITool(Node):
def __init__(
self,
name: str,
input_s: dict[str, type] = dict,
output_s: dict[str, type] = {"cat_information": list[dict[str, str]]},
limit: int = 1,
max_length: int = 140,
*args,
**kwargs,
) -> None:
super().__init__(name, input_s, output_s, *args, **kwargs)
self.limit = limit
self.max_length = max_length
def set_limit(self, limit: int) -> None:
self.limit = limit
def set_max_length(self, max_length: int) -> None:
self.max_length = max_length
async def execute(self) -> dict:
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://catfact.ninja/facts?limit={self.execute_args['kwargs'].get('limit', 1)}&max_length={self.execute_args['kwargs'].get('max_length', 140)}"
) as response:
if response.status == 200:
data = await response.json()
self.output = {"cat_information": data["data"]}
return self.output
else:
return {"error": "Unable to fetch cat fact."}
class UselessFactsAPITool(Node):
def __init__(
self,
name: str,
input_s: dict[str, type] = dict,
output_s: dict[str, type] = {"useless_information": str},
*args,
**kwargs,
) -> None:
super().__init__(name, input_s, output_s, *args, **kwargs)
async def execute(self) -> dict:
async with aiohttp.ClientSession() as session:
async with session.get(
"https://uselessfacts.jsph.pl/random.json"
) as response:
if response.status == 200:
data = await response.json()
self.output = {"useless_information": data["text"]}
return self.output
else:
return {"error": "Unable to fetch useless fact."}
class CorporateBSGeneratorAPITool(Node):
def __init__(
self,
name: str,
input_s: dict[str, type] = dict,
output_s: dict[str, type] = {"corporate_bs": str},
*args,
**kwargs,
) -> None:
super().__init__(name, input_s, output_s, *args, **kwargs)
async def execute(self) -> dict:
async with aiohttp.ClientSession() as session:
async with session.get(
"https://corporatebs-generator.sameerkumar.website/"
) as response:
if response.status == 200:
data = await response.json()
self.output = {"corporate_bs": data["phrase"]}
return self.output
else:
return {"error": "Unable to fetch corporate bs."}
class ImgFlipMemeNameAPITool(Node):
def __init__(
self,
name: str,
input_s: dict[str, type] = dict,
output_s: dict[str, type] = {"meme_name": str},
*args,
**kwargs,
) -> None:
super().__init__(name, input_s, output_s, *args, **kwargs)
async def execute(self) -> dict:
async with aiohttp.ClientSession() as session:
async with session.get("https://api.imgflip.com/get_memes") as response:
if response.status == 200:
data = await response.json()
self.output = {"meme_name": data["data"]["memes"][0]["name"]}
return self.output
else:
return {"error": "Unable to fetch meme name."}
@pytest.fixture
def dag() -> DAG:
return DAG()
@pytest.fixture
def cat_facts_api_tool() -> Node:
return CatFactsAPITool("cat_facts_api_tool")
@pytest.fixture
def useless_facts_api_tool() -> Node:
return UselessFactsAPITool("useless_facts_api_tool")
@pytest.fixture
def corporate_bs_generator_api_tool() -> Node:
return CorporateBSGeneratorAPITool("corporate_bs_generator_api_tool")
@pytest.fixture
def img_flip_meme_name_api_tool() -> Node:
return ImgFlipMemeNameAPITool("img_flip_meme_name_api_tool")
@pytest.fixture
def read_from_file_tool() -> Node:
return ReadFromFileTool("read_from_file_tool")
@pytest.fixture
def dummy_node() -> DummyNode:
return DummyNode("test")
@pytest.fixture()
def dummy_node_2():
return DummyNode("test2")
@pytest.fixture()
def dummy_node_3():
return DummyNode("test3")
@pytest.fixture
def dummy_node_4():
return DummyNode("test4")
@pytest.fixture
def dummy_node_5():
return DummyNode("test5")
@pytest.fixture
def dummy_node_6():
return DummyNode("test6")
@pytest.fixture
def dummy_node_7():
return DummyNode("test7")
@pytest.fixture
def dummy_node_8():
return DummyNode("test8")