aboutsummaryrefslogtreecommitdiffstats
path: root/_pytest
diff options
context:
space:
mode:
Diffstat (limited to '_pytest')
-rw-r--r--_pytest/conftest.py58
-rw-r--r--_pytest/test_command_reply.py17
-rw-r--r--_pytest/test_eventrouter.py4
-rw-r--r--_pytest/test_everything.py2
-rw-r--r--_pytest/test_formatted_name.py387
-rw-r--r--_pytest/test_formatting.py34
-rw-r--r--_pytest/test_linkifytext.py91
-rw-r--r--_pytest/test_presencechange.py24
-rw-r--r--_pytest/test_process_message.py64
-rw-r--r--_pytest/test_processreply.py12
-rw-r--r--_pytest/test_processsubteamcreated.py4
-rw-r--r--_pytest/test_processsubteamupdated.py12
-rw-r--r--_pytest/test_processteamjoin.py6
-rw-r--r--_pytest/test_sendmessage.py12
-rw-r--r--_pytest/test_thread.py26
-rw-r--r--_pytest/test_topic_command.py52
-rw-r--r--_pytest/test_unfurl.py325
-rw-r--r--_pytest/test_unwrap_attachments.py779
-rw-r--r--_pytest/test_utf8_helpers.py43
19 files changed, 1110 insertions, 842 deletions
diff --git a/_pytest/conftest.py b/_pytest/conftest.py
index 1ad2310..b0eb082 100644
--- a/_pytest/conftest.py
+++ b/_pytest/conftest.py
@@ -14,119 +14,153 @@ sys.path.append(".")
import wee_slack
from wee_slack import EventRouter, SlackRequest, initiate_connection
+
class fakewebsocket(object):
def __init__(self):
self.returndata = []
self.sentdata = []
+
def add(self, data):
- self.returndata.append(json.dumps(data).encode('utf-8'))
+ self.returndata.append(json.dumps(data).encode("utf-8"))
+
def recv(self):
- return self.recv_data()[1].decode('utf-8')
+ return self.recv_data()[1].decode("utf-8")
+
def recv_data(self, control_frame=False):
if self.returndata:
return ABNF.OPCODE_TEXT, self.returndata.pop(0)
else:
raise ssl.SSLWantReadError()
+
def send(self, data):
self.sentdata.append(data)
+
@pytest.fixture
def mock_websocket():
return fakewebsocket()
+
@pytest.fixture
def realish_eventrouter(mock_websocket, mock_weechat):
e = EventRouter()
wee_slack.EVENTROUTER = e
- context = e.store_context(initiate_connection('xoxs-token'))
- with open('_pytest/data/http/rtm.start.json') as rtmstartfile:
+ context = e.store_context(initiate_connection("xoxs-token"))
+ with open("_pytest/data/http/rtm.start.json") as rtmstartfile:
if sys.version_info.major == 2:
- rtmstartdata = rtmstartfile.read().decode('utf-8')
+ rtmstartdata = rtmstartfile.read().decode("utf-8")
else:
rtmstartdata = rtmstartfile.read()
- e.receive_httprequest_callback(context, '', 0, rtmstartdata, '')
+ e.receive_httprequest_callback(context, "", 0, rtmstartdata, "")
while len(e.queue):
e.handle_next()
for team in e.teams.values():
team.ws = mock_websocket
return e
+
@pytest.fixture
def team(realish_eventrouter):
return next(iter(realish_eventrouter.teams.values()))
+
@pytest.fixture
def channel_general(team):
- return team.channels[team.get_channel_map()['#general']]
+ return team.channels[team.get_channel_map()["#general"]]
+
@pytest.fixture
def channel_private(team):
- return team.channels[team.get_channel_map()['&some-private-channel']]
+ return team.channels[team.get_channel_map()["&some-private-channel"]]
+
@pytest.fixture
def channel_dm(team):
- return team.channels[team.get_channel_map()['alice']]
+ return team.channels[team.get_channel_map()["alice"]]
+
@pytest.fixture
def channel_mpdm(team):
- return team.channels[team.get_channel_map()['CharlesTestuser,alice']]
+ return team.channels[team.get_channel_map()["CharlesTestuser,alice"]]
+
@pytest.fixture
def user_alice(team):
- return team.users[team.get_username_map()['alice']]
+ return team.users[team.get_username_map()["alice"]]
-class FakeWeechat():
+
+class FakeWeechat:
"""
this is the thing that acts as "w." everywhere..
basically mock out all of the weechat calls here i guess
"""
+
WEECHAT_RC_ERROR = 0
WEECHAT_RC_OK = 1
WEECHAT_RC_OK_EAT = 2
+
def __init__(self):
self.config = {}
+
def prnt(*args):
output = "("
for arg in args:
if arg != None:
output += "{}, ".format(arg)
print("w.prnt {}".format(output))
+
def hdata_get(*args):
return "0x000001"
+
def hdata_integer(*args):
return 1
+
def hdata_pointer(*args):
return "0x000002"
+
def hdata_time(*args):
return "1355517519"
+
def hdata_string(*args):
return "testuser"
+
def buffer_new(*args):
return "0x" + "".join(random.choice(string.digits) for _ in range(8))
+
def prefix(self, type):
return ""
+
def config_get_plugin(self, key):
return self.config.get(key, "")
+
def config_get(self, key):
return ""
+
def config_integer(self, key):
return 1000
+
def config_set_plugin(self, key, value):
self.config[key] = value
+
def config_string(self, key):
return ""
+
def color(self, name):
return "<[color {}]>".format(name)
+
def info_get(self, info_name, arguments):
if info_name == "color_rgb2term":
return arguments
else:
return ""
+
def __getattr__(self, name):
def method(*args):
pass
+
return method
+
@pytest.fixture
def mock_weechat():
wee_slack.w = FakeWeechat()
diff --git a/_pytest/test_command_reply.py b/_pytest/test_command_reply.py
index a674d86..f78e0c7 100644
--- a/_pytest/test_command_reply.py
+++ b/_pytest/test_command_reply.py
@@ -4,13 +4,16 @@ import json
from wee_slack import SlackTS, command_reply
-parent_ts = SlackTS('1485975824.000004')
-child_ts = SlackTS('1485975835.000005')
+parent_ts = SlackTS("1485975824.000004")
+child_ts = SlackTS("1485975835.000005")
-def test_replying_to_child_should_use_parent_ts(realish_eventrouter, team, channel_general):
+
+def test_replying_to_child_should_use_parent_ts(
+ realish_eventrouter, team, channel_general
+):
datafiles = [
- '_pytest/data/websocket/1485975824.48-message.json',
- '_pytest/data/websocket/1485975836.23-message.json'
+ "_pytest/data/websocket/1485975824.48-message.json",
+ "_pytest/data/websocket/1485975836.23-message.json",
]
for datafile in datafiles:
data = json.loads(open(datafile).read())
@@ -19,7 +22,7 @@ def test_replying_to_child_should_use_parent_ts(realish_eventrouter, team, chann
realish_eventrouter.handle_next()
child_hash = channel_general.hashed_messages[child_ts]
- command_reply(None, channel_general.channel_buffer, '${} test'.format(child_hash))
+ command_reply(None, channel_general.channel_buffer, "${} test".format(child_hash))
sent = json.loads(team.ws.sentdata[0])
- assert sent['thread_ts'] == parent_ts
+ assert sent["thread_ts"] == parent_ts
diff --git a/_pytest/test_eventrouter.py b/_pytest/test_eventrouter.py
index de267c1..5420d5a 100644
--- a/_pytest/test_eventrouter.py
+++ b/_pytest/test_eventrouter.py
@@ -13,7 +13,7 @@ def test_EventRouter(mock_weechat):
# Handling an event removes from the queue.
e = EventRouter()
# Create a function to test we are called
- e.proc['testfunc'] = lambda json, eventrouter, team, channel, metadata: json
+ e.proc["testfunc"] = lambda json, eventrouter, team, channel, metadata: json
e.receive({"type": "testfunc"})
e.handle_next()
assert len(e.queue) == 0
@@ -21,7 +21,7 @@ def test_EventRouter(mock_weechat):
# Handling a local event removes from the queue.
e = EventRouter()
# Create a function to test we are called
- e.proc['local_testfunc'] = lambda json, eventrouter, team, channel, metadata: json
+ e.proc["local_testfunc"] = lambda json, eventrouter, team, channel, metadata: json
e.receive({"type": "local_testfunc"})
e.handle_next()
assert len(e.queue) == 0
diff --git a/_pytest/test_everything.py b/_pytest/test_everything.py
index ed045ae..282c89e 100644
--- a/_pytest/test_everything.py
+++ b/_pytest/test_everything.py
@@ -8,7 +8,7 @@ def test_everything(realish_eventrouter, team):
datafiles = glob.glob("_pytest/data/websocket/*.json")
for fname in sorted(datafiles):
- data = json.loads(open(fname, 'r').read())
+ data = json.loads(open(fname, "r").read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
diff --git a/_pytest/test_formatted_name.py b/_pytest/test_formatted_name.py
index 5383b63..0dd2ee3 100644
--- a/_pytest/test_formatted_name.py
+++ b/_pytest/test_formatted_name.py
@@ -4,198 +4,205 @@ import pytest
import wee_slack
-@pytest.mark.parametrize('case', (
- {
- "type": "channel",
- "style": "default",
- "typing": False,
- "present": False,
- "name": "#general"
- },
- {
- "type": "channel",
- "style": "default",
- "typing": True,
- "present": True,
- "name": "#general"
- },
- {
- "type": "channel",
- "style": "long_default",
- "typing": False,
- "present": False,
- "name": "slack.weeslacktest.#general"
- },
- {
- "type": "channel",
- "style": "long_default",
- "typing": True,
- "present": True,
- "name": "slack.weeslacktest.#general"
- },
- {
- "type": "channel",
- "style": "sidebar",
- "typing": False,
- "present": False,
- "name": "#general"
- },
- {
- "type": "channel",
- "style": "sidebar",
- "typing": True,
- "present": True,
- "name": ">general"
- },
- {
- "type": "private",
- "style": "default",
- "typing": False,
- "present": False,
- "name": "&some-private-channel"
- },
- {
- "type": "private",
- "style": "default",
- "typing": True,
- "present": True,
- "name": "&some-private-channel"
- },
- {
- "type": "private",
- "style": "long_default",
- "typing": False,
- "present": False,
- "name": "slack.weeslacktest.&some-private-channel"
- },
- {
- "type": "private",
- "style": "long_default",
- "typing": True,
- "present": True,
- "name": "slack.weeslacktest.&some-private-channel"
- },
- {
- "type": "private",
- "style": "sidebar",
- "typing": False,
- "present": False,
- "name": "&some-private-channel"
- },
- {
- "type": "private",
- "style": "sidebar",
- "typing": True,
- "present": True,
- "name": ">some-private-channel"
- },
- {
- "type": "dm",
- "style": "default",
- "typing": False,
- "present": False,
- "name": "alice"
- },
- {
- "type": "dm",
- "style": "default",
- "typing": True,
- "present": True,
- "name": "alice"
- },
- {
- "type": "dm",
- "style": "long_default",
- "typing": False,
- "present": False,
- "name": "slack.weeslacktest.alice"
- },
- {
- "type": "dm",
- "style": "long_default",
- "typing": True,
- "present": True,
- "name": "slack.weeslacktest.alice"
- },
- {
- "type": "dm",
- "style": "sidebar",
- "typing": False,
- "present": False,
- "name": " alice"
- },
- {
- "type": "dm",
- "style": "sidebar",
- "typing": False,
- "present": True,
- "name": "+alice"
- },
- {
- "type": "dm",
- "style": "sidebar",
- "typing": True,
- "present": False,
- "name": ">alice"
- },
- {
- "type": "dm",
- "style": "sidebar",
- "typing": True,
- "present": True,
- "name": ">alice"
- },
- {
- "type": "mpdm",
- "style": "default",
- "typing": False,
- "present": False,
- "name": "CharlesTestuser,alice"
- },
- {
- "type": "mpdm",
- "style": "default",
- "typing": True,
- "present": True,
- "name": "CharlesTestuser,alice"
- },
- {
- "type": "mpdm",
- "style": "long_default",
- "typing": False,
- "present": False,
- "name": "slack.weeslacktest.CharlesTestuser,alice"
- },
- {
- "type": "mpdm",
- "style": "long_default",
- "typing": True,
- "present": True,
- "name": "slack.weeslacktest.CharlesTestuser,alice"
- },
- {
- "type": "mpdm",
- "style": "sidebar",
- "typing": False,
- "present": False,
- "name": "@CharlesTestuser,alice"
- },
- {
- "type": "mpdm",
- "style": "sidebar",
- "typing": True,
- "present": True,
- "name": ">CharlesTestuser,alice"
- },
-))
-def test_formatted_name(case, channel_general, channel_private, channel_dm, channel_mpdm):
+@pytest.mark.parametrize(
+ "case",
+ (
+ {
+ "type": "channel",
+ "style": "default",
+ "typing": False,
+ "present": False,
+ "name": "#general",
+ },
+ {
+ "type": "channel",
+ "style": "default",
+ "typing": True,
+ "present": True,
+ "name": "#general",
+ },
+ {
+ "type": "channel",
+ "style": "long_default",
+ "typing": False,
+ "present": False,
+ "name": "slack.weeslacktest.#general",
+ },
+ {
+ "type": "channel",
+ "style": "long_default",
+ "typing": True,
+ "present": True,
+ "name": "slack.weeslacktest.#general",
+ },
+ {
+ "type": "channel",
+ "style": "sidebar",
+ "typing": False,
+ "present": False,
+ "name": "#general",
+ },
+ {
+ "type": "channel",
+ "style": "sidebar",
+ "typing": True,
+ "present": True,
+ "name": ">general",
+ },
+ {
+ "type": "private",
+ "style": "default",
+ "typing": False,
+ "present": False,
+ "name": "&some-private-channel",
+ },
+ {
+ "type": "private",
+ "style": "default",
+ "typing": True,
+ "present": True,
+ "name": "&some-private-channel",
+ },
+ {
+ "type": "private",
+ "style": "long_default",
+ "typing": False,
+ "present": False,
+ "name": "slack.weeslacktest.&some-private-channel",
+ },
+ {
+ "type": "private",
+ "style": "long_default",
+ "typing": True,
+ "present": True,
+ "name": "slack.weeslacktest.&some-private-channel",
+ },
+ {
+ "type": "private",
+ "style": "sidebar",
+ "typing": False,
+ "present": False,
+ "name": "&some-private-channel",
+ },
+ {
+ "type": "private",
+ "style": "sidebar",
+ "typing": True,
+ "present": True,
+ "name": ">some-private-channel",
+ },
+ {
+ "type": "dm",
+ "style": "default",
+ "typing": False,
+ "present": False,
+ "name": "alice",
+ },
+ {
+ "type": "dm",
+ "style": "default",
+ "typing": True,
+ "present": True,
+ "name": "alice",
+ },
+ {
+ "type": "dm",
+ "style": "long_default",
+ "typing": False,
+ "present": False,
+ "name": "slack.weeslacktest.alice",
+ },
+ {
+ "type": "dm",
+ "style": "long_default",
+ "typing": True,
+ "present": True,
+ "name": "slack.weeslacktest.alice",
+ },
+ {
+ "type": "dm",
+ "style": "sidebar",
+ "typing": False,
+ "present": False,
+ "name": " alice",
+ },
+ {
+ "type": "dm",
+ "style": "sidebar",
+ "typing": False,
+ "present": True,
+ "name": "+alice",
+ },
+ {
+ "type": "dm",
+ "style": "sidebar",
+ "typing": True,
+ "present": False,
+ "name": ">alice",
+ },
+ {
+ "type": "dm",
+ "style": "sidebar",
+ "typing": True,
+ "present": True,
+ "name": ">alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "default",
+ "typing": False,
+ "present": False,
+ "name": "CharlesTestuser,alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "default",
+ "typing": True,
+ "present": True,
+ "name": "CharlesTestuser,alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "long_default",
+ "typing": False,
+ "present": False,
+ "name": "slack.weeslacktest.CharlesTestuser,alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "long_default",
+ "typing": True,
+ "present": True,
+ "name": "slack.weeslacktest.CharlesTestuser,alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "sidebar",
+ "typing": False,
+ "present": False,
+ "name": "@CharlesTestuser,alice",
+ },
+ {
+ "type": "mpdm",
+ "style": "sidebar",
+ "typing": True,
+ "present": True,
+ "name": ">CharlesTestuser,alice",
+ },
+ ),
+)
+def test_formatted_name(
+ case, channel_general, channel_private, channel_dm, channel_mpdm
+):
wee_slack.config.channel_name_typing_indicator = True
wee_slack.config.show_buflist_presence = True
channels = {
- "channel": channel_general,
- "private": channel_private,
- "dm": channel_dm,
- "mpdm": channel_mpdm,
+ "channel": channel_general,
+ "private": channel_private,
+ "dm": channel_dm,
+ "mpdm": channel_mpdm,
}
- name = channels[case["type"]].formatted_name(case["style"], case["typing"], case["present"])
+ name = channels[case["type"]].formatted_name(
+ case["style"], case["typing"], case["present"]
+ )
assert name == case["name"]
diff --git a/_pytest/test_formatting.py b/_pytest/test_formatting.py
index 4f6daa2..e88c4af 100644
--- a/_pytest/test_formatting.py
+++ b/_pytest/test_formatting.py
@@ -6,28 +6,34 @@ import re
import wee_slack
-@pytest.mark.parametrize("text", [
- """
+@pytest.mark.parametrize(
+ "text",
+ [
+ """
* an item
* another item
""",
- "* Run this command: `find . -name '*.exe'`",
-])
+ "* Run this command: `find . -name '*.exe'`",
+ ],
+)
def test_does_not_format(realish_eventrouter, text):
assert wee_slack.render_formatting(text) == text
-@pytest.mark.parametrize("text", [
- "`hello *bar*`",
- "`*`",
- "`* *`",
- "`* * *`",
- "`* * * *`",
- "`* * * * *`",
- "`* * * * * *`",
-])
+@pytest.mark.parametrize(
+ "text",
+ [
+ "`hello *bar*`",
+ "`*`",
+ "`* *`",
+ "`* * *`",
+ "`* * * *`",
+ "`* * * * *`",
+ "`* * * * * *`",
+ ],
+)
def test_preserves_format_chars_in_code(realish_eventrouter, text):
formatted_text = wee_slack.render_formatting(text)
# TODO: wee-slack erroneously inserts formatting in code blocks
- formatted_text = re.sub(r'<\[color .*?\]>', '', formatted_text)
+ formatted_text = re.sub(r"<\[color .*?\]>", "", formatted_text)
assert formatted_text == text
diff --git a/_pytest/test_linkifytext.py b/_pytest/test_linkifytext.py
index 4f9cd3b..60bf923 100644
--- a/_pytest/test_linkifytext.py
+++ b/_pytest/test_linkifytext.py
@@ -8,86 +8,103 @@ from wee_slack import linkify_text
def test_linkifytext_does_partial_html_entity_encoding(team):
- text = linkify_text('& < > \' "', team)
+ text = linkify_text("& < > ' \"", team)
+
+ assert text == "&amp; &lt; &gt; ' \""
- assert text == '&amp; &lt; &gt; \' "'
def test_linkifytext_names_with_paranthesis(team):
- text = linkify_text('@JohnDoe(jdoe): my test message', team)
+ text = linkify_text("@JohnDoe(jdoe): my test message", team)
+
+ assert text == "@JohnDoe(jdoe): my test message"
- assert text == '@JohnDoe(jdoe): my test message'
def test_linkifytext_names_with_accents(team):
- text = linkify_text('@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message', team)
+ text = linkify_text("@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message", team)
+
+ assert text == "@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message"
- assert text == '@ÁrvíztűrőTükörfúrógép(atukorfurogep): my test message'
def test_linkifytext_formatting_characters(team):
- text = linkify_text('\x02\x1Dmy test message\x1D\x02', team)
+ text = linkify_text("\x02\x1Dmy test message\x1D\x02", team)
+
+ assert text == "*_my test message_*"
- assert text == '*_my test message_*'
def test_linkifytext_with_many_paranthesis(team):
- text = linkify_text('@k(o(v)a)())s: my(( test) message', team)
+ text = linkify_text("@k(o(v)a)())s: my(( test) message", team)
+
+ assert text == "@k(o(v)a)())s: my(( test) message"
- assert text == '@k(o(v)a)())s: my(( test) message'
def test_linkifytext_names_with_apostrophe(team):
- text = linkify_text('@O\'Connor: my test message', team)
+ text = linkify_text("@O'Connor: my test message", team)
+
+ assert text == "@O'Connor: my test message"
- assert text == '@O\'Connor: my test message'
def test_linkifytext_names_with_subgroup_notification(team):
- subteam = team.subteams['TGX0ALBK3']
- message = 'This is a message for a subteam'
- text = linkify_text('{}: {}'.format(subteam.handle, message), team)
+ subteam = team.subteams["TGX0ALBK3"]
+ message = "This is a message for a subteam"
+ text = linkify_text("{}: {}".format(subteam.handle, message), team)
+
+ assert text == "<!subteam^{}|{}>: {}".format(
+ subteam.identifier, subteam.handle, message
+ )
- assert text == '<!subteam^{}|{}>: {}'.format(subteam.identifier, subteam.handle, message)
def test_linkifytext_at_channel(team):
- text = linkify_text('@channel: my test message', team)
+ text = linkify_text("@channel: my test message", team)
+
+ assert text == "<!channel>: my test message"
- assert text == '<!channel>: my test message'
def test_linkifytext_at_everyone(team):
- text = linkify_text('@everyone: my test message', team)
+ text = linkify_text("@everyone: my test message", team)
+
+ assert text == "<!everyone>: my test message"
- assert text == '<!everyone>: my test message'
def test_linkifytext_at_group(team):
- text = linkify_text('@group: my test message', team)
+ text = linkify_text("@group: my test message", team)
+
+ assert text == "<!group>: my test message"
- assert text == '<!group>: my test message'
def test_linkifytext_at_here(team):
- text = linkify_text('@here: my test message', team)
+ text = linkify_text("@here: my test message", team)
+
+ assert text == "<!here>: my test message"
- assert text == '<!here>: my test message'
def test_linkifytext_channel(team, channel_general):
- channel_name = re.sub(r'^[#&]', '', channel_general.name)
- text = linkify_text('#{}: my test message'.format(channel_name), team)
+ channel_name = re.sub(r"^[#&]", "", channel_general.name)
+ text = linkify_text("#{}: my test message".format(channel_name), team)
+
+ assert text == "<#{}|{}>: my test message".format(channel_general.id, channel_name)
- assert text == '<#{}|{}>: my test message'.format(channel_general.id, channel_name)
def test_linkifytext_not_private_using_hash(team, channel_private):
- channel_name = re.sub(r'^[#&]', '', channel_private.name)
- text = linkify_text('#{}: my test message'.format(channel_name), team)
+ channel_name = re.sub(r"^[#&]", "", channel_private.name)
+ text = linkify_text("#{}: my test message".format(channel_name), team)
+
+ assert text == "#{}: my test message".format(channel_name)
- assert text == '#{}: my test message'.format(channel_name)
def test_linkifytext_not_private_using_ampersand(team, channel_private):
- channel_name = re.sub(r'^[#&]', '', channel_private.name)
- text = linkify_text('&{}: my test message'.format(channel_name), team)
+ channel_name = re.sub(r"^[#&]", "", channel_private.name)
+ text = linkify_text("&{}: my test message".format(channel_name), team)
+
+ assert text == "&amp;{}: my test message".format(channel_name)
- assert text == '&amp;{}: my test message'.format(channel_name)
def test_linkifytext_not_dm(team, channel_dm):
- text = linkify_text('#{}: my test message'.format(channel_dm.name), team)
+ text = linkify_text("#{}: my test message".format(channel_dm.name), team)
+
+ assert text == "#{}: my test message".format(channel_dm.name)
- assert text == '#{}: my test message'.format(channel_dm.name)
def test_linkifytext_not_mpdm(team, channel_mpdm):
- text = linkify_text('#{}: my test message'.format(channel_mpdm.name), team)
+ text = linkify_text("#{}: my test message".format(channel_mpdm.name), team)
- assert text == '#{}: my test message'.format(channel_mpdm.name)
+ assert text == "#{}: my test message".format(channel_mpdm.name)
diff --git a/_pytest/test_presencechange.py b/_pytest/test_presencechange.py
index ffe28c9..fc4d379 100644
--- a/_pytest/test_presencechange.py
+++ b/_pytest/test_presencechange.py
@@ -2,16 +2,20 @@ from __future__ import print_function, unicode_literals
def test_PresenceChange(realish_eventrouter, team, user_alice):
- team.ws.add({
- "type": "presence_change",
- "user": user_alice.identifier,
- "presence": "active",
- })
- team.ws.add({
- "type": "presence_change",
- "user": user_alice.identifier,
- "presence": "away",
- })
+ team.ws.add(
+ {
+ "type": "presence_change",
+ "user": user_alice.identifier,
+ "presence": "active",
+ }
+ )
+ team.ws.add(
+ {
+ "type": "presence_change",
+ "user": user_alice.identifier,
+ "presence": "away",
+ }
+ )
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
diff --git a/_pytest/test_process_message.py b/_pytest/test_process_message.py
index b6d8ab6..5017c10 100644
--- a/_pytest/test_process_message.py
+++ b/_pytest/test_process_message.py
@@ -7,15 +7,33 @@ from wee_slack import SlackTS
def test_process_message(realish_eventrouter, team, user_alice):
messages = []
- messages.append(json.loads(open('_pytest/data/websocket/1485975421.33-message.json', 'r').read()))
+ messages.append(
+ json.loads(
+ open("_pytest/data/websocket/1485975421.33-message.json", "r").read()
+ )
+ )
# test message and then change
- messages.append(json.loads(open('_pytest/data/websocket/1485976151.6-message.json', 'r').read()))
- messages.append(json.loads(open('_pytest/data/websocket/1485976157.18-message.json', 'r').read()))
+ messages.append(
+ json.loads(open("_pytest/data/websocket/1485976151.6-message.json", "r").read())
+ )
+ messages.append(
+ json.loads(
+ open("_pytest/data/websocket/1485976157.18-message.json", "r").read()
+ )
+ )
# test message then deletion
- messages.append(json.loads(open('_pytest/data/websocket/1485975698.45-message.json', 'r').read()))
- messages.append(json.loads(open('_pytest/data/websocket/1485975723.85-message.json', 'r').read()))
+ messages.append(
+ json.loads(
+ open("_pytest/data/websocket/1485975698.45-message.json", "r").read()
+ )
+ )
+ messages.append(
+ json.loads(
+ open("_pytest/data/websocket/1485975723.85-message.json", "r").read()
+ )
+ )
for m in messages:
m["user"] = user_alice.id
@@ -30,20 +48,32 @@ def test_process_message(realish_eventrouter, team, user_alice):
assert sum([len(channel.messages) for channel in team.channels.values()]) == 3
- unchanged_message_channel = team.channels['D3ZEQULHZ']
- unchanged_message_ts = SlackTS('1485975421.000002')
+ unchanged_message_channel = team.channels["D3ZEQULHZ"]
+ unchanged_message_ts = SlackTS("1485975421.000002")
assert list(unchanged_message_channel.messages.keys()) == [unchanged_message_ts]
- assert unchanged_message_channel.messages[unchanged_message_ts].message_json['text'] == 'hi bob'
- assert 'edited' not in unchanged_message_channel.messages[unchanged_message_ts].message_json
+ assert (
+ unchanged_message_channel.messages[unchanged_message_ts].message_json["text"]
+ == "hi bob"
+ )
+ assert (
+ "edited"
+ not in unchanged_message_channel.messages[unchanged_message_ts].message_json
+ )
- changed_message_channel = team.channels['C407ABS94']
- changed_message_ts = SlackTS('1485976151.000016')
+ changed_message_channel = team.channels["C407ABS94"]
+ changed_message_ts = SlackTS("1485976151.000016")
assert list(changed_message_channel.messages.keys()) == [changed_message_ts]
- assert changed_message_channel.messages[changed_message_ts].message_json['text'] == 'referencing a <#C407ABS94|general>'
- assert 'edited' in changed_message_channel.messages[changed_message_ts].message_json
+ assert (
+ changed_message_channel.messages[changed_message_ts].message_json["text"]
+ == "referencing a <#C407ABS94|general>"
+ )
+ assert "edited" in changed_message_channel.messages[changed_message_ts].message_json
- deleted_message_channel = team.channels['G3ZGMF4RZ']
- deleted_message_ts = SlackTS('1485975698.000002')
+ deleted_message_channel = team.channels["G3ZGMF4RZ"]
+ deleted_message_ts = SlackTS("1485975698.000002")
assert list(deleted_message_channel.messages.keys()) == [deleted_message_ts]
- deleted_str = '<[color red]>(deleted)<[color reset]>'
- assert deleted_message_channel.messages[deleted_message_ts].message_json['text'] == deleted_str
+ deleted_str = "<[color red]>(deleted)<[color reset]>"
+ assert (
+ deleted_message_channel.messages[deleted_message_ts].message_json["text"]
+ == deleted_str
+ )
diff --git a/_pytest/test_processreply.py b/_pytest/test_processreply.py
index 994b43f..34c2623 100644
--- a/_pytest/test_processreply.py
+++ b/_pytest/test_processreply.py
@@ -4,14 +4,16 @@ from wee_slack import SlackTS
def test_process_reply(realish_eventrouter, team, channel_general):
- message_ts = SlackTS('12341234.123456')
- message_text = 'reply test'
+ message_ts = SlackTS("12341234.123456")
+ message_text = "reply test"
channel_general.send_message(message_text)
- team.ws.add({'ok': True, 'reply_to': 1, '_team': team.team_hash, 'ts': str(message_ts)})
+ team.ws.add(
+ {"ok": True, "reply_to": 1, "_team": team.team_hash, "ts": str(message_ts)}
+ )
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
assert message_ts in channel_general.messages
message_json = channel_general.messages[message_ts].message_json
- assert message_json['ts'] == message_ts
- assert message_json['text'] == message_text
+ assert message_json["ts"] == message_ts
+ assert message_json["text"] == message_text
diff --git a/_pytest/test_processsubteamcreated.py b/_pytest/test_processsubteamcreated.py
index 299ac6f..9ff3ee2 100644
--- a/_pytest/test_processsubteamcreated.py
+++ b/_pytest/test_processsubteamcreated.py
@@ -6,8 +6,8 @@ import json
def test_process_subteam_created(realish_eventrouter, team):
assert len(team.subteams) == 1
- datafile = '_pytest/data/websocket/1483975206.59-subteam_created.json'
- data = json.loads(open(datafile, 'r').read())
+ datafile = "_pytest/data/websocket/1483975206.59-subteam_created.json"
+ data = json.loads(open(datafile, "r").read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
diff --git a/_pytest/test_processsubteamupdated.py b/_pytest/test_processsubteamupdated.py
index e3eb824..6eea30f 100644
--- a/_pytest/test_processsubteamupdated.py
+++ b/_pytest/test_processsubteamupdated.py
@@ -6,13 +6,13 @@ import json
def test_process_subteam_self_updated(realish_eventrouter, team):
assert len(team.subteams) == 1
- datafile = '_pytest/data/websocket/1483975206.59-subteam_updated.json'
- data = json.loads(open(datafile, 'r').read())
+ datafile = "_pytest/data/websocket/1483975206.59-subteam_updated.json"
+ data = json.loads(open(datafile, "r").read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
- subteam = team.subteams['TGX0ALBK3']
+ subteam = team.subteams["TGX0ALBK3"]
- assert '@{}'.format(data['subteam']['handle']) == subteam.handle
- assert data['subteam']['description'] == subteam.description
- assert data['subteam']['name'] == subteam.name
+ assert "@{}".format(data["subteam"]["handle"]) == subteam.handle
+ assert data["subteam"]["description"] == subteam.description
+ assert data["subteam"]["name"] == subteam.name
diff --git a/_pytest/test_processteamjoin.py b/_pytest/test_processteamjoin.py
index f965bbb..e07ee0a 100644
--- a/_pytest/test_processteamjoin.py
+++ b/_pytest/test_processteamjoin.py
@@ -5,12 +5,12 @@ import json
def test_process_team_join(realish_eventrouter, team):
# delete charles so we can add him
- del team.users['U4096CBHC']
+ del team.users["U4096CBHC"]
assert len(team.users) == 3
- datafile = '_pytest/data/websocket/1485975606.59-team_join.json'
- data = json.loads(open(datafile, 'r').read())
+ datafile = "_pytest/data/websocket/1485975606.59-team_join.json"
+ data = json.loads(open(datafile, "r").read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
diff --git a/_pytest/test_sendmessage.py b/_pytest/test_sendmessage.py
index 17f38d7..eb205c1 100644
--- a/_pytest/test_sendmessage.py
+++ b/_pytest/test_sendmessage.py
@@ -4,15 +4,15 @@ import json
def test_send_message(realish_eventrouter, team, channel_general):
- message_text = 'send message test'
+ message_text = "send message test"
channel_general.send_message(message_text)
sent = json.loads(team.ws.sentdata[0])
assert sent == {
- 'text': message_text,
- 'type': 'message',
- 'user': team.myidentifier,
- 'channel': channel_general.id,
- 'id': 1,
+ "text": message_text,
+ "type": "message",
+ "user": team.myidentifier,
+ "channel": channel_general.id,
+ "id": 1,
}
diff --git a/_pytest/test_thread.py b/_pytest/test_thread.py
index 4095e77..06150a3 100644
--- a/_pytest/test_thread.py
+++ b/_pytest/test_thread.py
@@ -5,33 +5,39 @@ import json
from wee_slack import SlackTS
-thread_ts = SlackTS('1485975824.000004')
+thread_ts = SlackTS("1485975824.000004")
def test_message_has_thread_suffix(realish_eventrouter, team, channel_general):
- datafile = '_pytest/data/websocket/1485975824.48-message.json'
+ datafile = "_pytest/data/websocket/1485975824.48-message.json"
data = json.loads(open(datafile).read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
- message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
- assert message_text == 'generally, yep!'
+ message_text = channel_general.messages[thread_ts].message_json["_rendered_text"]
+ assert message_text == "generally, yep!"
- datafile = '_pytest/data/websocket/1485975836.23-message.json'
+ datafile = "_pytest/data/websocket/1485975836.23-message.json"
data = json.loads(open(datafile).read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
- message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
- assert message_text == 'generally, yep! <[color lightcyan]>[ Thread: 309 Replies: 1 ]<[color reset]>'
+ message_text = channel_general.messages[thread_ts].message_json["_rendered_text"]
+ assert (
+ message_text
+ == "generally, yep! <[color lightcyan]>[ Thread: 309 Replies: 1 ]<[color reset]>"
+ )
- datafile = '_pytest/data/websocket/1485975842.1-message.json'
+ datafile = "_pytest/data/websocket/1485975842.1-message.json"
data = json.loads(open(datafile).read())
team.ws.add(data)
realish_eventrouter.receive_ws_callback(team.team_hash, None)
realish_eventrouter.handle_next()
- message_text = channel_general.messages[thread_ts].message_json['_rendered_text']
- assert message_text == 'generally, yep! <[color lightcyan]>[ Thread: 309 Replies: 2 ]<[color reset]>'
+ message_text = channel_general.messages[thread_ts].message_json["_rendered_text"]
+ assert (
+ message_text
+ == "generally, yep! <[color lightcyan]>[ Thread: 309 Replies: 2 ]<[color reset]>"
+ )
diff --git a/_pytest/test_topic_command.py b/_pytest/test_topic_command.py
index 79a26d3..1b1c15d 100644
--- a/_pytest/test_topic_command.py
+++ b/_pytest/test_topic_command.py
@@ -6,66 +6,67 @@ from mock import patch
def test_parse_topic_without_arguments():
- channel_name, topic = parse_topic_command('/topic')
+ channel_name, topic = parse_topic_command("/topic")
assert channel_name is None
assert topic is None
def test_parse_topic_with_text():
- channel_name, topic = parse_topic_command('/topic some topic text')
+ channel_name, topic = parse_topic_command("/topic some topic text")
assert channel_name is None
- assert topic == 'some topic text'
+ assert topic == "some topic text"
def test_parse_topic_with_text_with_newline():
- channel_name, topic = parse_topic_command('/topic some topic text\nsecond line')
+ channel_name, topic = parse_topic_command("/topic some topic text\nsecond line")
assert channel_name is None
- assert topic == 'some topic text\nsecond line'
+ assert topic == "some topic text\nsecond line"
def test_parse_topic_with_delete():
- channel_name, topic = parse_topic_command('/topic -delete')
+ channel_name, topic = parse_topic_command("/topic -delete")
assert channel_name is None
- assert topic == ''
+ assert topic == ""
def test_parse_topic_with_channel():
- channel_name, topic = parse_topic_command('/topic #general')
+ channel_name, topic = parse_topic_command("/topic #general")
- assert channel_name == '#general'
+ assert channel_name == "#general"
assert topic is None
def test_parse_topic_with_channel_and_text():
- channel_name, topic = parse_topic_command(
- '/topic #general some topic text')
+ channel_name, topic = parse_topic_command("/topic #general some topic text")
- assert channel_name == '#general'
- assert topic == 'some topic text'
+ assert channel_name == "#general"
+ assert topic == "some topic text"
def test_parse_topic_with_channel_and_delete():
- channel_name, topic = parse_topic_command('/topic #general -delete')
+ channel_name, topic = parse_topic_command("/topic #general -delete")
- assert channel_name == '#general'
- assert topic == ''
+ assert channel_name == "#general"
+ assert topic == ""
def test_call_topic_without_arguments(realish_eventrouter, channel_general):
current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
- command = '/topic'
+ command = "/topic"
- with patch('wee_slack.w.prnt') as fake_prnt:
+ with patch("wee_slack.w.prnt") as fake_prnt:
result = topic_command_cb(None, current_buffer, command)
fake_prnt.assert_called_with(
channel_general.channel_buffer,
- 'Topic for {} is "{}"'.format(channel_general.name, channel_general.topic['value']),
+ 'Topic for {} is "{}"'.format(
+ channel_general.name, channel_general.topic["value"]
+ ),
)
assert result == wee_slack.w.WEECHAT_RC_OK_EAT
@@ -74,9 +75,9 @@ def test_call_topic_with_unknown_channel(realish_eventrouter, team, channel_gene
current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
- command = '/topic #nonexisting'
+ command = "/topic #nonexisting"
- with patch('wee_slack.w.prnt') as fake_prnt:
+ with patch("wee_slack.w.prnt") as fake_prnt:
result = topic_command_cb(None, current_buffer, command)
fake_prnt.assert_called_with(
team.channel_buffer,
@@ -89,11 +90,14 @@ def test_call_topic_with_channel_and_string(realish_eventrouter, channel_general
current_buffer = channel_general.channel_buffer
wee_slack.EVENTROUTER = realish_eventrouter
- command = '/topic #general new topic'
+ command = "/topic #general new topic"
result = topic_command_cb(None, current_buffer, command)
request = realish_eventrouter.queue[-1]
- assert request.request == 'conversations.setTopic'
+ assert request.request == "conversations.setTopic"
assert request.post_data == {
- 'channel': 'C407ABS94', 'token': 'xoxs-token', 'topic': 'new topic'}
+ "channel": "C407ABS94",
+ "token": "xoxs-token",
+ "topic": "new topic",
+ }
assert result == wee_slack.w.WEECHAT_RC_OK_EAT
diff --git a/_pytest/test_unfurl.py b/_pytest/test_unfurl.py
index eb8fe27..e8043a8 100644
--- a/_pytest/test_unfurl.py
+++ b/_pytest/test_unfurl.py
@@ -6,166 +6,173 @@ import time
import wee_slack
import os
-os.environ['TZ'] = 'UTC'
+os.environ["TZ"] = "UTC"
-@pytest.mark.parametrize('case', (
- {
- 'input': "foo",
- 'output': "foo",
- },
- {
- 'input': "<!channel>",
- 'output': "@channel",
- },
- {
- 'input': "<!everyone>",
- 'output': "@everyone",
- },
- {
- 'input': "<!group>",
- 'output': "@group",
- },
- {
- 'input': "<!here>",
- 'output': "@here",
- },
- {
- 'input': "<@U407ABLLW|@othernick>: foo",
- 'output': "@alice: foo",
- },
- {
- 'input': "<@UNKNOWN|@othernick>: foo",
- 'output': "@othernick: foo",
- },
- {
- 'input': "foo <#C407ABS94|otherchannel> foo",
- 'output': "foo #general foo",
- },
- {
- 'input': "foo <#UNKNOWN|otherchannel> foo",
- 'output': "foo #otherchannel foo",
- },
- {
- 'input': "url: <https://example.com|fallback> suffix",
- 'output': "url: https://example.com suffix",
- 'ignore_alt_text': True,
- },
- {
- 'input': "url: <https://example.com|example> suffix",
- 'output': "url: https://example.com (example) suffix",
- 'auto_link_display': 'both',
- },
- {
- 'input': "url: <https://example.com|example with spaces> suffix",
- 'output': "url: https://example.com (example with spaces) suffix",
- 'auto_link_display': 'both',
- },
- {
- 'input': "url: <https://example.com|example.com> suffix",
- 'output': "url: https://example.com (example.com) suffix",
- 'auto_link_display': 'both',
- },
- {
- 'input': "url: <mailto:name@example.com|name@example.com> suffix",
- 'output': "url: mailto:name@example.com (name@example.com) suffix",
- 'auto_link_display': 'both',
- },
- {
- 'input': "url: <https://example.com|example.com> suffix",
- 'output': "url: example.com suffix",
- 'auto_link_display': 'text',
- },
- {
- 'input': "url: <https://example.com|different text> suffix",
- 'output': "url: https://example.com (different text) suffix",
- 'auto_link_display': 'text',
- },
- {
- 'input': "url: <mailto:name@example.com|name@example.com> suffix",
- 'output': "url: name@example.com suffix",
- 'auto_link_display': 'text',
- },
- {
- 'input': "url: <https://example.com|different text> suffix",
- 'output': "url: https://example.com (different text) suffix",
- 'auto_link_display': 'url',
- },
- {
- 'input': "url: <https://example.com|example.com> suffix",
- 'output': "url: https://example.com suffix",
- 'auto_link_display': 'url',
- },
- {
- 'input': "url: <mailto:name@example.com|name@example.com> suffix",
- 'output': "url: mailto:name@example.com suffix",
- 'auto_link_display': 'url',
- },
- {
- 'input': "<@U407ABLLW> multiple unfurl <https://example.com|example with spaces>",
- 'output': "@alice multiple unfurl https://example.com (example with spaces)",
- 'auto_link_display': 'both',
- },
- {
- 'input': "url with equal fallback: <https://example.com|https://example.com> suffix",
- 'output': "url with equal fallback: https://example.com suffix",
- 'auto_link_display': 'both',
- },
- {
- 'input': "try the #general channel",
- 'output': "try the #general channel",
- },
- {
- 'input': "<@U407ABLLW> I think 3 > 2",
- 'output': "@alice I think 3 > 2",
- },
- {
- 'input': "<!subteam^TGX0ALBK3|@othersubteam> This is announcement for the dev team",
- 'output': "@test This is announcement for the dev team"
- },
- {
- 'input': "<!subteam^UNKNOWN|@othersubteam> This is announcement for the dev team",
- 'output': "@othersubteam This is announcement for the dev team"
- },
- {
- 'input': "Ends <!date^1577880000^{date_num} - {date} - {date_short} - {date_long}|Jan 01, 2020>.",
- 'output': "Ends 2020-01-01 - January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020."
- },
- {
- 'input': "Ends <!date^1577880000^{time} - {time_secs}|12:00 PM>.",
- 'output': "Ends 12:00 - 12:00:00."
- },
- {
- 'input': "Ends <!date^1577880000^{date_num} {invalid_token}>.",
- 'output': "Ends 2020-01-01 {invalid_token}."
- },
- {
- 'input': "Ends <!date^1577880000^{date_num}^http://github.com>.",
- 'output': "Ends 2020-01-01 (http://github.com)."
- },
- {
- 'input': "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
- int(time.mktime(datetime.today().timetuple()))),
- 'output': "Ends today - today - today."
- },
- {
- 'input': "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
- int(time.mktime((datetime.today() - timedelta(days=1)).timetuple()))),
- 'output': "Ends yesterday - yesterday - yesterday."
- },
- {
- 'input': "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
- int(time.mktime((datetime.today() + timedelta(days=1)).timetuple()))),
- 'output': "Ends tomorrow - tomorrow - tomorrow."
- },
- {
- 'input': "Ends <!date^1577880000^{date_pretty} - {date_short_pretty} - {date_long_pretty}>.",
- 'output': "Ends January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020."
- }
-))
+
+@pytest.mark.parametrize(
+ "case",
+ (
+ {
+ "input": "foo",
+ "output": "foo",
+ },
+ {
+ "input": "<!channel>",
+ "output": "@channel",
+ },
+ {
+ "input": "<!everyone>",
+ "output": "@everyone",
+ },
+ {
+ "input": "<!group>",
+ "output": "@group",
+ },
+ {
+ "input": "<!here>",
+ "output": "@here",
+ },
+ {
+ "input": "<@U407ABLLW|@othernick>: foo",
+ "output": "@alice: foo",
+ },
+ {
+ "input": "<@UNKNOWN|@othernick>: foo",
+ "output": "@othernick: foo",
+ },
+ {
+ "input": "foo <#C407ABS94|otherchannel> foo",
+ "output": "foo #general foo",
+ },
+ {
+ "input": "foo <#UNKNOWN|otherchannel> foo",
+ "output": "foo #otherchannel foo",
+ },
+ {
+ "input": "url: <https://example.com|fallback> suffix",
+ "output": "url: https://example.com suffix",
+ "ignore_alt_text": True,
+ },
+ {
+ "input": "url: <https://example.com|example> suffix",
+ "output": "url: https://example.com (example) suffix",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "url: <https://example.com|example with spaces> suffix",
+ "output": "url: https://example.com (example with spaces) suffix",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "url: <https://example.com|example.com> suffix",
+ "output": "url: https://example.com (example.com) suffix",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "url: <mailto:name@example.com|name@example.com> suffix",
+ "output": "url: mailto:name@example.com (name@example.com) suffix",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "url: <https://example.com|example.com> suffix",
+ "output": "url: example.com suffix",
+ "auto_link_display": "text",
+ },
+ {
+ "input": "url: <https://example.com|different text> suffix",
+ "output": "url: https://example.com (different text) suffix",
+ "auto_link_display": "text",
+ },
+ {
+ "input": "url: <mailto:name@example.com|name@example.com> suffix",
+ "output": "url: name@example.com suffix",
+ "auto_link_display": "text",
+ },
+ {
+ "input": "url: <https://example.com|different text> suffix",
+ "output": "url: https://example.com (different text) suffix",
+ "auto_link_display": "url",
+ },
+ {
+ "input": "url: <https://example.com|example.com> suffix",
+ "output": "url: https://example.com suffix",
+ "auto_link_display": "url",
+ },
+ {
+ "input": "url: <mailto:name@example.com|name@example.com> suffix",
+ "output": "url: mailto:name@example.com suffix",
+ "auto_link_display": "url",
+ },
+ {
+ "input": "<@U407ABLLW> multiple unfurl <https://example.com|example with spaces>",
+ "output": "@alice multiple unfurl https://example.com (example with spaces)",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "url with equal fallback: <https://example.com|https://example.com> suffix",
+ "output": "url with equal fallback: https://example.com suffix",
+ "auto_link_display": "both",
+ },
+ {
+ "input": "try the #general channel",
+ "output": "try the #general channel",
+ },
+ {
+ "input": "<@U407ABLLW> I think 3 > 2",
+ "output": "@alice I think 3 > 2",
+ },
+ {
+ "input": "<!subteam^TGX0ALBK3|@othersubteam> This is announcement for the dev team",
+ "output": "@test This is announcement for the dev team",
+ },
+ {
+ "input": "<!subteam^UNKNOWN|@othersubteam> This is announcement for the dev team",
+ "output": "@othersubteam This is announcement for the dev team",
+ },
+ {
+ "input": "Ends <!date^1577880000^{date_num} - {date} - {date_short} - {date_long}|Jan 01, 2020>.",
+ "output": "Ends 2020-01-01 - January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020.",
+ },
+ {
+ "input": "Ends <!date^1577880000^{time} - {time_secs}|12:00 PM>.",
+ "output": "Ends 12:00 - 12:00:00.",
+ },
+ {
+ "input": "Ends <!date^1577880000^{date_num} {invalid_token}>.",
+ "output": "Ends 2020-01-01 {invalid_token}.",
+ },
+ {
+ "input": "Ends <!date^1577880000^{date_num}^http://github.com>.",
+ "output": "Ends 2020-01-01 (http://github.com).",
+ },
+ {
+ "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
+ int(time.mktime(datetime.today().timetuple()))
+ ),
+ "output": "Ends today - today - today.",
+ },
+ {
+ "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
+ int(time.mktime((datetime.today() - timedelta(days=1)).timetuple()))
+ ),
+ "output": "Ends yesterday - yesterday - yesterday.",
+ },
+ {
+ "input": "Ends <!date^{}^{{date_pretty}} - {{date_short_pretty}} - {{date_long_pretty}}>.".format(
+ int(time.mktime((datetime.today() + timedelta(days=1)).timetuple()))
+ ),
+ "output": "Ends tomorrow - tomorrow - tomorrow.",
+ },
+ {
+ "input": "Ends <!date^1577880000^{date_pretty} - {date_short_pretty} - {date_long_pretty}>.",
+ "output": "Ends January 01, 2020 - Jan 01, 2020 - Wednesday, January 01, 2020.",
+ },
+ ),
+)
def test_unfurl_refs(case, realish_eventrouter):
wee_slack.EVENTROUTER = realish_eventrouter
- wee_slack.config.unfurl_ignore_alt_text = case.get('ignore_alt_text')
- wee_slack.config.unfurl_auto_link_display = case.get('auto_link_display')
+ wee_slack.config.unfurl_ignore_alt_text = case.get("ignore_alt_text")
+ wee_slack.config.unfurl_auto_link_display = case.get("auto_link_display")
- result = wee_slack.unfurl_refs(case['input'])
- assert result == case['output']
+ result = wee_slack.unfurl_refs(case["input"])
+ assert result == case["output"]
diff --git a/_pytest/test_unwrap_attachments.py b/_pytest/test_unwrap_attachments.py
index aed696c..d4116eb 100644
--- a/_pytest/test_unwrap_attachments.py
+++ b/_pytest/test_unwrap_attachments.py
@@ -4,322 +4,467 @@ import wee_slack
import pytest
-@pytest.mark.parametrize('case', (
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- }]},
- 'input_text_before': "Text before",
- 'output': "\n".join([
- "",
- "| Title",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'title_link': 'http://title.link',
- 'from_url': 'http://from.url',
- 'fallback': 'Fallback',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title (http://title.link)",
- "| http://from.url",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'title_link': 'http://title.link',
- 'image_url': 'http://image.url',
- 'fallback': 'Fallback',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title (http://title.link)",
- "| Attachment text",
- "| http://image.url",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'title_link': 'http://link?a=1&b=2',
- 'from_url': 'http://link?a=1&b=2',
- 'image_url': 'http://link?a=1&b=2',
- }]},
- 'input_text_before': "http://link?a=1&amp;b=2",
- 'output': "\n".join([
- "",
- "| Title",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'title_link': 'http://link?a=1&amp;b=2',
- 'from_url': 'http://link?a=1&amp;b=2',
- 'image_url': 'http://link?a=1&amp;b=2',
- }]},
- 'input_text_before': "http://link?a=1&amp;b=2",
- 'output': "\n".join([
- "",
- "| Title",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'title_link': 'http://link',
- 'from_url': 'http://link',
- 'image_url': 'http://link',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title (http://link)",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text',
- 'from_url': 'http://link',
- 'image_url': 'http://link',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title",
- "| http://link",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'text': 'Attachment text\n\n\nWith multiple lines',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title",
- "| Attachment text",
- "| With multiple lines",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'author_name': 'Author',
- 'pretext': 'Pretext',
- 'text': 'Attachment text',
- 'title_link': 'http://title.link',
- 'from_url': 'http://from.url',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Pretext",
- "| Author: Title (http://title.link)",
- "| http://from.url",
- "| Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'author_name': 'Author',
- 'text': 'Attachment text',
- 'title_link': 'http://title.link',
- 'from_url': 'http://from.url',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| http://from.url",
- "| Author: Attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'fallback': 'Fallback',
- }]},
- 'input_text_before': "",
- 'output': "| Fallback",
- },
- {
- 'input_message': {'attachments': [{
- 'fallback': 'Fallback',
- 'title_link': 'http://link',
- }]},
- 'input_text_before': "http://link",
- 'output': "",
- },
- {
- 'input_message': {'attachments': [{
- 'fallback': 'Fallback',
- 'from_url': 'http://link',
- }]},
- 'input_text_before': "http://link",
- 'output': "",
- },
- {
- 'input_message': {'attachments': [{
- 'fallback': 'Fallback',
- 'image_url': 'http://link',
- }]},
- 'input_text_before': "http://link",
- 'output': "",
- },
- {
- 'input_message': {'attachments': [{
- 'text': 'Some message',
- 'footer': 'Thread in #general'
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Some message",
- "| Thread in #general",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'ts': 1584986782,
- 'text': 'Some message',
- 'footer': 'Thread in #general'
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Some message",
- "| Thread in #general | Mar 23, 2020",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'ts': '1584986782.261400',
- 'text': 'Some message',
- 'footer': 'Thread in #general'
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Some message",
- "| Thread in #general | Mar 23, 2020",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'text': 'Original message',
- 'files': [
- {
- 'title': 'File',
- 'url_private': 'http://link',
- }
- ],
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Original message",
- "| http://link (File)",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'fields': [{
- 'title': 'First field title',
- 'value': 'First field value',
- }, {
- 'title': '',
- 'value': 'Second field value',
- }],
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Title",
- "| First field title: First field value",
- "| Second field value",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'First attachment title',
- 'text': 'First attachment text',
- 'title_link': 'http://title.link.1',
- 'from_url': 'http://from.url.1',
- }, {
- 'title': 'Second attachment title',
- 'text': 'Second attachment text',
- 'title_link': 'http://title.link.2',
- 'from_url': 'http://from.url.2',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| First attachment title (http://title.link.1)",
- "| http://from.url.1",
- "| First attachment text",
- "| Second attachment title (http://title.link.2)",
- "| http://from.url.2",
- "| Second attachment text",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'color': 'ff0000',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "<[color 16711680]>|<[color reset]> Title",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'title': 'Title',
- 'color': '#ff0000',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "<[color 16711680]>|<[color reset]> Title",
- ]),
- },
- {
- 'input_message': {'attachments': [{
- 'text': 'Attachment text',
- 'original_url': 'http://from.url',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Attachment text",
- ]),
- 'link_previews': True
- },
- {
- 'input_message': {'attachments': [{
- 'text': 'Attachment text',
- 'original_url': 'http://from.url',
- }]},
- 'input_text_before': "",
- 'output': '',
- 'link_previews': False
- },
- {
- 'input_message': {'attachments': [{
- 'text': 'Attachment text',
- }]},
- 'input_text_before': "",
- 'output': "\n".join([
- "| Attachment text",
- ]),
- 'link_previews': False
- },
-))
+@pytest.mark.parametrize(
+ "case",
+ (
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ }
+ ]
+ },
+ "input_text_before": "Text before",
+ "output": "\n".join(
+ [
+ "",
+ "| Title",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "title_link": "http://title.link",
+ "from_url": "http://from.url",
+ "fallback": "Fallback",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title (http://title.link)",
+ "| http://from.url",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "title_link": "http://title.link",
+ "image_url": "http://image.url",
+ "fallback": "Fallback",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title (http://title.link)",
+ "| Attachment text",
+ "| http://image.url",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "title_link": "http://link?a=1&b=2",
+ "from_url": "http://link?a=1&b=2",
+ "image_url": "http://link?a=1&b=2",
+ }
+ ]
+ },
+ "input_text_before": "http://link?a=1&amp;b=2",
+ "output": "\n".join(
+ [
+ "",
+ "| Title",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "title_link": "http://link?a=1&amp;b=2",
+ "from_url": "http://link?a=1&amp;b=2",
+ "image_url": "http://link?a=1&amp;b=2",
+ }
+ ]
+ },
+ "input_text_before": "http://link?a=1&amp;b=2",
+ "output": "\n".join(
+ [
+ "",
+ "| Title",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "title_link": "http://link",
+ "from_url": "http://link",
+ "image_url": "http://link",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title (http://link)",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text",
+ "from_url": "http://link",
+ "image_url": "http://link",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title",
+ "| http://link",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "text": "Attachment text\n\n\nWith multiple lines",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title",
+ "| Attachment text",
+ "| With multiple lines",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "author_name": "Author",
+ "pretext": "Pretext",
+ "text": "Attachment text",
+ "title_link": "http://title.link",
+ "from_url": "http://from.url",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Pretext",
+ "| Author: Title (http://title.link)",
+ "| http://from.url",
+ "| Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "author_name": "Author",
+ "text": "Attachment text",
+ "title_link": "http://title.link",
+ "from_url": "http://from.url",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| http://from.url",
+ "| Author: Attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "fallback": "Fallback",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "| Fallback",
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "fallback": "Fallback",
+ "title_link": "http://link",
+ }
+ ]
+ },
+ "input_text_before": "http://link",
+ "output": "",
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "fallback": "Fallback",
+ "from_url": "http://link",
+ }
+ ]
+ },
+ "input_text_before": "http://link",
+ "output": "",
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "fallback": "Fallback",
+ "image_url": "http://link",
+ }
+ ]
+ },
+ "input_text_before": "http://link",
+ "output": "",
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {"text": "Some message", "footer": "Thread in #general"}
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Some message",
+ "| Thread in #general",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "ts": 1584986782,
+ "text": "Some message",
+ "footer": "Thread in #general",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Some message",
+ "| Thread in #general | Mar 23, 2020",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "ts": "1584986782.261400",
+ "text": "Some message",
+ "footer": "Thread in #general",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Some message",
+ "| Thread in #general | Mar 23, 2020",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "text": "Original message",
+ "files": [
+ {
+ "title": "File",
+ "url_private": "http://link",
+ }
+ ],
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Original message",
+ "| http://link (File)",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "fields": [
+ {
+ "title": "First field title",
+ "value": "First field value",
+ },
+ {
+ "title": "",
+ "value": "Second field value",
+ },
+ ],
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Title",
+ "| First field title: First field value",
+ "| Second field value",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "First attachment title",
+ "text": "First attachment text",
+ "title_link": "http://title.link.1",
+ "from_url": "http://from.url.1",
+ },
+ {
+ "title": "Second attachment title",
+ "text": "Second attachment text",
+ "title_link": "http://title.link.2",
+ "from_url": "http://from.url.2",
+ },
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| First attachment title (http://title.link.1)",
+ "| http://from.url.1",
+ "| First attachment text",
+ "| Second attachment title (http://title.link.2)",
+ "| http://from.url.2",
+ "| Second attachment text",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "color": "ff0000",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "<[color 16711680]>|<[color reset]> Title",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "title": "Title",
+ "color": "#ff0000",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "<[color 16711680]>|<[color reset]> Title",
+ ]
+ ),
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "text": "Attachment text",
+ "original_url": "http://from.url",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Attachment text",
+ ]
+ ),
+ "link_previews": True,
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "text": "Attachment text",
+ "original_url": "http://from.url",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "",
+ "link_previews": False,
+ },
+ {
+ "input_message": {
+ "attachments": [
+ {
+ "text": "Attachment text",
+ }
+ ]
+ },
+ "input_text_before": "",
+ "output": "\n".join(
+ [
+ "| Attachment text",
+ ]
+ ),
+ "link_previews": False,
+ },
+ ),
+)
def test_unwrap_attachments(case):
- wee_slack.config.link_previews = case.get('link_previews')
+ wee_slack.config.link_previews = case.get("link_previews")
result = wee_slack.unwrap_attachments(
- case['input_message'], case['input_text_before'])
- assert result == case['output']
+ case["input_message"], case["input_text_before"]
+ )
+ assert result == case["output"]
diff --git a/_pytest/test_utf8_helpers.py b/_pytest/test_utf8_helpers.py
index a2dea42..271b84b 100644
--- a/_pytest/test_utf8_helpers.py
+++ b/_pytest/test_utf8_helpers.py
@@ -7,79 +7,82 @@ from collections import OrderedDict
from wee_slack import decode_from_utf8, encode_to_utf8, utf8_decode
-b_ae = 'æ'.encode('utf-8')
-b_oe = 'ø'.encode('utf-8')
-b_aa = 'å'.encode('utf-8')
+b_ae = "æ".encode("utf-8")
+b_oe = "ø".encode("utf-8")
+b_aa = "å".encode("utf-8")
b_word = b_ae + b_oe + b_aa
if sys.version_info.major > 2:
+
def test_decode_should_not_transform_str():
- assert 'æøå' == decode_from_utf8('æøå')
+ assert "æøå" == decode_from_utf8("æøå")
def test_decode_should_not_transform_bytes():
assert b_word == decode_from_utf8(b_word)
def test_encode_should_not_transform_str():
- assert 'æøå' == encode_to_utf8('æøå')
+ assert "æøå" == encode_to_utf8("æøå")
def test_encode_should_not_transform_bytes():
assert b_word == encode_to_utf8(b_word)
+
else:
+
def test_decode_preserves_string_without_utf8():
- assert 'test' == decode_from_utf8(b'test')
+ assert "test" == decode_from_utf8(b"test")
def test_decode_preserves_unicode_strings():
- assert 'æøå' == decode_from_utf8('æøå')
+ assert "æøå" == decode_from_utf8("æøå")
def test_decode_preserves_mapping_type():
- value_dict = {'a': 'x', 'b': 'y', 'c': 'z'}
+ value_dict = {"a": "x", "b": "y", "c": "z"}
value_ord_dict = OrderedDict(value_dict)
assert type(value_dict) == type(decode_from_utf8(value_dict))
assert type(value_ord_dict) == type(decode_from_utf8(value_ord_dict))
def test_decode_preserves_iterable_type():
- value_set = {'a', 'b', 'c'}
- value_tuple = ('a', 'b', 'c')
+ value_set = {"a", "b", "c"}
+ value_tuple = ("a", "b", "c")
assert type(value_set) == type(decode_from_utf8(value_set))
assert type(value_tuple) == type(decode_from_utf8(value_tuple))
def test_decodes_utf8_string_to_unicode():
- assert 'æøå' == decode_from_utf8(b_word)
+ assert "æøå" == decode_from_utf8(b_word)
def test_decodes_utf8_dict_to_unicode():
- assert {'æ': 'å', 'ø': 'å'} == decode_from_utf8({b_ae: b_aa, b_oe: b_aa})
+ assert {"æ": "å", "ø": "å"} == decode_from_utf8({b_ae: b_aa, b_oe: b_aa})
def test_decodes_utf8_list_to_unicode():
- assert ['æ', 'ø', 'å'] == decode_from_utf8([b_ae, b_oe, b_aa])
+ assert ["æ", "ø", "å"] == decode_from_utf8([b_ae, b_oe, b_aa])
def test_encode_preserves_string_without_utf8():
- assert b'test' == encode_to_utf8('test')
+ assert b"test" == encode_to_utf8("test")
def test_encode_preserves_byte_strings():
assert b_word == encode_to_utf8(b_word)
def test_encode_preserves_mapping_type():
- value_dict = {'a': 'x', 'b': 'y', 'c': 'z'}
+ value_dict = {"a": "x", "b": "y", "c": "z"}
value_ord_dict = OrderedDict(value_dict)
assert type(value_dict) == type(encode_to_utf8(value_dict))
assert type(value_ord_dict) == type(encode_to_utf8(value_ord_dict))
def test_encode_preserves_iterable_type():
- value_set = {'a', 'b', 'c'}
- value_tuple = ('a', 'b', 'c')
+ value_set = {"a", "b", "c"}
+ value_tuple = ("a", "b", "c")
assert type(value_set) == type(encode_to_utf8(value_set))
assert type(value_tuple) == type(encode_to_utf8(value_tuple))
def test_encodes_utf8_string_to_unicode():
- assert b_word == encode_to_utf8('æøå')
+ assert b_word == encode_to_utf8("æøå")
def test_encodes_utf8_dict_to_unicode():
- assert {b_ae: b_aa, b_oe: b_aa} == encode_to_utf8({'æ': 'å', 'ø': 'å'})
+ assert {b_ae: b_aa, b_oe: b_aa} == encode_to_utf8({"æ": "å", "ø": "å"})
def test_encodes_utf8_list_to_unicode():
- assert [b_ae, b_oe, b_aa] == encode_to_utf8(['æ', 'ø', 'å'])
+ assert [b_ae, b_oe, b_aa] == encode_to_utf8(["æ", "ø", "å"])
@utf8_decode
def method_with_utf8_decode(*args, **kwargs):