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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
"""
The MIT License (MIT)
Copyright (c) 2015-present Rapptz
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
import discord
from discord import app_commands
from discord.ext import commands
def test_descriptions_describe():
@app_commands.command(description='This is the short description that will appear.')
@app_commands.describe(arg='Decorator description of arg.')
@app_commands.describe(arg2='Decorator description of arg2.')
async def describe(interaction: discord.Interaction, arg: str, arg2: int) -> None:
...
assert describe.description == 'This is the short description that will appear.'
assert describe.get_parameter('arg').description == 'Decorator description of arg.' # type: ignore
assert describe.get_parameter('arg2').description == 'Decorator description of arg2.' # type: ignore
def test_descriptions_no_args():
@app_commands.command()
async def no_args(interaction: discord.Interaction) -> None:
"""This is the short description that will appear."""
assert no_args.description == 'This is the short description that will appear.'
def test_descriptions_numpy():
@app_commands.command()
async def numpy(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
Parameters
----------
arg: str
Docstring description of arg.
This is the second line of the arg docstring.
arg2: int
Docstring description of arg2.
"""
assert numpy.description == 'This is the short description that will appear.'
assert numpy.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert numpy.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_numpy_extras():
@app_commands.command()
async def numpy(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
Parameters
----------
interaction: discord.Interaction
The interaction object.
arg: str
Docstring description of arg.
This is the second line of the arg docstring.
arg2: int
Docstring description of arg2.
Returns
-------
NoneType
This function does not return anything.
"""
assert numpy.description == 'This is the short description that will appear.'
assert numpy.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert numpy.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_google():
@app_commands.command()
async def google(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
Args:
arg: Docstring description of arg.
This is the second line of the arg docstring.
arg2 (int): Docstring description of arg2.
"""
assert google.description == 'This is the short description that will appear.'
assert google.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert google.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_google_extras():
@app_commands.command()
async def google(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
Args:
interaction: discord.Interaction
The interaction object.
arg: Docstring description of arg.
This is the second line of the arg docstring.
arg2 (int): Docstring description of arg2.
Returns:
NoneType
This function does not return anything.
"""
assert google.description == 'This is the short description that will appear.'
assert google.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert google.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_sphinx():
@app_commands.command()
async def sphinx(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
:param arg: Docstring description of arg.
This is the second line of the arg docstring.
:type arg: str
:param arg2: Docstring description of arg2.
:type arg2: int
"""
assert sphinx.description == 'This is the short description that will appear.'
assert sphinx.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert sphinx.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_sphinx_extras():
@app_commands.command()
async def sphinx(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This is the short description that will appear.
This extended description will not appear in the command description.
:param interaction: The interaction object.
:type interaction: :class:`discord.Interaction`
:param arg: Docstring description of arg.
This is the second line of the arg docstring.
:type arg: :class:`str`
:param arg2: Docstring description of arg2.
:type arg2: :class:`int`
:return: None
:rtpye: NoneType
"""
assert sphinx.description == 'This is the short description that will appear.'
assert sphinx.get_parameter('arg').description == 'Docstring description of arg. This is the second line of the arg docstring.' # type: ignore
assert sphinx.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_docstring_and_describe():
@app_commands.command(description='This is the short description that will appear.')
@app_commands.describe(arg='Decorator description of arg.')
async def describe(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""This description will not appear since it is overriden by the decorator.
This extended description will not appear in the command description.
Args:
arg: Docstring description of arg.
This will not be used since the decorator overrides it.
arg2 (int): Docstring description of arg2.
"""
assert describe.description == 'This is the short description that will appear.'
assert describe.get_parameter('arg').description == 'Decorator description of arg.' # type: ignore
assert describe.get_parameter('arg2').description == 'Docstring description of arg2.' # type: ignore
def test_descriptions_group_no_args():
my_group = app_commands.Group(name='mygroup', description='My group')
@my_group.command()
async def my_command(interaction: discord.Interaction) -> None:
"""Test slash command"""
assert my_command.description == 'Test slash command'
def test_descriptions_group_args():
my_group = app_commands.Group(name='mygroup', description='My group')
@my_group.command()
async def my_command(interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""Test slash command
Parameters
----------
arg: str
Description of arg.
This is the second line of the arg description.
arg2: int
Description of arg2.
"""
assert my_command.description == 'Test slash command'
assert my_command.get_parameter('arg').description == 'Description of arg. This is the second line of the arg description.' # type: ignore
assert my_command.get_parameter('arg2').description == 'Description of arg2.' # type: ignore
def test_descriptions_cog_commands():
class MyCog(commands.Cog):
@app_commands.command()
async def test(self, interaction: discord.Interaction, arg: str, arg2: int) -> None:
"""Test slash command
Parameters
----------
arg: str
Description of arg.
This is the second line of the arg description.
arg2: int
Description of arg2.
"""
cog = MyCog()
assert cog.test.description == 'Test slash command'
assert cog.test.get_parameter('arg').description == 'Description of arg. This is the second line of the arg description.' # type: ignore
assert cog.test.get_parameter('arg2').description == 'Description of arg2.' # type: ignore
|