Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format python files with black #828

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/wee-slack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ jobs:
# exit-zero treats all errors as warnings.
pipenv run flake8 . --exit-zero --select=C,E,F,W

- name: Check Python formatting
run: |
pipenv run black --check .

test:
if: >
github.event_name == 'push' || (
Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ websocket-client = "*"
mock = "*"
pytest = "*"
flake8 = "*"
black = "*"
58 changes: 46 additions & 12 deletions _pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,119 +14,153 @@
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()
Expand Down
17 changes: 10 additions & 7 deletions _pytest/test_command_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

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())
Expand All @@ -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
4 changes: 2 additions & 2 deletions _pytest/test_eventrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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

# 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
Expand Down
2 changes: 1 addition & 1 deletion _pytest/test_everything.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down