|
1 | | -from __future__ import annotations |
2 | | - |
3 | 1 | import collections |
4 | 2 | import itertools |
5 | 3 | import logging |
@@ -143,6 +141,46 @@ def _get_child_mock(self, **kw): |
143 | 141 | } |
144 | 142 | guild_instance = discord.Guild(data=guild_data, state=unittest.mock.MagicMock()) |
145 | 143 |
|
| 144 | +# Create a Role instance to get a realistic Mock of `discord.Role` |
| 145 | +role_data = {"name": "role", "id": 1} |
| 146 | +role_instance = discord.Role(guild=guild_instance, state=unittest.mock.MagicMock(), data=role_data) |
| 147 | + |
| 148 | +class MockRole(CustomMockMixin, unittest.mock.Mock, ColourMixin, HashableMixin): |
| 149 | + """ |
| 150 | + A Mock subclass to mock `discord.Role` objects. |
| 151 | +
|
| 152 | + Instances of this class will follow the specifications of `discord.Role` instances. For more |
| 153 | + information, see the `MockGuild` docstring. |
| 154 | + """ |
| 155 | + spec_set = role_instance |
| 156 | + |
| 157 | + def __init__(self, **kwargs) -> None: |
| 158 | + default_kwargs = { |
| 159 | + "id": next(self.discord_id), |
| 160 | + "name": "role", |
| 161 | + "position": 1, |
| 162 | + "colour": discord.Colour(0xdeadbf), |
| 163 | + "permissions": discord.Permissions(), |
| 164 | + } |
| 165 | + super().__init__(**collections.ChainMap(kwargs, default_kwargs)) |
| 166 | + |
| 167 | + if isinstance(self.colour, int): |
| 168 | + self.colour = discord.Colour(self.colour) |
| 169 | + |
| 170 | + if isinstance(self.permissions, int): |
| 171 | + self.permissions = discord.Permissions(self.permissions) |
| 172 | + |
| 173 | + if "mention" not in kwargs: |
| 174 | + self.mention = f"&{self.name}" |
| 175 | + |
| 176 | + def __lt__(self, other): |
| 177 | + """Simplified position-based comparisons similar to those of `discord.Role`.""" |
| 178 | + return self.position < other.position |
| 179 | + |
| 180 | + def __ge__(self, other): |
| 181 | + """Simplified position-based comparisons similar to those of `discord.Role`.""" |
| 182 | + return self.position >= other.position |
| 183 | + |
146 | 184 |
|
147 | 185 | class MockGuild(CustomMockMixin, unittest.mock.Mock, HashableMixin): |
148 | 186 | """ |
@@ -188,48 +226,6 @@ def roles(self) -> list[MockRole]: |
188 | 226 | return [MockRole(name="@everyone", position=1, id=0)] |
189 | 227 |
|
190 | 228 |
|
191 | | -# Create a Role instance to get a realistic Mock of `discord.Role` |
192 | | -role_data = {"name": "role", "id": 1} |
193 | | -role_instance = discord.Role(guild=guild_instance, state=unittest.mock.MagicMock(), data=role_data) |
194 | | - |
195 | | - |
196 | | -class MockRole(CustomMockMixin, unittest.mock.Mock, ColourMixin, HashableMixin): |
197 | | - """ |
198 | | - A Mock subclass to mock `discord.Role` objects. |
199 | | -
|
200 | | - Instances of this class will follow the specifications of `discord.Role` instances. For more |
201 | | - information, see the `MockGuild` docstring. |
202 | | - """ |
203 | | - spec_set = role_instance |
204 | | - |
205 | | - def __init__(self, **kwargs) -> None: |
206 | | - default_kwargs = { |
207 | | - "id": next(self.discord_id), |
208 | | - "name": "role", |
209 | | - "position": 1, |
210 | | - "colour": discord.Colour(0xdeadbf), |
211 | | - "permissions": discord.Permissions(), |
212 | | - } |
213 | | - super().__init__(**collections.ChainMap(kwargs, default_kwargs)) |
214 | | - |
215 | | - if isinstance(self.colour, int): |
216 | | - self.colour = discord.Colour(self.colour) |
217 | | - |
218 | | - if isinstance(self.permissions, int): |
219 | | - self.permissions = discord.Permissions(self.permissions) |
220 | | - |
221 | | - if "mention" not in kwargs: |
222 | | - self.mention = f"&{self.name}" |
223 | | - |
224 | | - def __lt__(self, other): |
225 | | - """Simplified position-based comparisons similar to those of `discord.Role`.""" |
226 | | - return self.position < other.position |
227 | | - |
228 | | - def __ge__(self, other): |
229 | | - """Simplified position-based comparisons similar to those of `discord.Role`.""" |
230 | | - return self.position >= other.position |
231 | | - |
232 | | - |
233 | 229 | # Create a Member instance to get a realistic Mock of `discord.Member` |
234 | 230 | member_data = {"user": "lemon", "roles": [1], "flags": 2} |
235 | 231 | state_mock = unittest.mock.MagicMock() |
|
0 commit comments