Skip to content

Commit

Permalink
Normalize import style with isort.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Jul 20, 2015
1 parent 659cb30 commit 739f9d1
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ python-tag = py33.py34

[flake8]
ignore = F403

[isort]
known_standard_library = asyncio
lines_after_imports = 2
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import sys

import setuptools


# Avoid polluting the .tar.gz with ._* files under Mac OS X
os.putenv('COPYFILE_DISABLE', 'true')

Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py33,py34,flake8
envlist = py33,py34,flake8,isort

[testenv]
deps =
Expand All @@ -10,3 +10,8 @@ commands = python -m unittest
commands = flake8 websockets
deps =
flake8

[testenv:isort]
commands = isort --check-only --recursive websockets
deps =
isort
2 changes: 1 addition & 1 deletion websockets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .exceptions import InvalidHandshake
from .handshake import build_request, check_response
from .http import read_response, USER_AGENT
from .http import USER_AGENT, read_response
from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol
from .uri import parse_uri

Expand Down
5 changes: 2 additions & 3 deletions websockets/framing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
.. _section 5 of RFC 6455: http://tools.ietf.org/html/rfc6455#section-5
"""

import asyncio
import collections
import io
import random
import struct

import asyncio

from .exceptions import WebSocketProtocolError, PayloadTooBig
from .exceptions import PayloadTooBig, WebSocketProtocolError


__all__ = [
Expand Down
3 changes: 1 addition & 2 deletions websockets/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

__all__ = ['read_request', 'read_response', 'USER_AGENT']

import asyncio
import email.parser
import io
import sys

import asyncio

from .version import version as websockets_version


Expand Down
9 changes: 4 additions & 5 deletions websockets/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

__all__ = ['WebSocketCommonProtocol']

import asyncio
import asyncio.queues
import codecs
import collections
import logging
import random
import struct

import asyncio
from asyncio.queues import Queue, QueueEmpty

from .exceptions import InvalidState, PayloadTooBig, WebSocketProtocolError
from .framing import *
from .handshake import *
Expand Down Expand Up @@ -96,7 +95,7 @@ def __init__(self, *,
self.connection_closed = asyncio.Future(loop=loop)

# Queue of received messages.
self.messages = Queue(loop=loop)
self.messages = asyncio.queues.Queue(loop=loop)

# Mapping of ping IDs to waiters, in chronological order.
self.pings = collections.OrderedDict()
Expand Down Expand Up @@ -171,7 +170,7 @@ def recv(self):
# Return any available message
try:
return self.messages.get_nowait()
except QueueEmpty:
except asyncio.queues.QueueEmpty:
pass

# Wait for a message until the connection is closed
Expand Down
7 changes: 3 additions & 4 deletions websockets/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

__all__ = ['serve', 'WebSocketServerProtocol']

import asyncio
import collections.abc
import logging

import asyncio

from .exceptions import InvalidHandshake, InvalidOrigin
from .handshake import check_request, build_response
from .http import read_request, USER_AGENT
from .handshake import build_response, check_request
from .http import USER_AGENT, read_request
from .protocol import CONNECTING, OPEN, WebSocketCommonProtocol


Expand Down
24 changes: 12 additions & 12 deletions websockets/test_client_server.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import asyncio
import logging
import os
import ssl
import unittest
from unittest.mock import patch

import asyncio
import unittest.mock

from .client import *
from .exceptions import InvalidHandshake
from .http import read_response, USER_AGENT
from .http import USER_AGENT, read_response
from .server import *


Expand Down Expand Up @@ -195,7 +194,8 @@ def test_subprotocol_not_requested(self):
self.stop_client()
self.stop_server()

@patch.object(WebSocketServerProtocol, 'select_subprotocol', autospec=True)
@unittest.mock.patch.object(
WebSocketServerProtocol, 'select_subprotocol', autospec=True)
def test_subprotocol_error(self, _select_subprotocol):
_select_subprotocol.return_value = 'superchat'

Expand All @@ -205,7 +205,7 @@ def test_subprotocol_error(self, _select_subprotocol):
self.notice_connection_close()
self.stop_server()

@patch('websockets.server.read_request')
@unittest.mock.patch('websockets.server.read_request')
def test_server_receives_malformed_request(self, _read_request):
_read_request.side_effect = ValueError("read_request failed")

Expand All @@ -214,7 +214,7 @@ def test_server_receives_malformed_request(self, _read_request):
self.start_client()
self.stop_server()

@patch('websockets.client.read_response')
@unittest.mock.patch('websockets.client.read_response')
def test_client_receives_malformed_response(self, _read_response):
_read_response.side_effect = ValueError("read_response failed")

Expand All @@ -224,7 +224,7 @@ def test_client_receives_malformed_response(self, _read_response):
self.notice_connection_close()
self.stop_server()

@patch('websockets.client.build_request')
@unittest.mock.patch('websockets.client.build_request')
def test_client_sends_invalid_handshake_request(self, _build_request):
def wrong_build_request(set_header):
return '42'
Expand All @@ -235,7 +235,7 @@ def wrong_build_request(set_header):
self.start_client()
self.stop_server()

@patch('websockets.server.build_response')
@unittest.mock.patch('websockets.server.build_response')
def test_server_sends_invalid_handshake_response(self, _build_response):
def wrong_build_response(set_header, key):
return build_response(set_header, '42')
Expand All @@ -246,7 +246,7 @@ def wrong_build_response(set_header, key):
self.start_client()
self.stop_server()

@patch('websockets.client.read_response')
@unittest.mock.patch('websockets.client.read_response')
def test_server_does_not_switch_protocols(self, _read_response):
@asyncio.coroutine
def wrong_read_response(stream):
Expand All @@ -260,7 +260,7 @@ def wrong_read_response(stream):
self.notice_connection_close()
self.stop_server()

@patch('websockets.server.WebSocketServerProtocol.send')
@unittest.mock.patch('websockets.server.WebSocketServerProtocol.send')
def test_server_handler_crashes(self, send):
send.side_effect = ValueError("send failed")

Expand All @@ -275,7 +275,7 @@ def test_server_handler_crashes(self, send):
# Connection ends with an unexpected error.
self.assertEqual(self.client.close_code, 1011)

@patch('websockets.server.WebSocketServerProtocol.close')
@unittest.mock.patch('websockets.server.WebSocketServerProtocol.close')
def test_server_close_crashes(self, close):
close.side_effect = ValueError("close failed")

Expand Down
5 changes: 2 additions & 3 deletions websockets/test_framing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import asyncio
import io
import unittest

import asyncio

from .exceptions import WebSocketProtocolError, PayloadTooBig
from .exceptions import PayloadTooBig, WebSocketProtocolError
from .framing import *


Expand Down
2 changes: 1 addition & 1 deletion websockets/test_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .exceptions import InvalidHandshake
from .handshake import *
from .handshake import accept # private API
from .handshake import accept # private API


class HandshakeTests(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions websockets/test_http.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import unittest

import asyncio
import unittest

from .http import *
from .http import read_message # private API
from .http import read_message # private API


class HTTPTests(unittest.TestCase):
Expand Down
13 changes: 6 additions & 7 deletions websockets/test_protocol.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import asyncio
import functools
import unittest
import unittest.mock

import asyncio
from functools import partial

from .exceptions import InvalidState
from .framing import *
from .protocol import CLOSED, CLOSING, WebSocketCommonProtocol
Expand All @@ -25,14 +24,14 @@ def setUp(self):
side_effect=lambda: self.protocol.connection_lost(None))
self.protocol.connection_made(self.transport)

@property
def async(self):
return partial(asyncio.async, loop=self.loop)

def tearDown(self):
self.loop.close()
super().tearDown()

@property
def async(self):
return functools.partial(asyncio.async, loop=self.loop)

def feed(self, frame):
"""Feed a frame to the protocol."""
mask = not self.protocol.is_client
Expand Down

0 comments on commit 739f9d1

Please sign in to comment.