-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_will_it_blend.py
172 lines (127 loc) · 4.42 KB
/
test_will_it_blend.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
import asyncio
import logging
# import os
import sys
import discord
from discord.ext import tasks
from dotenv import load_dotenv
import functions
from index import Friday
from launcher import setup_logging
# from create_trans_key import run
load_dotenv(dotenv_path="./.env")
# TOKEN = os.environ.get('TOKENTEST')
class Friday_testing(Friday):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# self.test_stop.start()
# self.test_message.start()
# async def setup(self, load_extentions=False):
# for cog in cogs.default:
# await self.load_extension(f"cogs.{cog}")
# return await super().setup(load_extentions=load_extentions)
async def channel(self) -> discord.TextChannel:
return self.get_channel(892840236781015120) if self.get_channel(892840236781015120) is None else await self.fetch_channel(892840236781015120) # type: ignore
async def on_ready(self):
await (await self.channel()).send("?ready")
try:
def online_check(m) -> bool:
return m.author.id == 892865928520413245 and m.channel.id == 892840236781015120
await self.wait_for("message", check=online_check, timeout=3.0)
except asyncio.TimeoutError:
return await self.close()
def pass_check(m) -> bool:
return m.author.id == 892865928520413245 and (m.content in ("!passed", "!failed", "!complete"))
await self.wait_for("message", check=pass_check, timeout=120.0)
await self.close()
@tasks.loop()
async def test_message(self):
print("passed")
@tasks.loop(seconds=1, count=1)
async def test_stop(self):
await self.wait_until_ready()
while not self.ready:
await asyncio.sleep(0.1)
assert await super().close()
# TODO: Add a check for functions modules/files not being named the same as the functions/defs
# def test_translate_key_gen():
# run()
formatter = logging.Formatter("%(levelname)s:%(name)s: %(message)s")
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
logger = logging.getLogger("Friday")
logger.handlers = [handler]
logger.setLevel(logging.INFO)
def test_will_it_blend():
bot = Friday_testing()
async def main(bot):
try:
pool = await functions.db.create_pool()
except Exception:
print('Could not set up PostgreSQL. Exiting.')
return
with setup_logging():
async with bot:
bot.pool = pool
await bot.start()
asyncio.run(main(bot))
# import asyncio
# import os
# import pytest
# import discord
# # from discord.ext import tasks, commands
# from dotenv import load_dotenv
# from index import Friday
# import cogs
# # from create_trans_key import run
# load_dotenv(dotenv_path="./.env")
# TOKEN = os.environ.get('TOKENTEST')
# class Friday_testing(Friday):
# def __init__(self, loop=None, *args, **kwargs):
# self.loop = loop
# super().__init__(loop=self.loop, *args, **kwargs)
# # self.test_stop.start()
# # self.test_message.start()
# async def setup(self, load_extentions=False):
# for cog in cogs.default:
# self.load_extension(f"cogs.{cog}")
# return await super().setup(load_extentions=load_extentions)
# # @tasks.loop()
# # async def test_message(self):
# # print("passed")
# # @tasks.loop(seconds=1, count=1)
# # async def test_stop(self):
# # await self.wait_until_ready()
# # while not self.ready:
# # await asyncio.sleep(0.1)
# # assert await super().close()
# # TODO: Add a check for functions modules/files not being named the same as the functions/defs
# # def test_translate_key_gen():
# # run()
# @pytest.fixture(scope="session")
# def event_loop():
# return asyncio.get_event_loop()
# @pytest.fixture(scope="session", autouse=True)
# async def bot(event_loop) -> Friday_testing:
# bot = Friday_testing(loop=event_loop)
# event_loop.create_task(bot.start(TOKEN))
# await bot.wait_until_ready()
# return bot
# @pytest.fixture(scope="session", autouse=True)
# def cleanup(request, bot):
# def close():
# asyncio.get_event_loop().run_until_complete(bot.close())
# request.addfinalizer(close)
# @pytest.mark.asyncio
# async def test_will_it_blend(bot):
# assert bot.status == discord.Status.online
# # bot = Friday_testing()
# # loop = asyncio.get_event_loop()
# # try:
# # loop.run_until_complete(bot.start(TOKEN))
# # except KeyboardInterrupt:
# # # mydb.close()
# # logging.info("STOPED")
# # loop.run_until_complete(bot.close())
# # finally:
# # loop.close()