black: Reformat without skipping string normalization.
This commit is contained in:
parent
fba21bb00d
commit
6f3f9bf7e4
178 changed files with 5242 additions and 5242 deletions
|
@ -11,8 +11,8 @@ from zulip_bots.test_file_utils import get_bot_message_handler, read_bot_fixture
|
|||
class StubBotHandler:
|
||||
def __init__(self) -> None:
|
||||
self.storage = SimpleStorage()
|
||||
self.full_name = 'test-bot'
|
||||
self.email = 'test-bot@example.com'
|
||||
self.full_name = "test-bot"
|
||||
self.email = "test-bot@example.com"
|
||||
self.user_id = 0
|
||||
self.message_server = MockMessageServer()
|
||||
self.reset_transcript()
|
||||
|
@ -24,14 +24,14 @@ class StubBotHandler:
|
|||
return BotIdentity(self.full_name, self.email)
|
||||
|
||||
def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
||||
self.transcript.append(('send_message', message))
|
||||
self.transcript.append(("send_message", message))
|
||||
return self.message_server.send(message)
|
||||
|
||||
def send_reply(
|
||||
self, message: Dict[str, Any], response: str, widget_content: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
response_message = dict(content=response, widget_content=widget_content)
|
||||
self.transcript.append(('send_reply', response_message))
|
||||
self.transcript.append(("send_reply", response_message))
|
||||
return self.message_server.send(response_message)
|
||||
|
||||
def react(self, message: Dict[str, Any], emoji_name: str) -> Dict[str, Any]:
|
||||
|
@ -41,7 +41,7 @@ class StubBotHandler:
|
|||
self.message_server.update(message)
|
||||
|
||||
def upload_file_from_path(self, file_path: str) -> Dict[str, Any]:
|
||||
with open(file_path, 'rb') as file:
|
||||
with open(file_path, "rb") as file:
|
||||
return self.message_server.upload_file(file)
|
||||
|
||||
def upload_file(self, file: IO[Any]) -> Dict[str, Any]:
|
||||
|
@ -57,7 +57,7 @@ class StubBotHandler:
|
|||
return {}
|
||||
|
||||
def unique_reply(self) -> Dict[str, Any]:
|
||||
responses = [message for (method, message) in self.transcript if method == 'send_reply']
|
||||
responses = [message for (method, message) in self.transcript if method == "send_reply"]
|
||||
self.ensure_unique_response(responses)
|
||||
return responses[0]
|
||||
|
||||
|
@ -68,13 +68,13 @@ class StubBotHandler:
|
|||
|
||||
def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None:
|
||||
if not responses:
|
||||
raise Exception('The bot is not responding for some reason.')
|
||||
raise Exception("The bot is not responding for some reason.")
|
||||
if len(responses) > 1:
|
||||
raise Exception('The bot is giving too many responses for some reason.')
|
||||
raise Exception("The bot is giving too many responses for some reason.")
|
||||
|
||||
|
||||
class DefaultTests:
|
||||
bot_name = ''
|
||||
bot_name = ""
|
||||
|
||||
def make_request_message(self, content: str) -> Dict[str, Any]:
|
||||
raise NotImplementedError()
|
||||
|
@ -84,26 +84,26 @@ class DefaultTests:
|
|||
|
||||
def test_bot_usage(self) -> None:
|
||||
bot = get_bot_message_handler(self.bot_name)
|
||||
assert bot.usage() != ''
|
||||
assert bot.usage() != ""
|
||||
|
||||
def test_bot_responds_to_empty_message(self) -> None:
|
||||
message = self.make_request_message('')
|
||||
message = self.make_request_message("")
|
||||
|
||||
# get_response will fail if we don't respond at all
|
||||
response = self.get_response(message)
|
||||
|
||||
# we also want a non-blank response
|
||||
assert len(response['content']) >= 1
|
||||
assert len(response["content"]) >= 1
|
||||
|
||||
|
||||
class BotTestCase(unittest.TestCase):
|
||||
bot_name = ''
|
||||
bot_name = ""
|
||||
|
||||
def _get_handlers(self) -> Tuple[Any, StubBotHandler]:
|
||||
bot = get_bot_message_handler(self.bot_name)
|
||||
bot_handler = StubBotHandler()
|
||||
|
||||
if hasattr(bot, 'initialize'):
|
||||
if hasattr(bot, "initialize"):
|
||||
bot.initialize(bot_handler)
|
||||
|
||||
return bot, bot_handler
|
||||
|
@ -121,10 +121,10 @@ class BotTestCase(unittest.TestCase):
|
|||
mocking/subclassing.
|
||||
"""
|
||||
message = dict(
|
||||
display_recipient='foo_stream',
|
||||
sender_email='foo@example.com',
|
||||
sender_full_name='Foo Test User',
|
||||
sender_id='123',
|
||||
display_recipient="foo_stream",
|
||||
sender_email="foo@example.com",
|
||||
sender_full_name="Foo Test User",
|
||||
sender_id="123",
|
||||
content=content,
|
||||
)
|
||||
return message
|
||||
|
@ -139,7 +139,7 @@ class BotTestCase(unittest.TestCase):
|
|||
|
||||
def verify_reply(self, request: str, response: str) -> None:
|
||||
reply = self.get_reply_dict(request)
|
||||
self.assertEqual(response, reply['content'])
|
||||
self.assertEqual(response, reply["content"])
|
||||
|
||||
def verify_dialog(self, conversation: List[Tuple[str, str]]) -> None:
|
||||
# Start a new message handler for the full conversation.
|
||||
|
@ -150,7 +150,7 @@ class BotTestCase(unittest.TestCase):
|
|||
bot_handler.reset_transcript()
|
||||
bot.handle_message(message, bot_handler)
|
||||
response = bot_handler.unique_response()
|
||||
self.assertEqual(expected_response, response['content'])
|
||||
self.assertEqual(expected_response, response["content"])
|
||||
|
||||
def validate_invalid_config(self, config_data: Dict[str, str], error_regexp: str) -> None:
|
||||
bot_class = type(get_bot_message_handler(self.bot_name))
|
||||
|
@ -171,5 +171,5 @@ class BotTestCase(unittest.TestCase):
|
|||
|
||||
def mock_config_info(self, config_info: Dict[str, str]) -> Any:
|
||||
return unittest.mock.patch(
|
||||
'zulip_bots.test_lib.StubBotHandler.get_config_info', return_value=config_info
|
||||
"zulip_bots.test_lib.StubBotHandler.get_config_info", return_value=config_info
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue