Improve Error Messages in CommandHandler.__init__ (#2837)

This commit is contained in:
Bibo-Joshi 2021-12-31 16:04:21 +01:00 committed by Hinrich Mahler
parent ced58b790e
commit 9a8c76fc2b
2 changed files with 4 additions and 2 deletions

View file

@ -97,7 +97,7 @@ class CommandHandler(Handler[Update, CCT]):
self.command = [x.lower() for x in command]
for comm in self.command:
if not re.match(r'^[\da-z_]{1,32}$', comm):
raise ValueError('Command is not a valid bot command')
raise ValueError(f'Command `{comm}` is not a valid bot command')
self.filters = filters if filters is not None else filters_module.UpdateType.MESSAGES

View file

@ -173,7 +173,9 @@ class TestCommandHandler(BaseTest):
ids=['too long', 'invalid letter', 'invalid characters'],
)
def test_invalid_commands(self, cmd):
with pytest.raises(ValueError, match='not a valid bot command'):
with pytest.raises(
ValueError, match=f'`{re.escape(cmd.lower())}` is not a valid bot command'
):
CommandHandler(cmd, self.callback_basic)
def test_command_list(self):