diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-18 16:24:42 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-18 16:24:42 +0200 |
| commit | 857a7364ddb9b10529593c5e9c3578eb95c1da9b (patch) | |
| tree | cc160ed8685039fcb08663226395fb97d78fcea6 /tests/conftest.py | |
| parent | add support for x^2+y^2=0,4 and alike (diff) | |
| download | senator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.tar.gz senator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.zip | |
add a test suite
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'tests/conftest.py')
| -rw-r--r-- | tests/conftest.py | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..c471b6b --- /dev/null +++ b/tests/conftest.py | |||
| @@ -0,0 +1,198 @@ | |||
| 1 | import asyncio | ||
| 2 | from unittest.mock import AsyncMock, MagicMock | ||
| 3 | import pytest | ||
| 4 | |||
| 5 | import discord | ||
| 6 | from discord.ext import commands | ||
| 7 | |||
| 8 | |||
| 9 | class MockUser: | ||
| 10 | def __init__(self, id=12345, name="testuser", discriminator="0001"): | ||
| 11 | self.id = id | ||
| 12 | self.name = name | ||
| 13 | self.discriminator = discriminator | ||
| 14 | self.mention = f"@{name}" | ||
| 15 | self.display_name = name | ||
| 16 | self.avatar = None | ||
| 17 | self.bot = False | ||
| 18 | self.guild = None | ||
| 19 | self._state = MagicMock() | ||
| 20 | |||
| 21 | def __str__(self): | ||
| 22 | return f"{self.name}#{self.discriminator}" | ||
| 23 | |||
| 24 | |||
| 25 | class MockChannel: | ||
| 26 | def __init__(self, id=11111, name="test-channel", type=discord.ChannelType.text): | ||
| 27 | self.id = id | ||
| 28 | self.name = name | ||
| 29 | self.type = type | ||
| 30 | self.mention = f"#{name}" | ||
| 31 | self.guild = None | ||
| 32 | self.category = None | ||
| 33 | self._state = MagicMock() | ||
| 34 | |||
| 35 | async def send(self, *args, **kwargs): | ||
| 36 | return MagicMock() | ||
| 37 | |||
| 38 | |||
| 39 | class MockTextChannel(MockChannel): | ||
| 40 | def __init__(self, id=11111, name="test-channel"): | ||
| 41 | super().__init__(id, name, discord.ChannelType.text) | ||
| 42 | |||
| 43 | |||
| 44 | class MockVoiceChannel(MockChannel): | ||
| 45 | def __init__(self, id=11112, name="test-voice"): | ||
| 46 | super().__init__(id, name, discord.ChannelType.voice) | ||
| 47 | self.voice_states = {} | ||
| 48 | |||
| 49 | |||
| 50 | class MockGuild: | ||
| 51 | def __init__(self, id=99999, name="Test Server"): | ||
| 52 | self.id = id | ||
| 53 | self.name = name | ||
| 54 | self.channels = [] | ||
| 55 | self.roles = [] | ||
| 56 | self.emojis = [] | ||
| 57 | self.me = MockUser(id=111111, name="Sen Bot") | ||
| 58 | self._state = MagicMock() | ||
| 59 | self._default_role = None | ||
| 60 | |||
| 61 | def get_channel(self, channel_id): | ||
| 62 | for ch in self.channels: | ||
| 63 | if ch.id == channel_id: | ||
| 64 | return ch | ||
| 65 | return None | ||
| 66 | |||
| 67 | def get_role(self, role_id): | ||
| 68 | for role in self.roles: | ||
| 69 | if role.id == role_id: | ||
| 70 | return role | ||
| 71 | return None | ||
| 72 | |||
| 73 | def get_member(self, member_id): | ||
| 74 | return None | ||
| 75 | |||
| 76 | |||
| 77 | class MockMessage: | ||
| 78 | def __init__(self, id=22222, content="test message", author=None, channel=None, guild=None): | ||
| 79 | self.id = id | ||
| 80 | self.content = content | ||
| 81 | self.author = author or MockUser() | ||
| 82 | self.channel = channel or MockChannel() | ||
| 83 | self.guild = guild | ||
| 84 | self.attachments = [] | ||
| 85 | self.embeds = [] | ||
| 86 | self.jump_url = "https://discord.com/channels/..." | ||
| 87 | self.created_at = None | ||
| 88 | |||
| 89 | async def reply(self, *args, **kwargs): | ||
| 90 | return MagicMock() | ||
| 91 | |||
| 92 | |||
| 93 | class MockInteraction: | ||
| 94 | def __init__(self, user=None, channel=None, guild=None): | ||
| 95 | self.user = user or MockUser() | ||
| 96 | self.channel = channel or MockChannel() | ||
| 97 | self.guild = guild or MockGuild() | ||
| 98 | self.message = None | ||
| 99 | self.response = AsyncMock() | ||
| 100 | self.followup = AsyncMock() | ||
| 101 | self.client = None | ||
| 102 | self.id = 33333 | ||
| 103 | self.token = "test_token" | ||
| 104 | self._state = MagicMock() | ||
| 105 | |||
| 106 | async def defer(self, *args, **kwargs): | ||
| 107 | pass | ||
| 108 | |||
| 109 | async def respond(self, *args, **kwargs): | ||
| 110 | pass | ||
| 111 | |||
| 112 | async def delete_original_response(self, *args, **kwargs): | ||
| 113 | pass | ||
| 114 | |||
| 115 | async def send(self, *args, **kwargs): | ||
| 116 | return MagicMock() | ||
| 117 | |||
| 118 | |||
| 119 | class MockApplicationContext: | ||
| 120 | def __init__(self, bot=None, interaction=None, user=None, channel=None, guild=None): | ||
| 121 | self.bot = bot | ||
| 122 | self.interaction = interaction or MockInteraction(user=user, channel=channel, guild=guild) | ||
| 123 | self.user = user or MockUser() | ||
| 124 | self.channel = channel or MockChannel() | ||
| 125 | self.guild = guild or MockGuild() | ||
| 126 | self.message = None | ||
| 127 | self.response = AsyncMock() | ||
| 128 | self.followup = AsyncMock() | ||
| 129 | self.client = self.bot | ||
| 130 | self.id = 33333 | ||
| 131 | self.token = "test_token" | ||
| 132 | self._state = self.interaction._state | ||
| 133 | self.author = self.user | ||
| 134 | |||
| 135 | async def defer(self, *args, **kwargs): | ||
| 136 | pass | ||
| 137 | |||
| 138 | async def respond(self, *args, **kwargs): | ||
| 139 | pass | ||
| 140 | |||
| 141 | async def delete_original_response(self, *args, **kwargs): | ||
| 142 | pass | ||
| 143 | |||
| 144 | async def send(self, *args, **kwargs): | ||
| 145 | return MagicMock() | ||
| 146 | |||
| 147 | async def reply(self, *args, **kwargs): | ||
| 148 | return MagicMock() | ||
| 149 | |||
| 150 | async def send_followup(self, *args, **kwargs): | ||
| 151 | return MagicMock() | ||
| 152 | |||
| 153 | |||
| 154 | @pytest.fixture | ||
| 155 | def mock_guild(): | ||
| 156 | return MockGuild() | ||
| 157 | |||
| 158 | |||
| 159 | @pytest.fixture | ||
| 160 | def mock_channel(mock_guild): | ||
| 161 | channel = MockTextChannel() | ||
| 162 | channel.guild = mock_guild | ||
| 163 | return channel | ||
| 164 | |||
| 165 | |||
| 166 | @pytest.fixture | ||
| 167 | def mock_voice_channel(mock_guild): | ||
| 168 | channel = MockVoiceChannel() | ||
| 169 | channel.guild = mock_guild | ||
| 170 | return channel | ||
| 171 | |||
| 172 | |||
| 173 | @pytest.fixture | ||
| 174 | def mock_user(): | ||
| 175 | return MockUser() | ||
| 176 | |||
| 177 | |||
| 178 | @pytest.fixture | ||
| 179 | def mock_member(mock_guild): | ||
| 180 | member = MockUser() | ||
| 181 | member.guild = mock_guild | ||
| 182 | return member | ||
| 183 | |||
| 184 | |||
| 185 | @pytest.fixture | ||
| 186 | def mock_message(mock_channel, mock_user, mock_guild): | ||
| 187 | return MockMessage(channel=mock_channel, author=mock_user, guild=mock_guild) | ||
| 188 | |||
| 189 | |||
| 190 | @pytest.fixture | ||
| 191 | def mock_interaction(mock_channel, mock_user, mock_guild): | ||
| 192 | return MockInteraction(user=mock_user, channel=mock_channel, guild=mock_guild) | ||
| 193 | |||
| 194 | |||
| 195 | @pytest.fixture | ||
| 196 | def bot(): | ||
| 197 | intents = discord.Intents.all() | ||
| 198 | return commands.Bot(intents=intents, command_prefix="!", loop=asyncio.new_event_loop()) \ No newline at end of file | ||
