From 5580c68ae5c359875c63ceafa83c88bd54e741b8 Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Fri, 28 May 2021 17:00:04 +0800 Subject: [PATCH] isort: Reformat using isort. --- tools/custom_check.py | 1 + tools/deploy | 10 +++--- tools/lint | 4 +-- tools/provision | 6 ++-- tools/release-packages | 6 ++-- tools/review | 1 + tools/run-mypy | 8 ++--- tools/server_lib/test_handler.py | 9 ++--- tools/test-bots | 9 ++--- .../run-interrealm-bridge | 9 ++--- .../bridge_with_irc/irc-mirror.py | 3 +- .../bridge_with_irc/irc_mirror_backend.py | 5 +-- .../bridge_with_matrix/matrix_bridge.py | 19 +++++----- .../bridge_with_matrix/test_matrix.py | 15 +++----- .../bridge_with_slack/run-slack-bridge | 4 +-- .../codebase/zulip_codebase_mirror | 14 ++++---- zulip/integrations/git/post-receive | 8 +++-- zulip/integrations/git/zulip_git_config.py | 2 +- .../google/get-google-credentials | 8 ++--- zulip/integrations/google/google-calendar | 9 ++--- zulip/integrations/hg/zulip_changegroup.py | 7 ++-- zulip/integrations/jabber/jabber_mirror.py | 8 +++-- .../jabber/jabber_mirror_backend.py | 16 ++++----- zulip/integrations/log2zulip/log2zulip | 5 +-- zulip/integrations/nagios/nagios-notify-zulip | 4 +-- zulip/integrations/openshift/post_deploy | 2 ++ .../openshift/zulip_openshift_config.py | 2 +- .../perforce/zulip_change-commit.py | 4 ++- zulip/integrations/rss/rss-bot | 8 +++-- zulip/integrations/svn/post-commit | 7 ++-- zulip/integrations/trac/zulip_trac.py | 8 +++-- zulip/integrations/trello/zulip_trello.py | 2 +- zulip/integrations/twitter/twitter-bot | 5 +-- zulip/integrations/zephyr/check-mirroring | 15 ++++---- zulip/integrations/zephyr/process_ccache | 6 ++-- zulip/integrations/zephyr/sync-public-streams | 7 ++-- zulip/integrations/zephyr/zephyr_mirror.py | 7 ++-- .../zephyr/zephyr_mirror_backend.py | 23 ++++++------ zulip/setup.py | 9 +++-- zulip/tests/test_default_arguments.py | 9 ++--- zulip/tests/test_hash_util_decode.py | 3 +- zulip/zulip/__init__.py | 35 +++++++++++++------ zulip/zulip/api_examples.py | 3 +- zulip/zulip/cli.py | 4 +-- zulip/zulip/examples/get-history | 2 +- zulip/zulip/examples/print-events | 1 - zulip/zulip/examples/print-messages | 1 - zulip/zulip/examples/upload-file | 3 +- zulip/zulip/examples/welcome-message | 3 +- zulip/zulip/send.py | 3 +- zulip_bots/setup.py | 2 +- .../bots/baremetrics/baremetrics.py | 7 ++-- .../bots/baremetrics/test_baremetrics.py | 5 +-- .../zulip_bots/bots/beeminder/beeminder.py | 6 ++-- .../bots/beeminder/test_beeminder.py | 5 ++- .../zulip_bots/bots/chessbot/chessbot.py | 8 +++-- .../zulip_bots/bots/chessbot/test_chessbot.py | 1 + .../bots/connect_four/connect_four.py | 5 +-- .../bots/connect_four/controller.py | 1 + .../bots/connect_four/test_connect_four.py | 4 +-- .../zulip_bots/bots/converter/converter.py | 6 ++-- .../bots/converter/test_converter.py | 2 +- zulip_bots/zulip_bots/bots/define/define.py | 8 +++-- .../zulip_bots/bots/define/test_define.py | 4 ++- .../zulip_bots/bots/dialogflow/dialogflow.py | 4 +-- .../bots/dialogflow/test_dialogflow.py | 8 ++--- .../bots/dropbox_share/dropbox_share.py | 8 +++-- .../bots/dropbox_share/test_dropbox_share.py | 7 ++-- .../bots/dropbox_share/test_util.py | 1 + zulip_bots/zulip_bots/bots/encrypt/encrypt.py | 2 ++ .../zulip_bots/bots/encrypt/test_encrypt.py | 1 + .../bots/file_uploader/file_uploader.py | 7 ++-- .../bots/file_uploader/test_file_uploader.py | 7 ++-- zulip_bots/zulip_bots/bots/flock/flock.py | 6 ++-- .../zulip_bots/bots/flock/test_flock.py | 5 ++- .../zulip_bots/bots/followup/followup.py | 2 ++ .../zulip_bots/bots/followup/test_followup.py | 5 +-- zulip_bots/zulip_bots/bots/front/front.py | 5 ++- .../zulip_bots/bots/front/test_front.py | 1 + .../bots/game_handler_bot/game_handler_bot.py | 5 +-- .../game_handler_bot/test_game_handler_bot.py | 6 ++-- .../bots/game_of_fifteen/game_of_fifteen.py | 5 +-- .../game_of_fifteen/test_game_of_fifteen.py | 4 +-- zulip_bots/zulip_bots/bots/giphy/giphy.py | 9 ++--- .../zulip_bots/bots/giphy/test_giphy.py | 4 ++- .../bots/github_detail/github_detail.py | 5 +-- .../bots/github_detail/test_github_detail.py | 8 ++--- .../bots/google_search/google_search.py | 4 +-- .../bots/google_search/test_google_search.py | 3 +- .../bots/google_translate/google_translate.py | 1 + .../google_translate/test_google_translate.py | 1 + .../zulip_bots/bots/helloworld/helloworld.py | 2 ++ .../bots/helloworld/test_helloworld.py | 1 + zulip_bots/zulip_bots/bots/help/help.py | 2 ++ zulip_bots/zulip_bots/bots/help/test_help.py | 1 + .../zulip_bots/bots/idonethis/idonethis.py | 5 +-- .../bots/idonethis/test_idonethis.py | 1 + .../zulip_bots/bots/incident/incident.py | 1 + .../bots/incrementor/incrementor.py | 2 ++ .../bots/incrementor/test_incrementor.py | 8 ++--- zulip_bots/zulip_bots/bots/jira/jira.py | 4 ++- zulip_bots/zulip_bots/bots/jira/test_jira.py | 1 + .../bots/link_shortener/link_shortener.py | 4 ++- .../link_shortener/test_link_shortener.py | 4 +-- zulip_bots/zulip_bots/bots/mention/mention.py | 5 ++- .../zulip_bots/bots/mention/test_mention.py | 7 ++-- .../zulip_bots/bots/merels/libraries/game.py | 4 +-- .../bots/merels/libraries/mechanics.py | 10 +++--- zulip_bots/zulip_bots/bots/merels/merels.py | 11 +++--- .../bots/merels/test/test_database.py | 5 +-- .../zulip_bots/bots/merels/test/test_game.py | 7 ++-- .../bots/merels/test/test_mechanics.py | 6 ++-- .../zulip_bots/bots/merels/test_merels.py | 8 +++-- .../zulip_bots/bots/monkeytestit/lib/parse.py | 3 +- .../bots/monkeytestit/lib/report.py | 2 +- .../bots/monkeytestit/monkeytestit.py | 4 +-- .../bots/monkeytestit/test_monkeytestit.py | 3 +- .../zulip_bots/bots/salesforce/salesforce.py | 12 ++++--- .../bots/salesforce/test_salesforce.py | 8 +++-- .../bots/stack_overflow/stack_overflow.py | 5 +-- .../stack_overflow/test_stack_overflow.py | 3 +- zulip_bots/zulip_bots/bots/susi/susi.py | 5 ++- zulip_bots/zulip_bots/bots/susi/test_susi.py | 6 ++-- .../bots/tictactoe/test_tictactoe.py | 6 ++-- .../zulip_bots/bots/tictactoe/tictactoe.py | 4 +-- .../zulip_bots/bots/trello/test_trello.py | 3 +- zulip_bots/zulip_bots/bots/trello/trello.py | 6 ++-- .../bots/trivia_quiz/test_trivia_quiz.py | 23 ++++-------- .../bots/trivia_quiz/trivia_quiz.py | 7 ++-- .../zulip_bots/bots/twitpost/test_twitpost.py | 13 +++---- .../zulip_bots/bots/twitpost/twitpost.py | 5 ++- .../bots/virtual_fs/test_virtual_fs.py | 6 ++-- .../zulip_bots/bots/virtual_fs/virtual_fs.py | 5 +-- .../zulip_bots/bots/weather/test_weather.py | 3 +- zulip_bots/zulip_bots/bots/weather/weather.py | 3 +- .../bots/wikipedia/test_wikipedia.py | 3 +- .../zulip_bots/bots/wikipedia/wikipedia.py | 4 ++- .../zulip_bots/bots/witai/test_witai.py | 6 ++-- zulip_bots/zulip_bots/bots/witai/witai.py | 9 +++-- zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py | 2 ++ zulip_bots/zulip_bots/bots/xkcd/xkcd.py | 6 ++-- zulip_bots/zulip_bots/bots/yoda/test_yoda.py | 3 +- zulip_bots/zulip_bots/bots/yoda/yoda.py | 3 +- .../zulip_bots/bots/youtube/test_youtube.py | 10 +++--- zulip_bots/zulip_bots/bots/youtube/youtube.py | 7 ++-- zulip_bots/zulip_bots/finder.py | 2 +- zulip_bots/zulip_bots/game_handler.py | 9 ++--- zulip_bots/zulip_bots/lib.py | 8 ++--- zulip_bots/zulip_bots/provision.py | 5 +-- zulip_bots/zulip_bots/request_test_lib.py | 6 ++-- zulip_bots/zulip_bots/run.py | 21 ++++++----- zulip_bots/zulip_bots/simple_lib.py | 3 +- zulip_bots/zulip_bots/terminal.py | 2 +- zulip_bots/zulip_bots/test_file_utils.py | 2 -- zulip_bots/zulip_bots/test_lib.py | 27 ++++---------- zulip_bots/zulip_bots/tests/test_finder.py | 2 +- zulip_bots/zulip_bots/tests/test_lib.py | 9 ++--- zulip_bots/zulip_bots/tests/test_run.py | 13 ++++--- zulip_botserver/setup.py | 2 +- zulip_botserver/tests/server_test_lib.py | 5 +-- zulip_botserver/tests/test_server.py | 16 +++++---- zulip_botserver/zulip_botserver/server.py | 14 ++++---- 162 files changed, 539 insertions(+), 444 deletions(-) diff --git a/tools/custom_check.py b/tools/custom_check.py index e834419..54c4ae9 100644 --- a/tools/custom_check.py +++ b/tools/custom_check.py @@ -1,4 +1,5 @@ from typing import List + from zulint.custom_rules import RuleList MYPY = False diff --git a/tools/deploy b/tools/deploy index 4ba8e52..73bea63 100755 --- a/tools/deploy +++ b/tools/deploy @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -from typing import Any, List, Dict, Callable - +import argparse import os import sys -import argparse -import zipfile import textwrap -import requests import urllib.parse +import zipfile +from typing import Any, Callable, Dict, List + +import requests from requests import Response red = '\033[91m' # type: str diff --git a/tools/lint b/tools/lint index 3deda28..2c520b1 100755 --- a/tools/lint +++ b/tools/lint @@ -3,9 +3,9 @@ import argparse import sys -from zulint.command import add_default_linter_arguments, LinterConfig +from zulint.command import LinterConfig, add_default_linter_arguments -from custom_check import python_rules, non_py_rules +from custom_check import non_py_rules, python_rules EXCLUDED_FILES = [ # This is an external file that doesn't comply with our codestyle diff --git a/tools/provision b/tools/provision index 7dd3ea0..63f2557 100755 --- a/tools/provision +++ b/tools/provision @@ -1,10 +1,10 @@ #!/usr/bin/env python3 -import os -import sys import argparse -import subprocess import glob +import os +import subprocess +import sys CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) ZULIP_BOTS_DIR = os.path.join(CURRENT_DIR, '..', 'zulip_bots') diff --git a/tools/release-packages b/tools/release-packages index 4f13d84..d847669 100755 --- a/tools/release-packages +++ b/tools/release-packages @@ -1,15 +1,15 @@ #!/usr/bin/env python3 -from contextlib import contextmanager -import os import argparse import glob +import os import shutil import tempfile +from contextlib import contextmanager import crayons -import twine.commands.upload import setuptools.sandbox +import twine.commands.upload REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/tools/review b/tools/review index 8ac489d..b71a4f3 100755 --- a/tools/review +++ b/tools/review @@ -3,6 +3,7 @@ import subprocess import sys + def exit(message: str) -> None: print('PROBLEM!') print(message) diff --git a/tools/run-mypy b/tools/run-mypy index 357c599..d25e8ad 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -1,14 +1,14 @@ #!/usr/bin/env python3 -import os -import sys import argparse +import os import subprocess - +import sys from collections import OrderedDict from pathlib import PurePath +from typing import Dict, List, cast + from zulint import lister -from typing import cast, Dict, List TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) os.chdir(os.path.dirname(TOOLS_DIR)) diff --git a/tools/server_lib/test_handler.py b/tools/server_lib/test_handler.py index a1d47e5..a4a9f9f 100644 --- a/tools/server_lib/test_handler.py +++ b/tools/server_lib/test_handler.py @@ -1,10 +1,11 @@ -import os -import sys import argparse -import unittest -import pytest +import os import shutil +import sys +import unittest + +import pytest TOOLS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(TOOLS_DIR)) diff --git a/tools/test-bots b/tools/test-bots index 5f62489..308dc87 100755 --- a/tools/test-bots +++ b/tools/test-bots @@ -1,14 +1,15 @@ #!/usr/bin/env python3 -from os.path import dirname, basename - -import os -import sys import argparse import glob +import os +import sys import unittest +from os.path import basename, dirname + import pytest + def parse_args(): description = """ Script to run test_.py files in the diff --git a/zulip/integrations/bridge_between_zulips/run-interrealm-bridge b/zulip/integrations/bridge_between_zulips/run-interrealm-bridge index 97434bf..0a6a345 100755 --- a/zulip/integrations/bridge_between_zulips/run-interrealm-bridge +++ b/zulip/integrations/bridge_between_zulips/run-interrealm-bridge @@ -1,13 +1,14 @@ #!/usr/bin/env python3 -import sys -import os import argparse import multiprocessing as mp -import zulip +import os +import sys +from typing import Any, Callable, Dict + import interrealm_bridge_config -from typing import Any, Callable, Dict +import zulip def create_pipe_event(to_client: zulip.Client, from_bot: Dict[str, Any], diff --git a/zulip/integrations/bridge_with_irc/irc-mirror.py b/zulip/integrations/bridge_with_irc/irc-mirror.py index 0d767ff..e74bc87 100755 --- a/zulip/integrations/bridge_with_irc/irc-mirror.py +++ b/zulip/integrations/bridge_with_irc/irc-mirror.py @@ -5,10 +5,11 @@ # import argparse -import zulip import sys import traceback +import zulip + usage = """./irc-mirror.py --irc-server=IRC_SERVER --channel= --nick-prefix= --stream= [optional args] Example: diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 9d8ca8f..50965d4 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -1,9 +1,10 @@ +import multiprocessing as mp +from typing import Any, Dict + import irc.bot import irc.strings from irc.client import Event, ServerConnection, ip_numstr_to_quad from irc.client_aio import AioReactor -import multiprocessing as mp -from typing import Any, Dict class IRCBot(irc.bot.SingleServerIRCBot): diff --git a/zulip/integrations/bridge_with_matrix/matrix_bridge.py b/zulip/integrations/bridge_with_matrix/matrix_bridge.py index a0665d0..8722a26 100644 --- a/zulip/integrations/bridge_with_matrix/matrix_bridge.py +++ b/zulip/integrations/bridge_with_matrix/matrix_bridge.py @@ -1,23 +1,22 @@ #!/usr/bin/env python3 -import os -import logging -import signal -import traceback -import zulip -import sys import argparse -import re import configparser - +import logging +import os +import re +import signal +import sys +import traceback from collections import OrderedDict - from types import FrameType from typing import Any, Callable, Dict, Optional -from matrix_client.errors import MatrixRequestError from matrix_client.client import MatrixClient +from matrix_client.errors import MatrixRequestError from requests.exceptions import MissingSchema +import zulip + GENERAL_NETWORK_USERNAME_REGEX = '@_?[a-zA-Z0-9]+_([a-zA-Z0-9-_]+):[a-zA-Z0-9.]+' MATRIX_USERNAME_REGEX = '@([a-zA-Z0-9-_]+):matrix.org' diff --git a/zulip/integrations/bridge_with_matrix/test_matrix.py b/zulip/integrations/bridge_with_matrix/test_matrix.py index 11e74cf..b49409c 100644 --- a/zulip/integrations/bridge_with_matrix/test_matrix.py +++ b/zulip/integrations/bridge_with_matrix/test_matrix.py @@ -1,22 +1,17 @@ -from .matrix_bridge import ( - check_zulip_message_validity, - zulip_to_matrix, -) - -from unittest import TestCase, mock -from subprocess import Popen, PIPE import os - import shutil - from contextlib import contextmanager +from subprocess import PIPE, Popen from tempfile import mkdtemp +from unittest import TestCase, mock + +from .matrix_bridge import check_zulip_message_validity, zulip_to_matrix script_file = "matrix_bridge.py" script_dir = os.path.dirname(__file__) script = os.path.join(script_dir, script_file) -from typing import List, Iterator +from typing import Iterator, List sample_config_path = "matrix_test.conf" diff --git a/zulip/integrations/bridge_with_slack/run-slack-bridge b/zulip/integrations/bridge_with_slack/run-slack-bridge index 984de8b..6b7b364 100755 --- a/zulip/integrations/bridge_with_slack/run-slack-bridge +++ b/zulip/integrations/bridge_with_slack/run-slack-bridge @@ -8,11 +8,11 @@ import threading import traceback from typing import Any, Callable, Dict +import bridge_with_slack_config import slack_sdk -import zulip from slack_sdk.rtm import RTMClient -import bridge_with_slack_config +import zulip # change these templates to change the format of displayed message ZULIP_MESSAGE_TEMPLATE = "**{username}**: {message}" diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index 45051be..8904f46 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -8,15 +8,15 @@ # # python-dateutil is a dependency for this script. -import requests import logging -import pytz -import time -import sys import os - +import sys +import time from datetime import datetime, timedelta +import pytz +import requests + try: import dateutil.parser except ImportError as e: @@ -26,12 +26,14 @@ except ImportError as e: sys.path.insert(0, os.path.dirname(__file__)) import zulip_codebase_config as config + VERSION = "0.9" if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) +from typing import Any, Dict, List, Optional + import zulip -from typing import Any, List, Dict, Optional client = zulip.Client( email=config.ZULIP_USER, diff --git a/zulip/integrations/git/post-receive b/zulip/integrations/git/post-receive index 95e7633..f2772af 100755 --- a/zulip/integrations/git/post-receive +++ b/zulip/integrations/git/post-receive @@ -9,20 +9,22 @@ # For example: # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master -from typing import Text import os -import sys -import subprocess import os.path +import subprocess +import sys +from typing import Text sys.path.insert(0, os.path.dirname(__file__)) import zulip_git_config as config + VERSION = "0.9" if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) import zulip + client = zulip.Client( email=config.ZULIP_USER, site=config.ZULIP_SITE, diff --git a/zulip/integrations/git/zulip_git_config.py b/zulip/integrations/git/zulip_git_config.py index 6000a09..2a592b1 100644 --- a/zulip/integrations/git/zulip_git_config.py +++ b/zulip/integrations/git/zulip_git_config.py @@ -1,5 +1,5 @@ # -from typing import Dict, Text, Optional +from typing import Dict, Optional, Text # Name of the stream to send notifications to, default is "commits" STREAM_NAME = 'commits' diff --git a/zulip/integrations/google/get-google-credentials b/zulip/integrations/google/get-google-credentials index 2cc5abe..883c015 100644 --- a/zulip/integrations/google/get-google-credentials +++ b/zulip/integrations/google/get-google-credentials @@ -1,12 +1,10 @@ #!/usr/bin/env python3 import os - -from oauth2client import client -from oauth2client import tools -from oauth2client.file import Storage - from typing import Optional +from oauth2client import client, tools +from oauth2client.file import Storage + try: import argparse flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() # type: Optional[argparse.Namespace] diff --git a/zulip/integrations/google/google-calendar b/zulip/integrations/google/google-calendar index 231c255..518a206 100755 --- a/zulip/integrations/google/google-calendar +++ b/zulip/integrations/google/google-calendar @@ -2,20 +2,21 @@ # # This script depends on python-dateutil and python-pytz for properly handling # times and time zones of calendar events. +import argparse import datetime -import dateutil.parser -import httplib2 import itertools import logging -import argparse import os -import pytz import sys import time from typing import List, Optional, Set, Tuple +import dateutil.parser +import httplib2 +import pytz from oauth2client import client from oauth2client.file import Storage + try: from googleapiclient import discovery except ImportError: diff --git a/zulip/integrations/hg/zulip_changegroup.py b/zulip/integrations/hg/zulip_changegroup.py index a03646b..71d4e25 100755 --- a/zulip/integrations/hg/zulip_changegroup.py +++ b/zulip/integrations/hg/zulip_changegroup.py @@ -5,10 +5,13 @@ # This hook is called when changesets are pushed to the master repository (ie # `hg push`). See https://zulip.com/integrations for installation instructions. -import zulip import sys from typing import Text -from mercurial import ui, repository as repo + +from mercurial import repository as repo +from mercurial import ui + +import zulip VERSION = "0.9" diff --git a/zulip/integrations/jabber/jabber_mirror.py b/zulip/integrations/jabber/jabber_mirror.py index c14da4b..ad6efc8 100755 --- a/zulip/integrations/jabber/jabber_mirror.py +++ b/zulip/integrations/jabber/jabber_mirror.py @@ -1,13 +1,15 @@ #!/usr/bin/env python3 -import sys -import subprocess import os -import traceback import signal +import subprocess +import sys +import traceback from types import FrameType + from zulip import RandomExponentialBackoff + def die(signal: int, frame: FrameType) -> None: """We actually want to exit, so run os._exit (so as not to be caught and restarted)""" os._exit(1) diff --git a/zulip/integrations/jabber/jabber_mirror_backend.py b/zulip/integrations/jabber/jabber_mirror_backend.py index 93a1cc7..ed4b778 100755 --- a/zulip/integrations/jabber/jabber_mirror_backend.py +++ b/zulip/integrations/jabber/jabber_mirror_backend.py @@ -23,6 +23,11 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import logging +import optparse +import sys +from configparser import SafeConfigParser + # The following is a table showing which kinds of messages are handled by the # mirror in each mode: # @@ -37,18 +42,13 @@ # | other sender| x | | | # public mode +-------------+-----+----+--------+---- # | self sender | | | | -from typing import Dict, List, Set, Optional +from typing import Any, Callable, Dict, List, Optional, Set -import logging -import optparse - -from sleekxmpp import ClientXMPP, InvalidJID, JID +from sleekxmpp import JID, ClientXMPP, InvalidJID from sleekxmpp.stanza import Message as JabberMessage -from configparser import SafeConfigParser -import sys + import zulip from zulip import Client -from typing import Any, Callable __version__ = "1.1" diff --git a/zulip/integrations/log2zulip/log2zulip b/zulip/integrations/log2zulip/log2zulip index 22e8801..55d8218 100755 --- a/zulip/integrations/log2zulip/log2zulip +++ b/zulip/integrations/log2zulip/log2zulip @@ -5,8 +5,8 @@ import errno import os import platform import re -import sys import subprocess +import sys import tempfile import traceback @@ -25,9 +25,10 @@ except ImportError: import json sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../../")) -import zulip from typing import List +import zulip + temp_dir = "/var/tmp/" if os.name == "posix" else tempfile.gettempdir() def mkdir_p(path: str) -> None: diff --git a/zulip/integrations/nagios/nagios-notify-zulip b/zulip/integrations/nagios/nagios-notify-zulip index 7c86bd3..e980cf1 100755 --- a/zulip/integrations/nagios/nagios-notify-zulip +++ b/zulip/integrations/nagios/nagios-notify-zulip @@ -1,9 +1,9 @@ #!/usr/bin/env python3 import argparse -import zulip - from typing import Any, Dict, Text +import zulip + VERSION = "0.9" # Nagios passes the notification details as command line options. # In Nagios, "output" means "first line of output", and "long diff --git a/zulip/integrations/openshift/post_deploy b/zulip/integrations/openshift/post_deploy index 6458d81..4f462c6 100755 --- a/zulip/integrations/openshift/post_deploy +++ b/zulip/integrations/openshift/post_deploy @@ -9,12 +9,14 @@ from typing import Dict sys.path.insert(0, os.path.dirname(__file__)) import zulip_openshift_config as config + VERSION = '0.1' if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) import zulip + client = zulip.Client( email=config.ZULIP_USER, site=config.ZULIP_SITE, diff --git a/zulip/integrations/openshift/zulip_openshift_config.py b/zulip/integrations/openshift/zulip_openshift_config.py index 2de32c5..9957a28 100755 --- a/zulip/integrations/openshift/zulip_openshift_config.py +++ b/zulip/integrations/openshift/zulip_openshift_config.py @@ -1,5 +1,5 @@ # https://github.com/python/mypy/issues/1141 -from typing import Dict, Text, Optional +from typing import Dict, Optional, Text # Change these values to configure authentication for the plugin ZULIP_USER = 'openshift-bot@example.com' diff --git a/zulip/integrations/perforce/zulip_change-commit.py b/zulip/integrations/perforce/zulip_change-commit.py index f029f68..1764217 100755 --- a/zulip/integrations/perforce/zulip_change-commit.py +++ b/zulip/integrations/perforce/zulip_change-commit.py @@ -15,8 +15,8 @@ For example: ''' import os -import sys import os.path +import sys import git_p4 @@ -24,12 +24,14 @@ __version__ = "0.1" sys.path.insert(0, os.path.dirname(__file__)) from typing import Any, Dict, Optional + import zulip_perforce_config as config if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) import zulip + client = zulip.Client( email=config.ZULIP_USER, site=config.ZULIP_SITE, diff --git a/zulip/integrations/rss/rss-bot b/zulip/integrations/rss/rss-bot index c387732..0dbd0bb 100755 --- a/zulip/integrations/rss/rss-bot +++ b/zulip/integrations/rss/rss-bot @@ -3,21 +3,23 @@ # RSS integration for Zulip # +import argparse import calendar import errno import hashlib -from html.parser import HTMLParser import logging -import argparse import os import re import sys import time import urllib.parse -from typing import Dict, List, Tuple, Any +from html.parser import HTMLParser +from typing import Any, Dict, List, Tuple import feedparser + import zulip + VERSION = "0.9" # type: str RSS_DATA_DIR = os.path.expanduser(os.path.join('~', '.cache', 'zulip-rss')) # type: str OLDNESS_THRESHOLD = 30 # type: int diff --git a/zulip/integrations/svn/post-commit b/zulip/integrations/svn/post-commit index e88f760..31cd196 100755 --- a/zulip/integrations/svn/post-commit +++ b/zulip/integrations/svn/post-commit @@ -10,19 +10,22 @@ # /srv/svn/carols 1843 import os -import sys import os.path -import pysvn +import sys from typing import Any, Dict, Optional, Text, Tuple +import pysvn + sys.path.insert(0, os.path.dirname(__file__)) import zulip_svn_config as config + VERSION = "0.9" if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) import zulip + client = zulip.Client( email=config.ZULIP_USER, site=config.ZULIP_SITE, diff --git a/zulip/integrations/trac/zulip_trac.py b/zulip/integrations/trac/zulip_trac.py index 646c0ae..da2021e 100644 --- a/zulip/integrations/trac/zulip_trac.py +++ b/zulip/integrations/trac/zulip_trac.py @@ -11,12 +11,15 @@ # You may then need to restart trac (or restart Apache) for the bot # (or changes to the bot) to actually be loaded by trac. +import os.path +import sys + from trac.core import Component, implements from trac.ticket import ITicketChangeListener -import sys -import os.path + sys.path.insert(0, os.path.dirname(__file__)) import zulip_trac_config as config + VERSION = "0.9" from typing import Any, Dict @@ -25,6 +28,7 @@ if config.ZULIP_API_PATH is not None: sys.path.append(config.ZULIP_API_PATH) import zulip + client = zulip.Client( email=config.ZULIP_USER, site=config.ZULIP_SITE, diff --git a/zulip/integrations/trello/zulip_trello.py b/zulip/integrations/trello/zulip_trello.py index b0594da..906210e 100755 --- a/zulip/integrations/trello/zulip_trello.py +++ b/zulip/integrations/trello/zulip_trello.py @@ -3,8 +3,8 @@ # An easy Trello integration for Zulip. -import sys import argparse +import sys try: import requests diff --git a/zulip/integrations/twitter/twitter-bot b/zulip/integrations/twitter/twitter-bot index 21f094b..c624fe1 100755 --- a/zulip/integrations/twitter/twitter-bot +++ b/zulip/integrations/twitter/twitter-bot @@ -2,12 +2,13 @@ # Twitter integration for Zulip +import argparse import os import sys -import argparse -from configparser import ConfigParser, NoSectionError, NoOptionError +from configparser import ConfigParser, NoOptionError, NoSectionError import zulip + VERSION = "0.9" CONFIGFILE = os.path.expanduser("~/.zulip_twitterrc") INSTRUCTIONS = r""" diff --git a/zulip/integrations/zephyr/check-mirroring b/zulip/integrations/zephyr/check-mirroring index 6a61d16..01810c1 100755 --- a/zulip/integrations/zephyr/check-mirroring +++ b/zulip/integrations/zephyr/check-mirroring @@ -1,16 +1,17 @@ #!/usr/bin/env python3 -import sys -import time +import hashlib +import logging import optparse import random -import logging import subprocess -import hashlib -import zephyr -import zulip - +import sys +import time from typing import Dict, List, Set, Tuple +import zephyr + +import zulip + parser = optparse.OptionParser() parser.add_option('--verbose', dest='verbose', diff --git a/zulip/integrations/zephyr/process_ccache b/zulip/integrations/zephyr/process_ccache index c633345..c0fe5aa 100755 --- a/zulip/integrations/zephyr/process_ccache +++ b/zulip/integrations/zephyr/process_ccache @@ -1,8 +1,8 @@ #!/usr/bin/env python3 -import os -import sys -import subprocess import base64 +import os +import subprocess +import sys short_user = sys.argv[1] api_key = sys.argv[2] diff --git a/zulip/integrations/zephyr/sync-public-streams b/zulip/integrations/zephyr/sync-public-streams index 053c655..f6b8898 100755 --- a/zulip/integrations/zephyr/sync-public-streams +++ b/zulip/integrations/zephyr/sync-public-streams @@ -1,14 +1,15 @@ #!/usr/bin/env python3 -import sys -import os -import logging import argparse import json +import logging +import os +import sys import unicodedata sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'api')) import zulip + def write_public_streams() -> None: public_streams = set() diff --git a/zulip/integrations/zephyr/zephyr_mirror.py b/zulip/integrations/zephyr/zephyr_mirror.py index e4b4b30..aecf3c0 100755 --- a/zulip/integrations/zephyr/zephyr_mirror.py +++ b/zulip/integrations/zephyr/zephyr_mirror.py @@ -1,10 +1,10 @@ #!/usr/bin/env python3 -import sys -import subprocess import os -import traceback import signal +import subprocess +import sys +import traceback sys.path[:0] = [os.path.dirname(__file__)] from zephyr_mirror_backend import parse_args @@ -13,6 +13,7 @@ from zephyr_mirror_backend import parse_args from types import FrameType + def die(signal: int, frame: FrameType) -> None: # We actually want to exit, so run os._exit (so as not to be caught and restarted) diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 0395984..6544991 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -1,21 +1,20 @@ #!/usr/bin/env python3 -from typing import Any, Dict, IO, List, NoReturn, Optional, Set, Tuple, Union -from types import FrameType - -import sys +import hashlib import json -import re -import time -import subprocess +import logging import optparse import os -import textwrap -import signal -import logging -import hashlib -import tempfile +import re import select +import signal +import subprocess +import sys +import tempfile +import textwrap +import time +from types import FrameType +from typing import IO, Any, Dict, List, NoReturn, Optional, Set, Tuple, Union from typing_extensions import Literal, TypedDict diff --git a/zulip/setup.py b/zulip/setup.py index d12265e..1756ad1 100755 --- a/zulip/setup.py +++ b/zulip/setup.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 -from typing import Any, Dict, Generator, List, Tuple - +import itertools import os import sys - -import itertools +from typing import Any, Dict, Generator, List, Tuple with open("README.md") as fh: long_description = fh.read() @@ -73,13 +71,14 @@ setuptools_info = dict( ) try: - from setuptools import setup, find_packages + from setuptools import find_packages, setup package_info.update(setuptools_info) package_info['packages'] = find_packages(exclude=['tests']) except ImportError: from distutils.core import setup from distutils.version import LooseVersion + # Manual dependency check try: import requests diff --git a/zulip/tests/test_default_arguments.py b/zulip/tests/test_default_arguments.py index 15259f8..ac8cf4c 100755 --- a/zulip/tests/test_default_arguments.py +++ b/zulip/tests/test_default_arguments.py @@ -1,15 +1,16 @@ #!/usr/bin/env python3 import argparse -import os import io +import os import unittest -import zulip - from unittest import TestCase -from zulip import ZulipError from unittest.mock import patch +import zulip +from zulip import ZulipError + + class TestDefaultArguments(TestCase): def test_invalid_arguments(self) -> None: diff --git a/zulip/tests/test_hash_util_decode.py b/zulip/tests/test_hash_util_decode.py index fd50399..3172bc7 100644 --- a/zulip/tests/test_hash_util_decode.py +++ b/zulip/tests/test_hash_util_decode.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import unittest +from unittest import TestCase + import zulip -from unittest import TestCase class TestHashUtilDecode(TestCase): def test_hash_util_decode(self) -> None: diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 629d07e..3000ee0 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -1,21 +1,34 @@ -import json -import requests -import time -import traceback -import sys -import os -import optparse import argparse +import json +import logging +import optparse +import os import platform import random +import sys +import time +import traceback import types +import urllib.parse +from configparser import SafeConfigParser from distutils.version import LooseVersion +from typing import ( + IO, + Any, + Callable, + Dict, + Iterable, + List, + Mapping, + Optional, + Sequence, + Text, + Tuple, + Union, +) import distro -from configparser import SafeConfigParser -import urllib.parse -import logging -from typing import Any, Callable, Dict, Iterable, IO, List, Mapping, Optional, Text, Tuple, Union, Sequence +import requests __version__ = "0.8.0" diff --git a/zulip/zulip/api_examples.py b/zulip/zulip/api_examples.py index 0d67c7c..2f44334 100644 --- a/zulip/zulip/api_examples.py +++ b/zulip/zulip/api_examples.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 +import argparse import os + import zulip -import argparse def main() -> None: usage = """zulip-api-examples [script_name] diff --git a/zulip/zulip/cli.py b/zulip/zulip/cli.py index da6c7c3..a1ec761 100755 --- a/zulip/zulip/cli.py +++ b/zulip/zulip/cli.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 import logging import sys - from typing import Any, Dict, List -import zulip import click +import zulip + logging.basicConfig(stream=sys.stdout, level=logging.INFO) log = logging.getLogger("zulip-cli") diff --git a/zulip/zulip/examples/get-history b/zulip/zulip/examples/get-history index 6c79ccb..89013bb 100644 --- a/zulip/zulip/examples/get-history +++ b/zulip/zulip/examples/get-history @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import argparse import json -from typing import Dict, List, Any +from typing import Any, Dict, List import zulip diff --git a/zulip/zulip/examples/print-events b/zulip/zulip/examples/print-events index 859e0d3..5975096 100755 --- a/zulip/zulip/examples/print-events +++ b/zulip/zulip/examples/print-events @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import argparse - from typing import Any, Dict usage = """print-events [options] diff --git a/zulip/zulip/examples/print-messages b/zulip/zulip/examples/print-messages index 7f0b0f8..d852e11 100755 --- a/zulip/zulip/examples/print-messages +++ b/zulip/zulip/examples/print-messages @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import argparse - from typing import Any, Dict usage = """print-messages [options] diff --git a/zulip/zulip/examples/upload-file b/zulip/zulip/examples/upload-file index f432a75..232bf4d 100755 --- a/zulip/zulip/examples/upload-file +++ b/zulip/zulip/examples/upload-file @@ -1,11 +1,12 @@ #!/usr/bin/env python3 import argparse - from io import StringIO as _StringIO from typing import IO, Any + import zulip + class StringIO(_StringIO): name = '' # https://github.com/python/typeshed/issues/598 diff --git a/zulip/zulip/examples/welcome-message b/zulip/zulip/examples/welcome-message index 6140c4d..8dbfb9d 100755 --- a/zulip/zulip/examples/welcome-message +++ b/zulip/zulip/examples/welcome-message @@ -1,7 +1,8 @@ #!/usr/bin/env python3 +from typing import Any, Dict, List + import zulip -from typing import Any, List, Dict welcome_text = 'Hello {}, Welcome to Zulip!\n \ * The first thing you should do is to install the development environment. \ diff --git a/zulip/zulip/send.py b/zulip/zulip/send.py index 6c2feb3..88f0f1f 100755 --- a/zulip/zulip/send.py +++ b/zulip/zulip/send.py @@ -1,10 +1,9 @@ #!/usr/bin/env python3 # zulip-send -- Sends a message to the specified recipients. -import sys import argparse import logging - +import sys from typing import Any, Dict import zulip diff --git a/zulip_bots/setup.py b/zulip_bots/setup.py index 8a3d4eb..caddbc5 100644 --- a/zulip_bots/setup.py +++ b/zulip_bots/setup.py @@ -70,7 +70,7 @@ setuptools_info = dict( ) try: - from setuptools import setup, find_packages + from setuptools import find_packages, setup package_info.update(setuptools_info) package_info['packages'] = find_packages() package_info['package_data'] = package_data diff --git a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py index e84d29a..01f7db9 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py @@ -1,9 +1,12 @@ # See readme.md for instructions on running this code. -from typing import Any, List, Dict -from zulip_bots.lib import BotHandler +from typing import Any, Dict, List + import requests +from zulip_bots.lib import BotHandler + + class BaremetricsHandler: def initialize(self, bot_handler: BotHandler) -> None: self.config_info = bot_handler.get_config_info('baremetrics') diff --git a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py index 15b231d..8c7ce44 100644 --- a/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py +++ b/zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py @@ -1,7 +1,8 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.test_lib import StubBotHandler + from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler + class TestBaremetricsBot(BotTestCase, DefaultTests): bot_name = "baremetrics" diff --git a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py index 858af09..7efe852 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py @@ -1,9 +1,11 @@ -import requests import logging from typing import Dict -from zulip_bots.lib import BotHandler + +import requests from requests.exceptions import ConnectionError +from zulip_bots.lib import BotHandler + help_message = ''' You can add datapoints towards your beeminder goals \ following the syntax shown below :smile:.\n \ diff --git a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py index 909a365..3f5497c 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py @@ -1,7 +1,10 @@ from unittest.mock import patch -from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler + from requests.exceptions import ConnectionError +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + + class TestBeeminderBot(BotTestCase, DefaultTests): bot_name = "beeminder" normal_config = { diff --git a/zulip_bots/zulip_bots/bots/chessbot/chessbot.py b/zulip_bots/zulip_bots/bots/chessbot/chessbot.py index 79696a8..24bbd55 100644 --- a/zulip_bots/zulip_bots/bots/chessbot/chessbot.py +++ b/zulip_bots/zulip_bots/bots/chessbot/chessbot.py @@ -1,8 +1,10 @@ +import copy +import re +from typing import Any, Dict, Optional + import chess import chess.uci -import re -import copy -from typing import Any, Optional, Dict + from zulip_bots.lib import BotHandler START_REGEX = re.compile('start with other user$') diff --git a/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py b/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py index 113a9e4..0fba979 100644 --- a/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py +++ b/zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py @@ -1,5 +1,6 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestChessBot(BotTestCase, DefaultTests): bot_name = "chessbot" diff --git a/zulip_bots/zulip_bots/bots/connect_four/connect_four.py b/zulip_bots/zulip_bots/bots/connect_four/connect_four.py index 8bd983f..46847f9 100644 --- a/zulip_bots/zulip_bots/bots/connect_four/connect_four.py +++ b/zulip_bots/zulip_bots/bots/connect_four/connect_four.py @@ -1,7 +1,8 @@ -from zulip_bots.game_handler import GameAdapter -from zulip_bots.bots.connect_four.controller import ConnectFourModel from typing import Any +from zulip_bots.bots.connect_four.controller import ConnectFourModel +from zulip_bots.game_handler import GameAdapter + class ConnectFourMessageHandler: tokens = [':blue_circle:', ':red_circle:'] diff --git a/zulip_bots/zulip_bots/bots/connect_four/controller.py b/zulip_bots/zulip_bots/bots/connect_four/controller.py index 3120f1b..bad7474 100644 --- a/zulip_bots/zulip_bots/bots/connect_four/controller.py +++ b/zulip_bots/zulip_bots/bots/connect_four/controller.py @@ -1,5 +1,6 @@ from copy import deepcopy from functools import reduce + from zulip_bots.game_handler import BadMoveException diff --git a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py index 3e091b9..6f8765c 100644 --- a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py +++ b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests +from typing import Dict, List from zulip_bots.bots.connect_four.connect_four import ConnectFourModel from zulip_bots.game_handler import BadMoveException -from typing import Dict, List +from zulip_bots.test_lib import BotTestCase, DefaultTests class TestConnectFourBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/converter/converter.py b/zulip_bots/zulip_bots/bots/converter/converter.py index bc0412a..979da70 100644 --- a/zulip_bots/zulip_bots/bots/converter/converter.py +++ b/zulip_bots/zulip_bots/bots/converter/converter.py @@ -1,13 +1,13 @@ # See readme.md for instructions on running this code. import copy -from math import log10, floor +from math import floor, log10 +from typing import Any, Dict, List from zulip_bots.bots.converter import utils - -from typing import Any, Dict, List from zulip_bots.lib import BotHandler + def is_float(value: Any) -> bool: try: float(value) diff --git a/zulip_bots/zulip_bots/bots/converter/test_converter.py b/zulip_bots/zulip_bots/bots/converter/test_converter.py index 4d53876..6aada3d 100755 --- a/zulip_bots/zulip_bots/bots/converter/test_converter.py +++ b/zulip_bots/zulip_bots/bots/converter/test_converter.py @@ -1,6 +1,6 @@ +from zulip_bots.bots.converter import utils from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.bots.converter import utils class TestConverterBot(BotTestCase, DefaultTests): bot_name = "converter" diff --git a/zulip_bots/zulip_bots/bots/define/define.py b/zulip_bots/zulip_bots/bots/define/define.py index 86c13be..0441eb2 100644 --- a/zulip_bots/zulip_bots/bots/define/define.py +++ b/zulip_bots/zulip_bots/bots/define/define.py @@ -1,12 +1,14 @@ # See readme.md for instructions on running this code. import logging -import requests -import html2text import string - from typing import Dict + +import html2text +import requests + from zulip_bots.lib import BotHandler + class DefineHandler: ''' This plugin define a word that the user inputs. It diff --git a/zulip_bots/zulip_bots/bots/define/test_define.py b/zulip_bots/zulip_bots/bots/define/test_define.py index fcf70d9..73b5077 100755 --- a/zulip_bots/zulip_bots/bots/define/test_define.py +++ b/zulip_bots/zulip_bots/bots/define/test_define.py @@ -1,6 +1,8 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests from unittest.mock import patch +from zulip_bots.test_lib import BotTestCase, DefaultTests + + class TestDefineBot(BotTestCase, DefaultTests): bot_name = "define" diff --git a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py index f442da6..006e48c 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py @@ -1,10 +1,10 @@ # See readme.md for instructions on running this code. -import logging import json +import logging +from typing import Dict import apiai -from typing import Dict from zulip_bots.lib import BotHandler help_message = '''DialogFlow bot diff --git a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py index c27e44b..a34568d 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py @@ -1,12 +1,10 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests, read_bot_fixture_data - +import json from contextlib import contextmanager - +from typing import ByteString, Iterator from unittest.mock import patch -from typing import Iterator, ByteString +from zulip_bots.test_lib import BotTestCase, DefaultTests, read_bot_fixture_data -import json class MockHttplibRequest(): def __init__(self, response: str) -> None: diff --git a/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py b/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py index ff1d09e..f2c454a 100644 --- a/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py +++ b/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py @@ -1,7 +1,9 @@ -from dropbox import Dropbox -from typing import Any, Dict, List, Tuple -from zulip_bots.lib import BotHandler import re +from typing import Any, Dict, List, Tuple + +from dropbox import Dropbox + +from zulip_bots.lib import BotHandler URL = "[{name}](https://www.dropbox.com/home{path})" diff --git a/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py b/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py index 8b51056..ec1cfe8 100644 --- a/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py +++ b/zulip_bots/zulip_bots/bots/dropbox_share/test_dropbox_share.py @@ -1,14 +1,15 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests from unittest.mock import patch from zulip_bots.bots.dropbox_share.test_util import ( MockFileMetadata, + MockHttpResponse, MockListFolderResult, + MockPathLinkMetadata, MockSearchMatch, MockSearchResult, - MockPathLinkMetadata, - MockHttpResponse ) +from zulip_bots.test_lib import BotTestCase, DefaultTests + def get_root_files_list(*args, **kwargs): return MockListFolderResult( diff --git a/zulip_bots/zulip_bots/bots/dropbox_share/test_util.py b/zulip_bots/zulip_bots/bots/dropbox_share/test_util.py index 77e97c8..9745013 100644 --- a/zulip_bots/zulip_bots/bots/dropbox_share/test_util.py +++ b/zulip_bots/zulip_bots/bots/dropbox_share/test_util.py @@ -1,5 +1,6 @@ from typing import List + class MockFileMetadata: def __init__(self, name: str, path_lower: str): self.name = name diff --git a/zulip_bots/zulip_bots/bots/encrypt/encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/encrypt.py index 11000c0..1548c2f 100755 --- a/zulip_bots/zulip_bots/bots/encrypt/encrypt.py +++ b/zulip_bots/zulip_bots/bots/encrypt/encrypt.py @@ -1,6 +1,8 @@ from typing import Dict + from zulip_bots.lib import BotHandler + def encrypt(text: str) -> str: # This is where the actual ROT13 is applied # WHY IS .JOIN NOT WORKING?! diff --git a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py index 07a32f3..1be3ab2 100755 --- a/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py +++ b/zulip_bots/zulip_bots/bots/encrypt/test_encrypt.py @@ -1,5 +1,6 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestEncryptBot(BotTestCase, DefaultTests): bot_name = "encrypt" diff --git a/zulip_bots/zulip_bots/bots/file_uploader/file_uploader.py b/zulip_bots/zulip_bots/bots/file_uploader/file_uploader.py index c73bef1..c6bdc44 100644 --- a/zulip_bots/zulip_bots/bots/file_uploader/file_uploader.py +++ b/zulip_bots/zulip_bots/bots/file_uploader/file_uploader.py @@ -1,8 +1,9 @@ -from typing import Dict -from zulip_bots.lib import BotHandler - import os from pathlib import Path +from typing import Dict + +from zulip_bots.lib import BotHandler + class FileUploaderHandler: def usage(self) -> str: diff --git a/zulip_bots/zulip_bots/bots/file_uploader/test_file_uploader.py b/zulip_bots/zulip_bots/bots/file_uploader/test_file_uploader.py index 1498c53..2669c2e 100644 --- a/zulip_bots/zulip_bots/bots/file_uploader/test_file_uploader.py +++ b/zulip_bots/zulip_bots/bots/file_uploader/test_file_uploader.py @@ -1,11 +1,8 @@ +from pathlib import Path from unittest.mock import Mock, patch -from zulip_bots.test_lib import ( - BotTestCase, - DefaultTests, -) +from zulip_bots.test_lib import BotTestCase, DefaultTests -from pathlib import Path class TestFileUploaderBot(BotTestCase, DefaultTests): bot_name = "file_uploader" diff --git a/zulip_bots/zulip_bots/bots/flock/flock.py b/zulip_bots/zulip_bots/bots/flock/flock.py index eeb186f..5e3b8af 100644 --- a/zulip_bots/zulip_bots/bots/flock/flock.py +++ b/zulip_bots/zulip_bots/bots/flock/flock.py @@ -1,9 +1,11 @@ import logging +from typing import Any, Dict, List, Optional, Tuple + import requests -from typing import Any, Dict, List, Tuple, Optional -from zulip_bots.lib import BotHandler from requests.exceptions import ConnectionError +from zulip_bots.lib import BotHandler + USERS_LIST_URL = 'https://api.flock.co/v1/roster.listContacts' SEND_MESSAGE_URL = 'https://api.flock.co/v1/chat.sendMessage' diff --git a/zulip_bots/zulip_bots/bots/flock/test_flock.py b/zulip_bots/zulip_bots/bots/flock/test_flock.py index 6add591..e77ccf2 100644 --- a/zulip_bots/zulip_bots/bots/flock/test_flock.py +++ b/zulip_bots/zulip_bots/bots/flock/test_flock.py @@ -1,7 +1,10 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase, DefaultTests + from requests.exceptions import ConnectionError +from zulip_bots.test_lib import BotTestCase, DefaultTests + + class TestFlockBot(BotTestCase, DefaultTests): bot_name = "flock" normal_config = {"token": "12345"} diff --git a/zulip_bots/zulip_bots/bots/followup/followup.py b/zulip_bots/zulip_bots/bots/followup/followup.py index 2dbbd71..ee4d070 100644 --- a/zulip_bots/zulip_bots/bots/followup/followup.py +++ b/zulip_bots/zulip_bots/bots/followup/followup.py @@ -1,7 +1,9 @@ # See readme.md for instructions on running this code. from typing import Dict + from zulip_bots.lib import BotHandler + class FollowupHandler: ''' This plugin facilitates creating follow-up tasks when diff --git a/zulip_bots/zulip_bots/bots/followup/test_followup.py b/zulip_bots/zulip_bots/bots/followup/test_followup.py index 12f4b93..dbb4e38 100755 --- a/zulip_bots/zulip_bots/bots/followup/test_followup.py +++ b/zulip_bots/zulip_bots/bots/followup/test_followup.py @@ -1,7 +1,4 @@ -from zulip_bots.test_lib import ( - BotTestCase, - DefaultTests, -) +from zulip_bots.test_lib import BotTestCase, DefaultTests class TestFollowUpBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/front/front.py b/zulip_bots/zulip_bots/bots/front/front.py index ac58c9a..1c8a42c 100644 --- a/zulip_bots/zulip_bots/bots/front/front.py +++ b/zulip_bots/zulip_bots/bots/front/front.py @@ -1,8 +1,11 @@ -import requests import re from typing import Any, Dict + +import requests + from zulip_bots.lib import BotHandler + class FrontHandler: FRONT_API = "https://api2.frontapp.com/conversations/{}" COMMANDS = [ diff --git a/zulip_bots/zulip_bots/bots/front/test_front.py b/zulip_bots/zulip_bots/bots/front/test_front.py index b16c185..7a8182f 100644 --- a/zulip_bots/zulip_bots/bots/front/test_front.py +++ b/zulip_bots/zulip_bots/bots/front/test_front.py @@ -2,6 +2,7 @@ from typing import Any, Dict, Optional from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestFrontBot(BotTestCase, DefaultTests): bot_name = 'front' diff --git a/zulip_bots/zulip_bots/bots/game_handler_bot/game_handler_bot.py b/zulip_bots/zulip_bots/bots/game_handler_bot/game_handler_bot.py index 5c9a025..8bd6a8e 100644 --- a/zulip_bots/zulip_bots/bots/game_handler_bot/game_handler_bot.py +++ b/zulip_bots/zulip_bots/bots/game_handler_bot/game_handler_bot.py @@ -1,5 +1,6 @@ -from zulip_bots.game_handler import GameAdapter, BadMoveException -from typing import List, Any +from typing import Any, List + +from zulip_bots.game_handler import BadMoveException, GameAdapter class GameHandlerBotMessageHandler: diff --git a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py index 32c4a31..0588fec 100644 --- a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py +++ b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py @@ -1,9 +1,9 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.game_handler import GameInstance +from typing import Any, Dict, List from mock import patch -from typing import Any, Dict, List +from zulip_bots.game_handler import GameInstance +from zulip_bots.test_lib import BotTestCase, DefaultTests class TestGameHandlerBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py b/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py index 124de95..fb4bfd9 100644 --- a/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py +++ b/zulip_bots/zulip_bots/bots/game_of_fifteen/game_of_fifteen.py @@ -1,7 +1,8 @@ import copy +from typing import Any, Dict, List, Tuple + +from zulip_bots.game_handler import BadMoveException, GameAdapter -from typing import List, Any, Tuple, Dict -from zulip_bots.game_handler import GameAdapter, BadMoveException class GameOfFifteenModel: diff --git a/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py b/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py index 0fc1276..c86adf7 100644 --- a/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py +++ b/zulip_bots/zulip_bots/bots/game_of_fifteen/test_game_of_fifteen.py @@ -1,8 +1,8 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests +from typing import Dict, List, Tuple from zulip_bots.bots.game_of_fifteen.game_of_fifteen import GameOfFifteenModel from zulip_bots.game_handler import BadMoveException -from typing import Dict, List, Tuple +from zulip_bots.test_lib import BotTestCase, DefaultTests class TestGameOfFifteenBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/giphy/giphy.py b/zulip_bots/zulip_bots/bots/giphy/giphy.py index 2c985c2..56cee0e 100644 --- a/zulip_bots/zulip_bots/bots/giphy/giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/giphy.py @@ -1,10 +1,11 @@ -from typing import Dict, Union -from zulip_bots.lib import BotHandler -import requests import logging -from requests.exceptions import HTTPError, ConnectionError +from typing import Dict, Union + +import requests +from requests.exceptions import ConnectionError, HTTPError from zulip_bots.custom_exceptions import ConfigValidationError +from zulip_bots.lib import BotHandler GIPHY_TRANSLATE_API = 'http://api.giphy.com/v1/gifs/translate' GIPHY_RANDOM_API = 'http://api.giphy.com/v1/gifs/random' diff --git a/zulip_bots/zulip_bots/bots/giphy/test_giphy.py b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py index 3349150..732d116 100755 --- a/zulip_bots/zulip_bots/bots/giphy/test_giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/test_giphy.py @@ -1,7 +1,9 @@ from unittest.mock import patch + from requests.exceptions import ConnectionError -from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + class TestGiphyBot(BotTestCase, DefaultTests): bot_name = "giphy" diff --git a/zulip_bots/zulip_bots/bots/github_detail/github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/github_detail.py index ba46535..f18b6a1 100644 --- a/zulip_bots/zulip_bots/bots/github_detail/github_detail.py +++ b/zulip_bots/zulip_bots/bots/github_detail/github_detail.py @@ -1,11 +1,12 @@ -import re import logging +import re +from typing import Any, Dict, Tuple, Union import requests -from typing import Dict, Any, Tuple, Union from zulip_bots.lib import BotHandler + class GithubHandler: ''' This bot provides details on github issues and pull requests when they're diff --git a/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py index dc9eaa1..02fb308 100755 --- a/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py +++ b/zulip_bots/zulip_bots/bots/github_detail/test_github_detail.py @@ -1,9 +1,5 @@ -from zulip_bots.test_lib import ( - StubBotHandler, - BotTestCase, - DefaultTests, - get_bot_message_handler, -) +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + class TestGithubDetailBot(BotTestCase, DefaultTests): bot_name = "github_detail" diff --git a/zulip_bots/zulip_bots/bots/google_search/google_search.py b/zulip_bots/zulip_bots/bots/google_search/google_search.py index 9a521ea..6ff5b4e 100644 --- a/zulip_bots/zulip_bots/bots/google_search/google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/google_search.py @@ -1,13 +1,13 @@ # See readme.md for instructions on running this code. import logging +from typing import Dict, List import requests - from bs4 import BeautifulSoup -from typing import Dict, List from zulip_bots.lib import BotHandler + def google_search(keywords: str) -> List[Dict[str, str]]: query = {'q': keywords} # Gets the page diff --git a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py index fbffb5e..53c16c7 100644 --- a/zulip_bots/zulip_bots/bots/google_search/test_google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/test_google_search.py @@ -1,6 +1,7 @@ +from unittest.mock import patch + from zulip_bots.test_lib import BotTestCase, DefaultTests -from unittest.mock import patch class TestGoogleSearchBot(BotTestCase, DefaultTests): bot_name = 'google_search' diff --git a/zulip_bots/zulip_bots/bots/google_translate/google_translate.py b/zulip_bots/zulip_bots/bots/google_translate/google_translate.py index 7db5d30..1aeac15 100644 --- a/zulip_bots/zulip_bots/bots/google_translate/google_translate.py +++ b/zulip_bots/zulip_bots/bots/google_translate/google_translate.py @@ -3,6 +3,7 @@ import requests + class GoogleTranslateHandler: ''' This bot will translate any messages sent to it using google translate. diff --git a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py index bad4d83..5053e41 100644 --- a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py +++ b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py @@ -1,4 +1,5 @@ from unittest.mock import patch + from requests.exceptions import ConnectionError from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler diff --git a/zulip_bots/zulip_bots/bots/helloworld/helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/helloworld.py index 0839266..5265bd8 100644 --- a/zulip_bots/zulip_bots/bots/helloworld/helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/helloworld.py @@ -1,8 +1,10 @@ # See readme.md for instructions on running this code. from typing import Any, Dict + from zulip_bots.lib import BotHandler + class HelloWorldHandler: def usage(self) -> str: return ''' diff --git a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py index e65268f..442dcaf 100755 --- a/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py +++ b/zulip_bots/zulip_bots/bots/helloworld/test_helloworld.py @@ -1,5 +1,6 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestHelpBot(BotTestCase, DefaultTests): bot_name = "helloworld" # type: str diff --git a/zulip_bots/zulip_bots/bots/help/help.py b/zulip_bots/zulip_bots/bots/help/help.py index cd75cfc..727c06a 100644 --- a/zulip_bots/zulip_bots/bots/help/help.py +++ b/zulip_bots/zulip_bots/bots/help/help.py @@ -1,7 +1,9 @@ # See readme.md for instructions on running this code. from typing import Dict + from zulip_bots.lib import BotHandler + class HelpHandler: def usage(self) -> str: return ''' diff --git a/zulip_bots/zulip_bots/bots/help/test_help.py b/zulip_bots/zulip_bots/bots/help/test_help.py index d4bcce6..b5a1aa6 100755 --- a/zulip_bots/zulip_bots/bots/help/test_help.py +++ b/zulip_bots/zulip_bots/bots/help/test_help.py @@ -1,5 +1,6 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestHelpBot(BotTestCase, DefaultTests): bot_name = "help" diff --git a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py index 13f5829..35abf40 100644 --- a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py +++ b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py @@ -1,8 +1,9 @@ -import requests import logging import re +from typing import Any, Dict, List, Optional + +import requests -from typing import Any, Dict, Optional, List from zulip_bots.lib import BotHandler API_BASE_URL = "https://beta.idonethis.com/api/v2" diff --git a/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py b/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py index 847148f..5e81def 100644 --- a/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py +++ b/zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py @@ -2,6 +2,7 @@ from unittest.mock import patch from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestIDoneThisBot(BotTestCase, DefaultTests): bot_name = "idonethis" # type: str diff --git a/zulip_bots/zulip_bots/bots/incident/incident.py b/zulip_bots/zulip_bots/bots/incident/incident.py index 8ec1a97..25dc596 100644 --- a/zulip_bots/zulip_bots/bots/incident/incident.py +++ b/zulip_bots/zulip_bots/bots/incident/incident.py @@ -1,6 +1,7 @@ import json import re from typing import Any, Dict, Tuple + from zulip_bots.lib import BotHandler QUESTION = 'How should we handle this?' diff --git a/zulip_bots/zulip_bots/bots/incrementor/incrementor.py b/zulip_bots/zulip_bots/bots/incrementor/incrementor.py index 2346316..115f1b8 100644 --- a/zulip_bots/zulip_bots/bots/incrementor/incrementor.py +++ b/zulip_bots/zulip_bots/bots/incrementor/incrementor.py @@ -1,8 +1,10 @@ # See readme.md for instructions on running this code. from typing import Dict + from zulip_bots.lib import BotHandler, use_storage + class IncrementorHandler: META = { 'name': 'Incrementor', diff --git a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py index aa5f637..103f804 100644 --- a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py +++ b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py @@ -1,11 +1,7 @@ from unittest.mock import patch -from zulip_bots.test_lib import ( - get_bot_message_handler, - StubBotHandler, - DefaultTests, - BotTestCase, -) +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + class TestIncrementorBot(BotTestCase, DefaultTests): bot_name = "incrementor" diff --git a/zulip_bots/zulip_bots/bots/jira/jira.py b/zulip_bots/zulip_bots/bots/jira/jira.py index b59ad99..eefef4a 100644 --- a/zulip_bots/zulip_bots/bots/jira/jira.py +++ b/zulip_bots/zulip_bots/bots/jira/jira.py @@ -1,7 +1,9 @@ import base64 import re -import requests from typing import Any, Dict, Optional + +import requests + from zulip_bots.lib import BotHandler GET_REGEX = re.compile('get "(?P.+)"$') diff --git a/zulip_bots/zulip_bots/bots/jira/test_jira.py b/zulip_bots/zulip_bots/bots/jira/test_jira.py index 6bd021e..cc1d87b 100644 --- a/zulip_bots/zulip_bots/bots/jira/test_jira.py +++ b/zulip_bots/zulip_bots/bots/jira/test_jira.py @@ -1,5 +1,6 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestJiraBot(BotTestCase, DefaultTests): bot_name = 'jira' diff --git a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py index c046fb8..ffe1905 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/link_shortener.py @@ -1,9 +1,11 @@ import re +from typing import Any, Dict + import requests -from typing import Any, Dict from zulip_bots.lib import BotHandler + class LinkShortenerHandler: '''A Zulip bot that will shorten URLs ("links") in a conversation using the goo.gl URL shortener. diff --git a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py index ee00ab4..cc5dbb7 100644 --- a/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py +++ b/zulip_bots/zulip_bots/bots/link_shortener/test_link_shortener.py @@ -1,7 +1,7 @@ from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.test_lib import StubBotHandler + from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler class TestLinkShortenerBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/mention/mention.py b/zulip_bots/zulip_bots/bots/mention/mention.py index 166c794..c7153b8 100644 --- a/zulip_bots/zulip_bots/bots/mention/mention.py +++ b/zulip_bots/zulip_bots/bots/mention/mention.py @@ -1,9 +1,12 @@ # See readme.md for instructions on running this code. +from typing import Any, Dict, List + import requests -from typing import Any, List, Dict + from zulip_bots.lib import BotHandler + class MentionHandler: def initialize(self, bot_handler: BotHandler) -> None: self.config_info = bot_handler.get_config_info('mention') diff --git a/zulip_bots/zulip_bots/bots/mention/test_mention.py b/zulip_bots/zulip_bots/bots/mention/test_mention.py index 1aac508..02da176 100644 --- a/zulip_bots/zulip_bots/bots/mention/test_mention.py +++ b/zulip_bots/zulip_bots/bots/mention/test_mention.py @@ -1,7 +1,8 @@ -from zulip_bots.bots.mention.mention import MentionHandler from unittest.mock import patch -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.test_lib import StubBotHandler + +from zulip_bots.bots.mention.mention import MentionHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler + class TestMentionBot(BotTestCase, DefaultTests): bot_name = "mention" diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/game.py b/zulip_bots/zulip_bots/bots/merels/libraries/game.py index 1822d29..c146295 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/game.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/game.py @@ -9,8 +9,8 @@ import re from zulip_bots.game_handler import BadMoveException -from . import database -from . import mechanics +from . import database, mechanics + COMMAND_PATTERN = re.compile( "^(\\w*).*(\\d,\\d).*(\\d,\\d)|^(\\w+).*(\\d,\\d)") diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py index 1018d71..6322d9f 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/mechanics.py @@ -2,16 +2,14 @@ mechanisms as well as some functions for accessing the database. """ +from collections import Counter from math import sqrt -from collections import Counter - -from . import constants -from . import database -from . import game_data -from . import interface from zulip_bots.game_handler import BadMoveException +from . import constants, database, game_data, interface + + def is_in_grid(vertical_pos, horizontal_pos): """Checks whether the cell actually exists or not diff --git a/zulip_bots/zulip_bots/bots/merels/merels.py b/zulip_bots/zulip_bots/bots/merels/merels.py index 85d4e38..b27af59 100644 --- a/zulip_bots/zulip_bots/bots/merels/merels.py +++ b/zulip_bots/zulip_bots/bots/merels/merels.py @@ -1,12 +1,9 @@ -from typing import List, Any -from zulip_bots.bots.merels.libraries import ( - game, - mechanics, - database, - game_data -) +from typing import Any, List + +from zulip_bots.bots.merels.libraries import database, game, game_data, mechanics from zulip_bots.game_handler import GameAdapter, SamePlayerMove + class Storage: data = {} diff --git a/zulip_bots/zulip_bots/bots/merels/test/test_database.py b/zulip_bots/zulip_bots/bots/merels/test/test_database.py index c3b3768..45b5f2a 100644 --- a/zulip_bots/zulip_bots/bots/merels/test/test_database.py +++ b/zulip_bots/zulip_bots/bots/merels/test/test_database.py @@ -1,9 +1,10 @@ -from libraries import database -from libraries import game_data +from libraries import database, game_data + from zulip_bots.simple_lib import SimpleStorage from zulip_bots.test_lib import BotTestCase, DefaultTests + class DatabaseTest(BotTestCase, DefaultTests): bot_name = 'merels' diff --git a/zulip_bots/zulip_bots/bots/merels/test/test_game.py b/zulip_bots/zulip_bots/bots/merels/test/test_game.py index 35e2395..31b4164 100644 --- a/zulip_bots/zulip_bots/bots/merels/test/test_game.py +++ b/zulip_bots/zulip_bots/bots/merels/test/test_game.py @@ -1,9 +1,10 @@ import unittest -from libraries import game -from libraries import database -from zulip_bots.simple_lib import SimpleStorage +from libraries import database, game + from zulip_bots.game_handler import BadMoveException +from zulip_bots.simple_lib import SimpleStorage + class GameTest(unittest.TestCase): def setUp(self): diff --git a/zulip_bots/zulip_bots/bots/merels/test/test_mechanics.py b/zulip_bots/zulip_bots/bots/merels/test/test_mechanics.py index 6073b3b..7aa2385 100644 --- a/zulip_bots/zulip_bots/bots/merels/test/test_mechanics.py +++ b/zulip_bots/zulip_bots/bots/merels/test/test_mechanics.py @@ -1,9 +1,7 @@ import unittest -from libraries import database -from libraries import game_data -from libraries import interface -from libraries import mechanics +from libraries import database, game_data, interface, mechanics + from zulip_bots.simple_lib import SimpleStorage diff --git a/zulip_bots/zulip_bots/bots/merels/test_merels.py b/zulip_bots/zulip_bots/bots/merels/test_merels.py index f37d5fc..14faec5 100644 --- a/zulip_bots/zulip_bots/bots/merels/test_merels.py +++ b/zulip_bots/zulip_bots/bots/merels/test_merels.py @@ -1,8 +1,10 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.game_handler import GameInstance +from typing import Any, List, Tuple + from libraries.constants import EMPTY_BOARD -from typing import List, Tuple, Any +from zulip_bots.game_handler import GameInstance +from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestMerelsBot(BotTestCase, DefaultTests): bot_name = 'merels' diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/lib/parse.py b/zulip_bots/zulip_bots/bots/monkeytestit/lib/parse.py index b6487d6..28e75e3 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/lib/parse.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/lib/parse.py @@ -5,8 +5,7 @@ for extract.py from json.decoder import JSONDecodeError from typing import Text -from zulip_bots.bots.monkeytestit.lib import extract -from zulip_bots.bots.monkeytestit.lib import report +from zulip_bots.bots.monkeytestit.lib import extract, report def execute(message: Text, apikey: Text) -> Text: diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py b/zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py index 4e03af3..1c59ebd 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py @@ -1,7 +1,7 @@ """Used to mainly compose a decorated report for the user """ -from typing import Dict, Text, List +from typing import Dict, List, Text def compose(results: Dict) -> Text: diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/monkeytestit.py index 6474c31..9555e2b 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/monkeytestit.py @@ -1,8 +1,8 @@ import logging from typing import Dict -from zulip_bots.lib import BotHandler + from zulip_bots.bots.monkeytestit.lib import parse -from zulip_bots.lib import NoBotConfigException +from zulip_bots.lib import BotHandler, NoBotConfigException class MonkeyTestitBot: diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py index c4b53b7..921373e 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py @@ -1,8 +1,9 @@ +from importlib import import_module from unittest.mock import patch -from importlib import import_module from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestMonkeyTestitBot(BotTestCase, DefaultTests): bot_name = "monkeytestit" diff --git a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py index bc766c3..46e4e71 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/salesforce.py @@ -1,11 +1,13 @@ # See readme.md for instructions on running this code. -import simple_salesforce -from typing import Dict, Any, List -from zulip_bots.lib import BotHandler -import re import logging -from zulip_bots.bots.salesforce.utils import commands, object_types, link_query, default_query +import re +from typing import Any, Dict, List + +import simple_salesforce + +from zulip_bots.bots.salesforce.utils import commands, default_query, link_query, object_types +from zulip_bots.lib import BotHandler base_help_text = '''Salesforce bot This bot can do simple salesforce query requests diff --git a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py index ed4ca26..790ec2e 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py +++ b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py @@ -1,8 +1,10 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, read_bot_fixture_data -from simple_salesforce.exceptions import SalesforceAuthenticationFailed from contextlib import contextmanager -from unittest.mock import patch from typing import Any, Dict, Iterator +from unittest.mock import patch + +from simple_salesforce.exceptions import SalesforceAuthenticationFailed + +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, read_bot_fixture_data @contextmanager diff --git a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py index 9334439..40f5e99 100644 --- a/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py +++ b/zulip_bots/zulip_bots/bots/stack_overflow/stack_overflow.py @@ -1,7 +1,8 @@ -import requests import logging +from typing import Dict, Optional + +import requests -from typing import Optional, Dict from zulip_bots.lib import BotHandler # See readme.md for instructions on running this code. diff --git a/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py b/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py index 5904a07..06c8ae7 100755 --- a/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py +++ b/zulip_bots/zulip_bots/bots/stack_overflow/test_stack_overflow.py @@ -1,5 +1,6 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.request_test_lib import mock_request_exception +from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestStackoverflowBot(BotTestCase, DefaultTests): bot_name = "stack_overflow" diff --git a/zulip_bots/zulip_bots/bots/susi/susi.py b/zulip_bots/zulip_bots/bots/susi/susi.py index 317f8e3..cd85cbc 100644 --- a/zulip_bots/zulip_bots/bots/susi/susi.py +++ b/zulip_bots/zulip_bots/bots/susi/susi.py @@ -1,7 +1,10 @@ -import requests from typing import Dict + +import requests + from zulip_bots.lib import BotHandler + class SusiHandler: ''' Susi AI Bot diff --git a/zulip_bots/zulip_bots/bots/susi/test_susi.py b/zulip_bots/zulip_bots/bots/susi/test_susi.py index 30d62ad..6f60792 100644 --- a/zulip_bots/zulip_bots/bots/susi/test_susi.py +++ b/zulip_bots/zulip_bots/bots/susi/test_susi.py @@ -1,7 +1,5 @@ -from zulip_bots.test_lib import ( - BotTestCase, - DefaultTests, -) +from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestSusiBot(BotTestCase, DefaultTests): bot_name = "susi" diff --git a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py index 8d9f621..d3e9cae 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/test_tictactoe.py @@ -1,7 +1,7 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.game_handler import GameInstance +from typing import Any, List, Tuple -from typing import List, Tuple, Any +from zulip_bots.game_handler import GameInstance +from zulip_bots.test_lib import BotTestCase, DefaultTests class TestTicTacToeBot(BotTestCase, DefaultTests): diff --git a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py index 840e4b1..06447c5 100644 --- a/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py +++ b/zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py @@ -1,8 +1,8 @@ import copy import random +from typing import Any, List, Tuple -from typing import List, Any, Tuple -from zulip_bots.game_handler import GameAdapter, BadMoveException +from zulip_bots.game_handler import BadMoveException, GameAdapter # ------------------------------------- diff --git a/zulip_bots/zulip_bots/bots/trello/test_trello.py b/zulip_bots/zulip_bots/bots/trello/test_trello.py index 24817b6..f8c11c3 100644 --- a/zulip_bots/zulip_bots/bots/trello/test_trello.py +++ b/zulip_bots/zulip_bots/bots/trello/test_trello.py @@ -1,8 +1,7 @@ from unittest.mock import patch from zulip_bots.bots.trello.trello import TrelloHandler -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.test_lib import StubBotHandler +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler mock_config = { 'api_key': 'TEST', diff --git a/zulip_bots/zulip_bots/bots/trello/trello.py b/zulip_bots/zulip_bots/bots/trello/trello.py index 9a6bff9..b024e45 100644 --- a/zulip_bots/zulip_bots/bots/trello/trello.py +++ b/zulip_bots/zulip_bots/bots/trello/trello.py @@ -1,7 +1,9 @@ -from typing import Any, List, Dict -from zulip_bots.lib import BotHandler +from typing import Any, Dict, List + import requests +from zulip_bots.lib import BotHandler + supported_commands = [ ('help', 'Get the bot usage information.'), ('list-commands', 'Get information about the commands supported by the bot.'), diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py index 525afd4..7197401 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py @@ -1,27 +1,18 @@ -import json import html - +import json +from typing import Any, Dict, Optional, Tuple from unittest.mock import patch -from typing import Optional, Tuple, Any, Dict - -from zulip_bots.test_lib import ( - BotTestCase, - DefaultTests, - read_bot_fixture_data, - StubBotHandler, -) - -from zulip_bots.request_test_lib import ( - mock_request_exception, -) from zulip_bots.bots.trivia_quiz.trivia_quiz import ( - get_quiz_from_payload, fix_quotes, get_quiz_from_id, - update_quiz, + get_quiz_from_payload, handle_answer, + update_quiz, ) +from zulip_bots.request_test_lib import mock_request_exception +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, read_bot_fixture_data + class TestTriviaQuizBot(BotTestCase, DefaultTests): bot_name = "trivia_quiz" # type: str diff --git a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py index d78edb8..4703d2c 100644 --- a/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py +++ b/zulip_bots/zulip_bots/bots/trivia_quiz/trivia_quiz.py @@ -1,11 +1,14 @@ import html import json -import requests import random import re -from typing import Optional, Any, Dict, Tuple +from typing import Any, Dict, Optional, Tuple + +import requests + from zulip_bots.lib import BotHandler + class NotAvailableException(Exception): pass diff --git a/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py b/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py index fe91cf7..11ee27d 100644 --- a/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py +++ b/zulip_bots/zulip_bots/bots/twitpost/test_twitpost.py @@ -1,14 +1,9 @@ -from zulip_bots.test_lib import ( - StubBotHandler, - BotTestCase, - DefaultTests, - get_bot_message_handler, -) -from zulip_bots.test_file_utils import ( - read_bot_fixture_data, -) from unittest.mock import patch +from zulip_bots.test_file_utils import read_bot_fixture_data +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + + class TestTwitpostBot(BotTestCase, DefaultTests): bot_name = "twitpost" mock_config = {'consumer_key': 'abcdefghijklmnopqrstuvwxy', diff --git a/zulip_bots/zulip_bots/bots/twitpost/twitpost.py b/zulip_bots/zulip_bots/bots/twitpost/twitpost.py index fbbb16b..ab61a0d 100644 --- a/zulip_bots/zulip_bots/bots/twitpost/twitpost.py +++ b/zulip_bots/zulip_bots/bots/twitpost/twitpost.py @@ -1,7 +1,10 @@ -import tweepy from typing import Dict + +import tweepy + from zulip_bots.lib import BotHandler + class TwitpostBot: def usage(self) -> str: diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py index 1012d30..b91baae 100755 --- a/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/test_virtual_fs.py @@ -1,7 +1,9 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests -from zulip_bots.bots.virtual_fs.virtual_fs import sample_conversation from unittest.mock import patch +from zulip_bots.bots.virtual_fs.virtual_fs import sample_conversation +from zulip_bots.test_lib import BotTestCase, DefaultTests + + class TestVirtualFsBot(BotTestCase, DefaultTests): bot_name = "virtual_fs" help_txt = ('foo@example.com:\n\nThis bot implements a virtual file system for a stream.\n' diff --git a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py index 4bbccd4..85c0d2c 100644 --- a/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py +++ b/zulip_bots/zulip_bots/bots/virtual_fs/virtual_fs.py @@ -1,11 +1,12 @@ # See readme.md for instructions on running this code. -import re import os - +import re from typing import Any, Dict, List, Set, Tuple, Union + from zulip_bots.lib import BotHandler + class VirtualFsHandler: META = { 'name': 'VirtualFs', diff --git a/zulip_bots/zulip_bots/bots/weather/test_weather.py b/zulip_bots/zulip_bots/bots/weather/test_weather.py index aa0e695..fe1611c 100644 --- a/zulip_bots/zulip_bots/bots/weather/test_weather.py +++ b/zulip_bots/zulip_bots/bots/weather/test_weather.py @@ -1,7 +1,8 @@ +from typing import Optional from unittest.mock import patch + from zulip_bots.test_lib import BotTestCase, DefaultTests -from typing import Optional class TestWeatherBot(BotTestCase, DefaultTests): bot_name = "weather" diff --git a/zulip_bots/zulip_bots/bots/weather/weather.py b/zulip_bots/zulip_bots/bots/weather/weather.py index c2d5dad..9f08f76 100644 --- a/zulip_bots/zulip_bots/bots/weather/weather.py +++ b/zulip_bots/zulip_bots/bots/weather/weather.py @@ -1,7 +1,8 @@ # See readme.md for instructions on running this code. +from typing import Any, Dict + import requests -from typing import Any, Dict from zulip_bots.lib import BotHandler api_url = 'http://api.openweathermap.org/data/2.5/weather' diff --git a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py index 8c7df56..384d342 100755 --- a/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/test_wikipedia.py @@ -1,5 +1,6 @@ -from zulip_bots.test_lib import BotTestCase, DefaultTests from zulip_bots.request_test_lib import mock_request_exception +from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestWikipediaBot(BotTestCase, DefaultTests): bot_name = "wikipedia" diff --git a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py index 2f25f47..1524d09 100644 --- a/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py +++ b/zulip_bots/zulip_bots/bots/wikipedia/wikipedia.py @@ -1,6 +1,8 @@ -import requests import logging from typing import Dict + +import requests + from zulip_bots.lib import BotHandler # See readme.md for instructions on running this code. diff --git a/zulip_bots/zulip_bots/bots/witai/test_witai.py b/zulip_bots/zulip_bots/bots/witai/test_witai.py index 6248dcf..cd87518 100644 --- a/zulip_bots/zulip_bots/bots/witai/test_witai.py +++ b/zulip_bots/zulip_bots/bots/witai/test_witai.py @@ -1,6 +1,8 @@ +from typing import Any, Dict, Optional from unittest.mock import patch -from typing import Dict, Any, Optional -from zulip_bots.test_lib import BotTestCase, DefaultTests, get_bot_message_handler, StubBotHandler + +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + class TestWitaiBot(BotTestCase, DefaultTests): bot_name = 'witai' diff --git a/zulip_bots/zulip_bots/bots/witai/witai.py b/zulip_bots/zulip_bots/bots/witai/witai.py index 05a874a..30c7285 100644 --- a/zulip_bots/zulip_bots/bots/witai/witai.py +++ b/zulip_bots/zulip_bots/bots/witai/witai.py @@ -1,10 +1,13 @@ # See readme.md for instructions on running this code. -from typing import Dict, Any, Optional, Callable -from zulip_bots.lib import BotHandler -import wit import importlib.abc import importlib.util +from typing import Any, Callable, Dict, Optional + +import wit + +from zulip_bots.lib import BotHandler + class WitaiHandler: def usage(self) -> str: diff --git a/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py index 5ef5eb3..c3d7f53 100755 --- a/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/test_xkcd.py @@ -1,6 +1,8 @@ from unittest.mock import MagicMock, patch + from zulip_bots.test_lib import BotTestCase, DefaultTests + class TestXkcdBot(BotTestCase, DefaultTests): bot_name = "xkcd" diff --git a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py index 1cdb231..68587ef 100644 --- a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py @@ -1,9 +1,9 @@ -import random - import logging +import random +from typing import Dict, Optional + import requests -from typing import Dict, Optional from zulip_bots.lib import BotHandler XKCD_TEMPLATE_URL = 'https://xkcd.com/%s/info.0.json' diff --git a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py index 0b1689e..2db1e2b 100644 --- a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py @@ -1,7 +1,8 @@ +from typing import Optional + from zulip_bots.bots.yoda.yoda import ServiceUnavailableError from zulip_bots.test_lib import BotTestCase, DefaultTests -from typing import Optional class TestYodaBot(BotTestCase, DefaultTests): bot_name = "yoda" diff --git a/zulip_bots/zulip_bots/bots/yoda/yoda.py b/zulip_bots/zulip_bots/bots/yoda/yoda.py index 323777e..227b6ce 100644 --- a/zulip_bots/zulip_bots/bots/yoda/yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/yoda.py @@ -1,9 +1,10 @@ # See readme.md for instructions on running this code. import logging import ssl +from typing import Dict + import requests -from typing import Dict from zulip_bots.lib import BotHandler HELP_MESSAGE = ''' diff --git a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py index 13f69fa..8d55f11 100644 --- a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py +++ b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py @@ -1,8 +1,10 @@ -from unittest.mock import patch -from requests.exceptions import HTTPError, ConnectionError - -from zulip_bots.test_lib import StubBotHandler, BotTestCase, DefaultTests, get_bot_message_handler from typing import Dict +from unittest.mock import patch + +from requests.exceptions import ConnectionError, HTTPError + +from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, get_bot_message_handler + class TestYoutubeBot(BotTestCase, DefaultTests): bot_name = "youtube" diff --git a/zulip_bots/zulip_bots/bots/youtube/youtube.py b/zulip_bots/zulip_bots/bots/youtube/youtube.py index 3c354cf..219897e 100644 --- a/zulip_bots/zulip_bots/bots/youtube/youtube.py +++ b/zulip_bots/zulip_bots/bots/youtube/youtube.py @@ -1,8 +1,9 @@ -import requests import logging +from typing import Dict, List, Optional, Tuple, Union + +import requests +from requests.exceptions import ConnectionError, HTTPError -from requests.exceptions import HTTPError, ConnectionError -from typing import Dict, Union, List, Tuple, Optional from zulip_bots.lib import BotHandler commands_list = ('list', 'top', 'help') diff --git a/zulip_bots/zulip_bots/finder.py b/zulip_bots/zulip_bots/finder.py index 3b9f5be..8886971 100644 --- a/zulip_bots/zulip_bots/finder.py +++ b/zulip_bots/zulip_bots/finder.py @@ -2,8 +2,8 @@ import importlib import importlib.abc import importlib.util import os -from typing import Any, Optional, Text, Tuple from pathlib import Path +from typing import Any, Optional, Text, Tuple current_dir = os.path.dirname(os.path.abspath(__file__)) diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index 7da12a2..60351fd 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -1,10 +1,11 @@ import json -import re -import random import logging -from zulip_bots.lib import BotHandler +import random +import re from copy import deepcopy -from typing import Any, Dict, Tuple, List +from typing import Any, Dict, List, Tuple + +from zulip_bots.lib import BotHandler class BadMoveException(Exception): diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index b6fe334..ff2f4bb 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -2,15 +2,15 @@ import configparser import json import logging import os +import re import signal import sys import time -import re - - from contextlib import contextmanager -from typing import Any, Iterator, Optional, List, Dict, IO, Set, Text +from typing import IO, Any, Dict, Iterator, List, Optional, Set, Text + from typing_extensions import Protocol + from zulip import Client, ZulipError diff --git a/zulip_bots/zulip_bots/provision.py b/zulip_bots/zulip_bots/provision.py index ac84008..9848e01 100755 --- a/zulip_bots/zulip_bots/provision.py +++ b/zulip_bots/zulip_bots/provision.py @@ -1,13 +1,14 @@ #!/usr/bin/env python3 import argparse +import glob import logging import os -import sys import subprocess -import glob +import sys from typing import Iterator + def get_bot_paths() -> Iterator[str]: current_dir = os.path.dirname(os.path.abspath(__file__)) bots_dir = os.path.join(current_dir, "bots") diff --git a/zulip_bots/zulip_bots/request_test_lib.py b/zulip_bots/zulip_bots/request_test_lib.py index 1a7f7e2..becf2dc 100644 --- a/zulip_bots/zulip_bots/request_test_lib.py +++ b/zulip_bots/zulip_bots/request_test_lib.py @@ -1,10 +1,10 @@ import json -import requests - from contextlib import contextmanager +from typing import Any, Dict, List from unittest.mock import patch -from typing import Any, Dict, List +import requests + @contextmanager def mock_http_conversation(http_data: Dict[str, Any]) -> Any: diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index c67f591..cb6e3ec 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -1,20 +1,19 @@ #!/usr/bin/env python3 -import logging import argparse -import sys +import logging import os - -from zulip_bots.lib import ( - zulip_env_vars_are_present, - run_message_handler_for_bot, - NoBotConfigException, -) -from zulip_bots import finder -from zulip_bots.provision import provision_bot - +import sys from typing import Optional +from zulip_bots import finder +from zulip_bots.lib import ( + NoBotConfigException, + run_message_handler_for_bot, + zulip_env_vars_are_present, +) +from zulip_bots.provision import provision_bot + current_dir = os.path.dirname(os.path.abspath(__file__)) def parse_args() -> argparse.Namespace: diff --git a/zulip_bots/zulip_bots/simple_lib.py b/zulip_bots/zulip_bots/simple_lib.py index 96788a7..e772270 100644 --- a/zulip_bots/zulip_bots/simple_lib.py +++ b/zulip_bots/zulip_bots/simple_lib.py @@ -1,8 +1,9 @@ import configparser import sys +from uuid import uuid4 from zulip_bots.lib import BotIdentity -from uuid import uuid4 + class SimpleStorage: def __init__(self): diff --git a/zulip_bots/zulip_bots/terminal.py b/zulip_bots/zulip_bots/terminal.py index abc8be4..4678830 100644 --- a/zulip_bots/zulip_bots/terminal.py +++ b/zulip_bots/zulip_bots/terminal.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 +import argparse import os import sys -import argparse from zulip_bots.finder import import_module_from_source, resolve_bot_path from zulip_bots.simple_lib import MockMessageServer, TerminalBotHandler diff --git a/zulip_bots/zulip_bots/test_file_utils.py b/zulip_bots/zulip_bots/test_file_utils.py index 1fb04e4..81c6fc1 100644 --- a/zulip_bots/zulip_bots/test_file_utils.py +++ b/zulip_bots/zulip_bots/test_file_utils.py @@ -1,8 +1,6 @@ import json import os - from importlib import import_module - from typing import Any, Dict ''' diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 53e37cc..9138d6a 100755 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -1,27 +1,12 @@ import unittest +from typing import IO, Any, Dict, List, Optional, Tuple -from typing import List, Dict, Any, Tuple, Optional, IO - -from zulip_bots.custom_exceptions import ( - ConfigValidationError, -) - -from zulip_bots.request_test_lib import ( - mock_http_conversation, - mock_request_exception -) - -from zulip_bots.simple_lib import ( - SimpleStorage, - MockMessageServer, -) - -from zulip_bots.test_file_utils import ( - get_bot_message_handler, - read_bot_fixture_data, -) - +from zulip_bots.custom_exceptions import ConfigValidationError from zulip_bots.lib import BotIdentity +from zulip_bots.request_test_lib import mock_http_conversation, mock_request_exception +from zulip_bots.simple_lib import MockMessageServer, SimpleStorage +from zulip_bots.test_file_utils import get_bot_message_handler, read_bot_fixture_data + class StubBotHandler: def __init__(self) -> None: diff --git a/zulip_bots/zulip_bots/tests/test_finder.py b/zulip_bots/zulip_bots/tests/test_finder.py index b4a60bf..996dc0f 100644 --- a/zulip_bots/zulip_bots/tests/test_finder.py +++ b/zulip_bots/zulip_bots/tests/test_finder.py @@ -1,5 +1,5 @@ -from unittest import TestCase from pathlib import Path +from unittest import TestCase from zulip_bots import finder diff --git a/zulip_bots/zulip_bots/tests/test_lib.py b/zulip_bots/zulip_bots/tests/test_lib.py index c42c52a..382cb72 100644 --- a/zulip_bots/zulip_bots/tests/test_lib.py +++ b/zulip_bots/zulip_bots/tests/test_lib.py @@ -1,14 +1,15 @@ +import io from unittest import TestCase -from unittest.mock import MagicMock, patch, ANY, create_autospec +from unittest.mock import ANY, MagicMock, create_autospec, patch + from zulip_bots.lib import ( ExternalBotHandler, StateHandler, - run_message_handler_for_bot, extract_query_without_mention, - is_private_message_but_not_group_pm + is_private_message_but_not_group_pm, + run_message_handler_for_bot, ) -import io class FakeClient: def __init__(self, *args, **kwargs): diff --git a/zulip_bots/zulip_bots/tests/test_run.py b/zulip_bots/zulip_bots/tests/test_run.py index 973fa00..85c3d8b 100644 --- a/zulip_bots/zulip_bots/tests/test_run.py +++ b/zulip_bots/zulip_bots/tests/test_run.py @@ -1,15 +1,14 @@ #!/usr/bin/env python3 -from pathlib import Path import os import sys +import unittest +from pathlib import Path +from typing import Optional +from unittest import TestCase, mock +from unittest.mock import patch + import zulip_bots.run from zulip_bots.lib import extract_query_without_mention -import unittest -from typing import Optional -from unittest import TestCase - -from unittest import mock -from unittest.mock import patch class TestDefaultArguments(TestCase): diff --git a/zulip_botserver/setup.py b/zulip_botserver/setup.py index 755451c..d15aee4 100644 --- a/zulip_botserver/setup.py +++ b/zulip_botserver/setup.py @@ -53,7 +53,7 @@ setuptools_info = dict( ) try: - from setuptools import setup, find_packages + from setuptools import find_packages, setup package_info.update(setuptools_info) package_info['packages'] = find_packages(exclude=['tests']) diff --git a/zulip_botserver/tests/server_test_lib.py b/zulip_botserver/tests/server_test_lib.py index a90e02a..4e9d5bd 100644 --- a/zulip_botserver/tests/server_test_lib.py +++ b/zulip_botserver/tests/server_test_lib.py @@ -1,9 +1,10 @@ import configparser import json +from typing import Any, Dict, List, Optional +from unittest import TestCase + import mock -from typing import Any, List, Dict, Optional -from unittest import TestCase from zulip_botserver import server diff --git a/zulip_botserver/tests/test_server.py b/zulip_botserver/tests/test_server.py index 14784bf..86f1e72 100644 --- a/zulip_botserver/tests/test_server.py +++ b/zulip_botserver/tests/test_server.py @@ -1,18 +1,20 @@ -import mock -import os -from typing import Any, Dict -from zulip_bots.lib import BotHandler -import unittest -from .server_test_lib import BotServerTestCase import json +import os +import unittest from collections import OrderedDict from importlib import import_module -from types import ModuleType from pathlib import Path +from types import ModuleType +from typing import Any, Dict +import mock + +from zulip_bots.lib import BotHandler from zulip_botserver import server from zulip_botserver.input_parameters import parse_args +from .server_test_lib import BotServerTestCase + class BotServerTests(BotServerTestCase): class MockMessageHandler: diff --git a/zulip_botserver/zulip_botserver/server.py b/zulip_botserver/zulip_botserver/server.py index b7d85e7..3d208d0 100644 --- a/zulip_botserver/zulip_botserver/server.py +++ b/zulip_botserver/zulip_botserver/server.py @@ -1,19 +1,19 @@ #!/usr/bin/env python3 import configparser -import logging -import json -import os -import sys import importlib.abc import importlib.util - +import json +import logging +import os +import sys from collections import OrderedDict from configparser import MissingSectionHeaderError, NoOptionError -from flask import Flask, request from importlib import import_module -from typing import Any, Dict, List, Optional from types import ModuleType +from typing import Any, Dict, List, Optional + +from flask import Flask, request from werkzeug.exceptions import BadRequest, Unauthorized from zulip import Client