mypy: Enable explicit-override error.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-26 13:52:38 -07:00
parent 43654b9cf2
commit 6cb1d5f775
31 changed files with 86 additions and 3 deletions

View file

@ -41,6 +41,7 @@ enable_error_code = [
"truthy-iterable", "truthy-iterable",
"ignore-without-code", "ignore-without-code",
"unused-awaitable", "unused-awaitable",
"explicit-override",
] ]
# Other options. # Other options.

View file

@ -9,6 +9,7 @@ from typing import Any, Awaitable, Callable, Iterator, List
from unittest import TestCase, mock from unittest import TestCase, mock
import nio import nio
from typing_extensions import override
from .matrix_bridge import MatrixToZulip, ZulipToMatrix, read_configuration from .matrix_bridge import MatrixToZulip, ZulipToMatrix, read_configuration
@ -183,6 +184,7 @@ class MatrixBridgeMatrixToZulipTests(TestCase):
room = mock.MagicMock() room = mock.MagicMock()
room.user_name = lambda _: "John Smith" room.user_name = lambda _: "John Smith"
@override
def setUp(self) -> None: def setUp(self) -> None:
self.matrix_to_zulip = mock.MagicMock() self.matrix_to_zulip = mock.MagicMock()
self.matrix_to_zulip.get_message_content_from_event = ( self.matrix_to_zulip.get_message_content_from_event = (
@ -229,6 +231,7 @@ class MatrixBridgeZulipToMatrixTests(TestCase):
subject=valid_zulip_config["topic"], subject=valid_zulip_config["topic"],
) )
@override
def setUp(self) -> None: def setUp(self) -> None:
self.zulip_to_matrix = mock.MagicMock() self.zulip_to_matrix = mock.MagicMock()
self.zulip_to_matrix.zulip_config = self.valid_zulip_config self.zulip_to_matrix.zulip_config = self.valid_zulip_config

View file

@ -17,6 +17,7 @@ from html.parser import HTMLParser
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
import feedparser import feedparser
from typing_extensions import override
import zulip import zulip
@ -138,6 +139,7 @@ class MLStripper(HTMLParser):
self.reset() self.reset()
self.fed: List[str] = [] self.fed: List[str] = []
@override
def handle_data(self, data: str) -> None: def handle_data(self, data: str) -> None:
self.fed.append(data) self.fed.append(data)

View file

@ -16,6 +16,8 @@ from ctypes import (
c_void_p, c_void_p,
) )
from typing_extensions import override
libc = CDLL("libc.so.6") libc = CDLL("libc.so.6")
com_err = CDLL("libcom_err.so.2") com_err = CDLL("libcom_err.so.2")
libzephyr = CDLL("libzephyr.so.4") libzephyr = CDLL("libzephyr.so.4")
@ -198,6 +200,7 @@ class ZephyrError(Exception):
def __init__(self, code: int) -> None: def __init__(self, code: int) -> None:
self.code = code self.code = code
@override
def __str__(self) -> str: def __str__(self) -> str:
return error_message(self.code).decode() return error_message(self.code).decode()

View file

@ -67,7 +67,7 @@ setup(
"requests[security]>=0.12.1", "requests[security]>=0.12.1",
"distro", "distro",
"click", "click",
"typing_extensions>=3.7", "typing_extensions>=4.5.0",
], ],
packages=find_packages(exclude=["tests"]), packages=find_packages(exclude=["tests"]),
) )

View file

@ -27,7 +27,7 @@ from typing import (
import distro import distro
import requests import requests
from typing_extensions import Literal from typing_extensions import Literal, override
__version__ = "0.8.2" __version__ = "0.8.2"
@ -125,6 +125,7 @@ class CountingBackoff:
class RandomExponentialBackoff(CountingBackoff): class RandomExponentialBackoff(CountingBackoff):
@override
def fail(self) -> None: def fail(self) -> None:
super().fail() super().fail()
# Exponential growth with ratio sqrt(2); compute random delay # Exponential growth with ratio sqrt(2); compute random delay
@ -1802,6 +1803,7 @@ if LEGACY_CLIENT_INTERFACE_FROM_SERVER_DOCS_VERSION == "3":
# This block is support for testing Zulip 3.x, which documents old # This block is support for testing Zulip 3.x, which documents old
# interfaces for the following functions: # interfaces for the following functions:
class LegacyInterfaceClient(Client): class LegacyInterfaceClient(Client):
@override
def update_user_group_members(self, group_data: Dict[str, Any]) -> Dict[str, Any]: # type: ignore[override] # Intentional override; see comments above. def update_user_group_members(self, group_data: Dict[str, Any]) -> Dict[str, Any]: # type: ignore[override] # Intentional override; see comments above.
modern_group_data = group_data.copy() modern_group_data = group_data.copy()
group_id = group_data["group_id"] group_id = group_data["group_id"]

View file

@ -57,7 +57,7 @@ setup(
"html2text", "html2text",
"lxml", "lxml",
"BeautifulSoup4", "BeautifulSoup4",
"typing_extensions", "typing_extensions>=4.5.0",
'importlib-metadata >= 3.6; python_version < "3.10"', 'importlib-metadata >= 3.6; python_version < "3.10"',
], ],
packages=find_packages(), packages=find_packages(),

View file

@ -1,5 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -7,6 +9,7 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
class TestBaremetricsBot(BotTestCase, DefaultTests): class TestBaremetricsBot(BotTestCase, DefaultTests):
bot_name = "baremetrics" bot_name = "baremetrics"
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"api_key": "TEST"}), patch("requests.get"): with self.mock_config_info({"api_key": "TEST"}), patch("requests.get"):
self.verify_reply("", "No Command Specified") self.verify_reply("", "No Command Specified")

View file

@ -1,3 +1,5 @@
from typing_extensions import override
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -107,6 +109,7 @@ To make your next move, respond to Chess Bot with
h g f e d c b a h g f e d c b a
```""" ```"""
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"stockfish_location": "/foo/bar"}): with self.mock_config_info({"stockfish_location": "/foo/bar"}):
response = self.get_response(dict(content="")) response = self.get_response(dict(content=""))

View file

@ -1,5 +1,7 @@
from typing import Dict, List from typing import Dict, List
from typing_extensions import override
from zulip_bots.bots.connect_four.controller import ConnectFourModel from zulip_bots.bots.connect_four.controller import ConnectFourModel
from zulip_bots.game_handler import BadMoveException from zulip_bots.game_handler import BadMoveException
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -8,6 +10,7 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests
class TestConnectFourBot(BotTestCase, DefaultTests): class TestConnectFourBot(BotTestCase, DefaultTests):
bot_name = "connect_four" bot_name = "connect_four"
@override
def make_request_message( def make_request_message(
self, content: str, user: str = "foo@example.com", user_name: str = "foo" self, content: str, user: str = "foo@example.com", user_name: str = "foo"
) -> Dict[str, str]: ) -> Dict[str, str]:

View file

@ -3,6 +3,8 @@ from contextlib import contextmanager
from typing import ByteString, Iterator from typing import ByteString, Iterator
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.test_file_utils import read_bot_fixture_data from zulip_bots.test_file_utils import read_bot_fixture_data
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -71,6 +73,7 @@ class TestDialogFlowBot(BotTestCase, DefaultTests):
def test_alternate_response(self) -> None: def test_alternate_response(self) -> None:
self._test("test_alternate_result", "hello", "alternate result") self._test("test_alternate_result", "hello", "alternate result")
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"key": "abcdefg", "bot_info": "bot info foo bar"}): with self.mock_config_info({"key": "abcdefg", "bot_info": "bot info foo bar"}):
pass pass

View file

@ -1,3 +1,5 @@
from typing_extensions import override
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -30,6 +32,7 @@ class TestFollowUpBot(BotTestCase, DefaultTests):
self.assertEqual(response["content"], "from foo@example.com: feed the cat") self.assertEqual(response["content"], "from foo@example.com: feed the cat")
self.assertEqual(response["to"], "issue") self.assertEqual(response["to"], "issue")
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
bot_response = ( bot_response = (
"Please specify the message you want to send to followup stream after @mention-bot" "Please specify the message you want to send to followup stream after @mention-bot"

View file

@ -1,11 +1,14 @@
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from typing_extensions import override
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
class TestFrontBot(BotTestCase, DefaultTests): class TestFrontBot(BotTestCase, DefaultTests):
bot_name = "front" bot_name = "front"
@override
def make_request_message(self, content: str) -> Dict[str, Any]: def make_request_message(self, content: str) -> Dict[str, Any]:
message = super().make_request_message(content) message = super().make_request_message(content)
message["subject"] = "cnv_kqatm2" message["subject"] = "cnv_kqatm2"
@ -18,6 +21,7 @@ class TestFrontBot(BotTestCase, DefaultTests):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
bot, bot_handler = self._get_handlers() bot, bot_handler = self._get_handlers()
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"api_key": "TEST"}): with self.mock_config_info({"api_key": "TEST"}):
self.verify_reply("", "Unknown command. Use `help` for instructions.") self.verify_reply("", "Unknown command. Use `help` for instructions.")
@ -87,11 +91,13 @@ class TestFrontBot(BotTestCase, DefaultTests):
class TestFrontBotWrongTopic(BotTestCase, DefaultTests): class TestFrontBotWrongTopic(BotTestCase, DefaultTests):
bot_name = "front" bot_name = "front"
@override
def make_request_message(self, content: str) -> Dict[str, Any]: def make_request_message(self, content: str) -> Dict[str, Any]:
message = super().make_request_message(content) message = super().make_request_message(content)
message["subject"] = "kqatm2" message["subject"] = "kqatm2"
return message return message
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
pass pass

View file

@ -1,6 +1,8 @@
from typing import Any, Dict, List from typing import Any, Dict, List
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.game_handler import GameInstance from zulip_bots.game_handler import GameInstance
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -8,6 +10,7 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests
class TestGameHandlerBot(BotTestCase, DefaultTests): class TestGameHandlerBot(BotTestCase, DefaultTests):
bot_name = "game_handler_bot" bot_name = "game_handler_bot"
@override
def make_request_message( def make_request_message(
self, self,
content: str, content: str,

View file

@ -1,6 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
from typing_extensions import override
from zulip_bots.test_file_utils import get_bot_message_handler from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -10,6 +11,7 @@ class TestGiphyBot(BotTestCase, DefaultTests):
bot_name = "giphy" bot_name = "giphy"
# Test for bot response to empty message # Test for bot response to empty message
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
bot_response = ( bot_response = (
"[Click to enlarge]" "[Click to enlarge]"

View file

@ -1,3 +1,5 @@
from typing_extensions import override
from zulip_bots.test_file_utils import get_bot_message_handler from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -8,6 +10,7 @@ class TestGithubDetailBot(BotTestCase, DefaultTests):
empty_config = {"owner": "", "repo": ""} empty_config = {"owner": "", "repo": ""}
# Overrides default test_bot_usage(). # Overrides default test_bot_usage().
@override
def test_bot_usage(self) -> None: def test_bot_usage(self) -> None:
bot = get_bot_message_handler(self.bot_name) bot = get_bot_message_handler(self.bot_name)
bot_handler = StubBotHandler() bot_handler = StubBotHandler()
@ -18,6 +21,7 @@ class TestGithubDetailBot(BotTestCase, DefaultTests):
self.assertIn("displays details on github issues", bot.usage()) self.assertIn("displays details on github issues", bot.usage())
# Override default function in BotTestCase # Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply("", "Failed to find any issue or PR.") self.verify_reply("", "Failed to find any issue or PR.")

View file

@ -1,5 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -112,6 +114,7 @@ class TestIDoneThisBot(BotTestCase, DefaultTests):
" * ID: 72c8241d2218464433268c5abd6625ac104e3d8f", " * ID: 72c8241d2218464433268c5abd6625ac104e3d8f",
) )
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info( with self.mock_config_info(
{"api_key": "12345678", "bot_info": "team"} {"api_key": "12345678", "bot_info": "team"}

View file

@ -1,5 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -11,6 +13,7 @@ class TestLinkShortenerBot(BotTestCase, DefaultTests):
with self.mock_config_info({"key": "qwertyuiop"}): with self.mock_config_info({"key": "qwertyuiop"}):
self.verify_reply(message, response) self.verify_reply(message, response)
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with patch("requests.get"): with patch("requests.get"):
self._test( self._test(

View file

@ -1,5 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.bots.mention.mention import MentionHandler from zulip_bots.bots.mention.mention import MentionHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -7,6 +9,7 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
class TestMentionBot(BotTestCase, DefaultTests): class TestMentionBot(BotTestCase, DefaultTests):
bot_name = "mention" bot_name = "mention"
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"access_token": "12345"}), patch("requests.get"): with self.mock_config_info({"access_token": "12345"}), patch("requests.get"):
self.verify_reply("", "Empty Mention Query") self.verify_reply("", "Empty Mention Query")

View file

@ -3,6 +3,7 @@ from typing import Any, Dict, Iterator
from unittest.mock import patch from unittest.mock import patch
from simple_salesforce.exceptions import SalesforceAuthenticationFailed from simple_salesforce.exceptions import SalesforceAuthenticationFailed
from typing_extensions import override
from zulip_bots.test_file_utils import read_bot_fixture_data from zulip_bots.test_file_utils import read_bot_fixture_data
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -111,6 +112,7 @@ class TestSalesforceBot(BotTestCase, DefaultTests):
), mock_salesforce_commands_types(): ), mock_salesforce_commands_types():
bot, bot_handler = self._get_handlers() bot, bot_handler = self._get_handlers()
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
self._test("test_one_result", "", help_text) self._test("test_one_result", "", help_text)

View file

@ -2,6 +2,8 @@ import copy
import random import random
from typing import Any, List, Tuple from typing import Any, List, Tuple
from typing_extensions import override
from zulip_bots.game_handler import BadMoveException, GameAdapter from zulip_bots.game_handler import BadMoveException, GameAdapter
# ------------------------------------- # -------------------------------------
@ -267,6 +269,7 @@ class ticTacToeHandler(GameAdapter):
"description": "Lets you play Tic-tac-toe against a computer.", "description": "Lets you play Tic-tac-toe against a computer.",
} }
@override
def usage(self) -> str: def usage(self) -> str:
return """ return """
You can play tic-tac-toe now! Make sure your You can play tic-tac-toe now! Make sure your

View file

@ -1,5 +1,7 @@
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.bots.trello.trello import TrelloHandler from zulip_bots.bots.trello.trello import TrelloHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -9,10 +11,12 @@ mock_config = {"api_key": "TEST", "access_token": "TEST", "user_name": "TEST"}
class TestTrelloBot(BotTestCase, DefaultTests): class TestTrelloBot(BotTestCase, DefaultTests):
bot_name: str = "trello" bot_name: str = "trello"
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(mock_config), patch("requests.get"): with self.mock_config_info(mock_config), patch("requests.get"):
self.verify_reply("", "Empty Query") self.verify_reply("", "Empty Query")
@override
def test_bot_usage(self) -> None: def test_bot_usage(self) -> None:
with self.mock_config_info(mock_config), patch("requests.get"): with self.mock_config_info(mock_config), patch("requests.get"):
self.verify_reply( self.verify_reply(

View file

@ -3,6 +3,8 @@ import json
from typing import Any, Dict, Optional, Tuple from typing import Any, Dict, Optional, Tuple
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.bots.trivia_quiz.trivia_quiz import ( from zulip_bots.bots.trivia_quiz.trivia_quiz import (
fix_quotes, fix_quotes,
get_quiz_from_id, get_quiz_from_id,
@ -41,6 +43,7 @@ class TestTriviaQuizBot(BotTestCase, DefaultTests):
else: else:
self.verify_reply(message, response) self.verify_reply(message, response)
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
self._test("", 'type "new" for a new question') self._test("", 'type "new" for a new question')

View file

@ -1,6 +1,8 @@
from typing import Optional from typing import Optional
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -26,6 +28,7 @@ class TestWeatherBot(BotTestCase, DefaultTests):
self.verify_reply(message, response) self.verify_reply(message, response)
# Override default function in BotTestCase # Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with patch("requests.get"): with patch("requests.get"):
self._test("", self.help_content) self._test("", self.help_content)

View file

@ -1,6 +1,8 @@
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from unittest.mock import patch from unittest.mock import patch
from typing_extensions import override
from zulip_bots.test_file_utils import get_bot_message_handler from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -28,6 +30,7 @@ class TestWitaiBot(BotTestCase, DefaultTests):
self.verify_reply("What is your favorite food?", "pizza") self.verify_reply("What is your favorite food?", "pizza")
# This overrides the default one in `BotTestCase`. # This overrides the default one in `BotTestCase`.
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with patch("zulip_bots.bots.witai.witai.get_handle", return_value=mock_handle): with patch("zulip_bots.bots.witai.witai.get_handle", return_value=mock_handle):
with self.mock_config_info(self.MOCK_CONFIG_INFO): with self.mock_config_info(self.MOCK_CONFIG_INFO):

View file

@ -1,5 +1,7 @@
from typing import Optional from typing import Optional
from typing_extensions import override
from zulip_bots.bots.yoda.yoda import ServiceUnavailableError from zulip_bots.bots.yoda.yoda import ServiceUnavailableError
from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.test_lib import BotTestCase, DefaultTests
@ -30,6 +32,7 @@ class TestYodaBot(BotTestCase, DefaultTests):
self.verify_reply(message, response) self.verify_reply(message, response)
# Override default function in BotTestCase # Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
self._test("", self.help_text) self._test("", self.help_text)

View file

@ -2,6 +2,7 @@ from typing import Dict
from unittest.mock import patch from unittest.mock import patch
from requests.exceptions import ConnectionError, HTTPError from requests.exceptions import ConnectionError, HTTPError
from typing_extensions import override
from zulip_bots.test_file_utils import get_bot_message_handler from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
@ -27,6 +28,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests):
) )
# Override default function in BotTestCase # Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None: def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(self.normal_config), self.mock_http_conversation("test_keyok"): with self.mock_config_info(self.normal_config), self.mock_http_conversation("test_keyok"):
self.verify_reply("", self.help_content) self.verify_reply("", self.help_content)

View file

@ -5,6 +5,8 @@ import re
from copy import deepcopy from copy import deepcopy
from typing import Any, Dict, List, Tuple from typing import Any, Dict, List, Tuple
from typing_extensions import override
from zulip_bots.lib import BotHandler from zulip_bots.lib import BotHandler
@ -12,6 +14,7 @@ class BadMoveException(Exception):
def __init__(self, message: str) -> None: def __init__(self, message: str) -> None:
self.message = message self.message = message
@override
def __str__(self) -> str: def __str__(self) -> str:
return self.message return self.message
@ -20,6 +23,7 @@ class SamePlayerMove(Exception):
def __init__(self, message: str) -> None: def __init__(self, message: str) -> None:
self.message = message self.message = message
@override
def __str__(self) -> str: def __str__(self) -> str:
return self.message return self.message

View file

@ -44,6 +44,7 @@ setup(
"zulip", "zulip",
"zulip_bots", "zulip_bots",
"flask>=0.12.2", "flask>=0.12.2",
"typing_extensions>=4.5.0",
], ],
packages=find_packages(exclude=["tests"]), packages=find_packages(exclude=["tests"]),
) )

View file

@ -3,10 +3,13 @@ import json
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
from unittest import TestCase, mock from unittest import TestCase, mock
from typing_extensions import override
from zulip_botserver import server from zulip_botserver import server
class BotServerTestCase(TestCase): class BotServerTestCase(TestCase):
@override
def setUp(self) -> None: def setUp(self) -> None:
server.app.testing = True server.app.testing = True
self.app = server.app.test_client() self.app = server.app.test_client()

View file

@ -9,6 +9,7 @@ from typing import Any, Dict
from unittest import mock from unittest import mock
import importlib_metadata as metadata import importlib_metadata as metadata
from typing_extensions import override
from zulip_bots.lib import BotHandler from zulip_bots.lib import BotHandler
from zulip_botserver import server from zulip_botserver import server
@ -26,6 +27,7 @@ class BotServerTests(BotServerTestCase):
def handler_class(self) -> Any: def handler_class(self) -> Any:
return BotServerTests.MockMessageHandler() return BotServerTests.MockMessageHandler()
@override
def setUp(self) -> None: def setUp(self) -> None:
# Since initializing Client invokes `get_server_settings` that fails in the test # Since initializing Client invokes `get_server_settings` that fails in the test
# environment, we need to mock it to pretend that there exists a backend. # environment, we need to mock it to pretend that there exists a backend.