This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bot.py
More file actions
59 lines (57 loc) · 1.81 KB
/
test_bot.py
File metadata and controls
59 lines (57 loc) · 1.81 KB
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
from cogs.get import Get
import pytest
import asyncio
class MockView:
def __init__(self, args):
self.index = 1
self.args = args
def skip_ws(self):
pass
def eof(self):
if self.ind > len(self.args):
print("eof")
return True
return False
class MockBot:
def __init__(self, args, kwargs):
self.args = args
self.kwargs = kwargs
self.can_run = self.return_true
self.command = None
self.bot = self
self.view = MockView(self.args)
self.init = True
self.ind = 0
self.author = self
self.name = "Discord.py Mockup User"
self.discriminator = "0000"
self.id = 0
def __setattr__(self, name: str, value) -> None:
try:
if name == "args" or name == "kwargs" and self.init:
print(f"Potential Bug! {name} should not be changed! (current value: {getattr(self, name)})")
except:
pass
super().__setattr__(name, value)
async def return_true(self, *args, **kwargs):
return True
def sync_return_true(self, *args, **kwargs):
return True
async def send(self, *args, **kwargs):
print(f"Would send message with args: {args} and kwargs: {kwargs}")
class CogTestClient:
def __init__(self, cog):
self._cog = cog(MockBot(None, None))
def run_command(self, command, *args, **kwargs):
pass_args = list(args)
pass_args.insert(0, self._cog)
pass_args.insert(1, MockBot(args, kwargs))
print(pass_args)
asyncio.run(getattr(self._cog, command)(*pass_args, **kwargs))
@pytest.fixture
def client():
yield CogTestClient
def test_allmemes(client):
client(Get).run_command("allmemes")
def test_allpets(client):
client(Get).run_command("allpets")