Skip to content

Commit

Permalink
Upgrade black (code formatter) to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Jan 28, 2021
1 parent d9ce076 commit a8d709b
Show file tree
Hide file tree
Showing 135 changed files with 1,339 additions and 886 deletions.
8 changes: 6 additions & 2 deletions integration_tests/env_variable_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

# Testing with Grid workspaces
SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN = "SLACK_SDK_TEST_GRID_ORG_ADMIN_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN = (
"SLACK_SDK_TEST_GRID_WORKSPACE_ADMIN_USER_TOKEN"
)
SLACK_SDK_TEST_GRID_WORKSPACE_USER_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_USER_TOKEN"
SLACK_SDK_TEST_GRID_WORKSPACE_BOT_TOKEN = "SLACK_SDK_TEST_GRID_WORKSPACE_BOT_TOKEN"
SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID = "SLACK_SDK_TEST_GRID_IDP_USERGROUP_ID"
Expand All @@ -27,4 +29,6 @@

# Webhook
SLACK_SDK_TEST_INCOMING_WEBHOOK_URL = "SLACK_SDK_TEST_INCOMING_WEBHOOK_URL"
SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME = "SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME"
SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME = (
"SLACK_SDK_TEST_INCOMING_WEBHOOK_CHANNEL_NAME"
)
3 changes: 1 addition & 2 deletions integration_tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ def is_not_specified() -> bool:

# python setup.py integration_tests --test-target=web/test_issue_560.py
test_target: str = sys.argv[1] # e.g., web/test_issue_560.py
return not test_target or \
not filepath.endswith(test_target)
return not test_target or not filepath.endswith(test_target)
12 changes: 9 additions & 3 deletions integration_tests/rtm/test_issue_530.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ def tearDown(self):

def test_issue_530(self):
try:
rtm_client = RTMClient(token="I am not a token", run_async=False, loop=asyncio.new_event_loop())
rtm_client = RTMClient(
token="I am not a token", run_async=False, loop=asyncio.new_event_loop()
)
rtm_client.start()
self.fail("Raising an error here was expected")
except Exception as e:
self.assertEqual(
"The request to the Slack API failed.\n"
"The server responded with: {'ok': False, 'error': 'invalid_auth'}", str(e))
"The server responded with: {'ok': False, 'error': 'invalid_auth'}",
str(e),
)
finally:
if not rtm_client._stopped:
rtm_client.stop()
Expand All @@ -42,7 +46,9 @@ async def test_issue_530_async(self):
except Exception as e:
self.assertEqual(
"The request to the Slack API failed.\n"
"The server responded with: {'ok': False, 'error': 'invalid_auth'}", str(e))
"The server responded with: {'ok': False, 'error': 'invalid_auth'}",
str(e),
)
finally:
if not rtm_client._stopped:
rtm_client.stop()
Expand Down
19 changes: 12 additions & 7 deletions integration_tests/rtm/test_issue_558.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import pytest

from integration_tests.env_variable_names import \
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN, \
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID
from integration_tests.env_variable_names import (
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN,
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID,
)
from integration_tests.helpers import async_test, is_not_specified
from slack_sdk.rtm import RTMClient
from slack_sdk.web import WebClient
Expand Down Expand Up @@ -46,8 +47,8 @@ async def process_reactions(**payload):
self.reaction_count += 1

rtm = RTMClient(token=self.bot_token, run_async=True)
RTMClient.on(event='message', callback=process_messages)
RTMClient.on(event='reaction_added', callback=process_reactions)
RTMClient.on(event="message", callback=process_messages)
RTMClient.on(event="reaction_added", callback=process_reactions)

web_client = WebClient(token=self.bot_token, run_async=True)
message = await web_client.chat_postMessage(channel=channel_id, text=text)
Expand All @@ -60,7 +61,9 @@ async def process_reactions(**payload):
await asyncio.sleep(3)

try:
first_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="eyes")
first_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="eyes"
)
self.assertFalse("error" in first_reaction)
await asyncio.sleep(2)

Expand All @@ -69,7 +72,9 @@ async def process_reactions(**payload):
# used to start blocking here

# This reaction_add event won't be handled due to a bug
second_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="tada")
second_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="tada"
)
self.assertFalse("error" in second_reaction)
await asyncio.sleep(2)

Expand Down
32 changes: 22 additions & 10 deletions integration_tests/rtm/test_issue_569.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import psutil
import pytest

from integration_tests.env_variable_names import \
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN, \
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID
from integration_tests.env_variable_names import (
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN,
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID,
)
from integration_tests.helpers import async_test, is_not_specified
from slack_sdk.rtm import RTMClient
from slack_sdk.web import WebClient
Expand All @@ -31,6 +32,7 @@ def setUp(self):
self.bot_token = os.environ[SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN]

if not hasattr(self, "cpu_monitor") or not TestRTMClient.cpu_monitor.is_alive():

def run_cpu_monitor(self):
self.logger.debug("Starting CPU monitor in another thread...")
TestRTMClient.cpu_usage = 0
Expand All @@ -41,7 +43,9 @@ def run_cpu_monitor(self):
if current_cpu_usage > TestRTMClient.cpu_usage:
TestRTMClient.cpu_usage = current_cpu_usage

TestRTMClient.cpu_monitor = threading.Thread(target=run_cpu_monitor, args=[self])
TestRTMClient.cpu_monitor = threading.Thread(
target=run_cpu_monitor, args=[self]
)
TestRTMClient.cpu_monitor.setDaemon(True)
TestRTMClient.cpu_monitor.start()

Expand All @@ -55,9 +59,13 @@ def tearDown(self):
if hasattr(self, "rtm_client") and not self.rtm_client._stopped:
self.rtm_client.stop()

@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate_limited errors")
@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate_limited errors"
)
def test_cpu_usage(self):
self.rtm_client = RTMClient(token=self.bot_token, run_async=False, loop=asyncio.new_event_loop())
self.rtm_client = RTMClient(
token=self.bot_token, run_async=False, loop=asyncio.new_event_loop()
)
self.web_client = WebClient(token=self.bot_token)

self.call_count = 0
Expand All @@ -73,7 +81,7 @@ def send_reply(**payload):
for i in range(0, 3):
new_message = web_client.chat_postMessage(
channel=event["channel"],
text=f"Current CPU usage: {TestRTMClient.cpu_usage} % (test_cpu_usage)"
text=f"Current CPU usage: {TestRTMClient.cpu_usage} % (test_cpu_usage)",
)
self.logger.debug(new_message)
self.call_count += 1
Expand All @@ -89,7 +97,9 @@ def connect():
time.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_cpu_usage)"
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=text)
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=text
)
self.assertFalse("error" in new_message)

time.sleep(5)
Expand Down Expand Up @@ -119,7 +129,7 @@ async def send_reply_async(**payload):
for i in range(0, 3):
new_message = await web_client.chat_postMessage(
channel=event["channel"],
text=f"Current CPU usage: {TestRTMClient.cpu_usage} % (test_cpu_usage_async)"
text=f"Current CPU usage: {TestRTMClient.cpu_usage} % (test_cpu_usage_async)",
)
self.logger.debug(new_message)
self.call_count += 1
Expand All @@ -130,7 +140,9 @@ async def send_reply_async(**payload):
await asyncio.sleep(5)

text = "This message was sent by <https://slack.dev/python-slackclient/|python-slackclient>! (test_cpu_usage_async)"
new_message = await self.web_client.chat_postMessage(channel=self.channel_id, text=text)
new_message = await self.web_client.chat_postMessage(
channel=self.channel_id, text=text
)
self.assertFalse("error" in new_message)

await asyncio.sleep(5)
Expand Down
17 changes: 11 additions & 6 deletions integration_tests/rtm/test_issue_605.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import pytest

from integration_tests.env_variable_names import \
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN, \
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID
from integration_tests.env_variable_names import (
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN,
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID,
)
from integration_tests.helpers import is_not_specified
from slack_sdk.rtm import RTMClient
from slack_sdk.web import WebClient
Expand All @@ -31,7 +32,9 @@ def tearDown(self):
# Reset the decorators by @RTMClient.run_on
RTMClient._callbacks = collections.defaultdict(list)

@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate_limited errors")
@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate_limited errors"
)
def test_issue_605(self):
self.text = "This message was sent to verify issue #605"
self.called = False
Expand All @@ -57,13 +60,15 @@ def connect():
token=self.bot_token,
run_async=False,
)
new_message = self.web_client.chat_postMessage(channel=self.channel_id, text=self.text)
new_message = self.web_client.chat_postMessage(
channel=self.channel_id, text=self.text
)
self.assertFalse("error" in new_message)

time.sleep(5)
self.assertTrue(self.called)
finally:
t.join(.3)
t.join(0.3)

# --- a/slack/rtm/client.py
# +++ b/slack/rtm/client.py
Expand Down
36 changes: 25 additions & 11 deletions integration_tests/rtm/test_issue_611.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import pytest

from integration_tests.env_variable_names import \
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN, \
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID
from integration_tests.env_variable_names import (
SLACK_SDK_TEST_CLASSIC_APP_BOT_TOKEN,
SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID,
)
from integration_tests.helpers import async_test, is_not_specified
from slack_sdk.rtm import RTMClient
from slack_sdk.web import WebClient
Expand All @@ -28,7 +29,9 @@ def tearDown(self):
# Reset the decorators by @RTMClient.run_on
RTMClient._callbacks = collections.defaultdict(list)

@pytest.mark.skipif(condition=is_not_specified(), reason="To avoid rate limited errors")
@pytest.mark.skipif(
condition=is_not_specified(), reason="To avoid rate limited errors"
)
@async_test
async def test_issue_611(self):
channel_id = os.environ[SLACK_SDK_TEST_RTM_TEST_CHANNEL_ID]
Expand All @@ -38,19 +41,24 @@ async def test_issue_611(self):

async def process_messages(**payload):
self.logger.info(payload)
if "subtype" in payload["data"] and payload["data"]["subtype"] == "message_replied":
if (
"subtype" in payload["data"]
and payload["data"]["subtype"] == "message_replied"
):
return # skip

self.message_count += 1
raise Exception("something is wrong!") # This causes the termination of the process
raise Exception(
"something is wrong!"
) # This causes the termination of the process

async def process_reactions(**payload):
self.logger.info(payload)
self.reaction_count += 1

rtm = RTMClient(token=self.bot_token, run_async=True)
RTMClient.on(event='message', callback=process_messages)
RTMClient.on(event='reaction_added', callback=process_reactions)
RTMClient.on(event="message", callback=process_messages)
RTMClient.on(event="reaction_added", callback=process_reactions)

web_client = WebClient(token=self.bot_token, run_async=True)
message = await web_client.chat_postMessage(channel=channel_id, text=text)
Expand All @@ -64,15 +72,21 @@ async def process_reactions(**payload):
try:
await asyncio.sleep(3)

first_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="eyes")
first_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="eyes"
)
self.assertFalse("error" in first_reaction)
await asyncio.sleep(2)

should_be_ignored = await web_client.chat_postMessage(channel=channel_id, text="Hello?", thread_ts=ts)
should_be_ignored = await web_client.chat_postMessage(
channel=channel_id, text="Hello?", thread_ts=ts
)
self.assertFalse("error" in should_be_ignored)
await asyncio.sleep(2)

second_reaction = await web_client.reactions_add(channel=channel_id, timestamp=ts, name="tada")
second_reaction = await web_client.reactions_add(
channel=channel_id, timestamp=ts, name="tada"
)
self.assertFalse("error" in second_reaction)
await asyncio.sleep(2)

Expand Down
Loading

0 comments on commit a8d709b

Please sign in to comment.