Skip to content

Commit 1572c61

Browse files
Increase Test Coverage of CallbackQueryHandler (python-telegram-bot#2520)
* Test: let's see * Test: let's see, now in the correct place * Fix: Explicitly return None in else clause also documented this behaviour clearly in the docstring * add link in doc Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de> * Fix: remove unnecessary else statement Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de>
1 parent 5ff3b76 commit 1572c61

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

telegram/ext/callbackqueryhandler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class CallbackQueryHandler(Handler[Update]):
8181
DEPRECATED: Please switch to context based callbacks.
8282
pattern (:obj:`str` | `Pattern`, optional): Regex pattern. If not :obj:`None`, ``re.match``
8383
is used on :attr:`telegram.CallbackQuery.data` to determine if an update should be
84-
handled by this handler.
84+
handled by this handler. If :attr:`telegram.CallbackQuery.data` is not present, the
85+
:class:`telegram.CallbackQuery` update will not be handled.
8586
pass_groups (:obj:`bool`, optional): If the callback should be passed the result of
8687
``re.match(pattern, data).groups()`` as a keyword argument called ``groups``.
8788
Default is :obj:`False`

tests/test_callbackqueryhandler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def test_with_pattern(self, callback_query):
135135
callback_query.callback_query.data = 'nothing here'
136136
assert not handler.check_update(callback_query)
137137

138+
callback_query.callback_query.data = False
139+
callback_query.callback_query.game_short_name = "this is a short game name"
140+
assert not handler.check_update(callback_query)
141+
138142
def test_with_passing_group_dict(self, dp, callback_query):
139143
handler = CallbackQueryHandler(
140144
self.callback_group, pattern='(?P<begin>.*)est(?P<end>.*)', pass_groups=True

0 commit comments

Comments
 (0)