Test against Python 3.4 and multiple Twisted versions (#75)

* Test against Python 3.4 and multiple Twisted versions

This commit adds tox to be able to test against different dependencies
locally. We agreed that Python 3.4 should be supported across all Channels
projects, so it is also added with this commit.

Furthermore, I think it makes sense to support a broad range of Twisted
releases, as users of daphne are not unlikely to have other Twisted code
running. It's not feasible to test against all releases since 16.0, and
it would require constant maintenance to add new releases as they come
out. So I opted to keep things simple for now, and only test against the
oldest supported and the current Twisted release.

I did consider @jpic's great idea from
https://github.com/django/daphne/pull/19 to just use tox to avoid having
to duplicate the dependency matrix. But it does lead to slower test runs
as it bypasses Travis' caching, and is slightly more verbose.

* Require asgiref 1.0 and use receive instead of receive_many

As both daphne and asgiref had a 1.0 release, I think it makes sense to
require the presumably more stable asgiref 1.0. It's also a good
occasion to fix the deprecation warnings when running the tests by
switching to receive instead of receive_many.

* Document supported Python and Twisted versions
This commit is contained in:
Maik Hoepfel 2017-01-31 02:24:17 +01:00 committed by Andrew Godwin
parent 07dd777ef1
commit cf94ec01fa
8 changed files with 45 additions and 15 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
__pycache__ __pycache__
dist/ dist/
build/ build/
/.tox

View File

@ -1,9 +1,16 @@
sudo: false sudo: false
language: python language: python
python: python:
- "2.7" - "2.7"
- "3.4"
- "3.5" - "3.5"
install:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install unittest2; fi env:
- pip install asgiref twisted autobahn - TWISTED_RELEASE="twisted"
script: if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then python -m unittest2; else python -m unittest; fi - TWISTED_RELEASE="twisted==16.0.0"
install: pip install $TWISTED_RELEASE -e .
script: python -m unittest discover

View File

@ -67,6 +67,19 @@ should start with a slash, but not end with one; for example::
daphne --root-path=/forum django_project.asgi:channel_layer daphne --root-path=/forum django_project.asgi:channel_layer
Dependencies
------------
All Channels projects currently support Python 2.7, 3.4 and 3.5. `daphne` requires Twisted 16.0 or
greater.
Contributing
------------
Please refer to the
`main Channels contributing docs <https://github.com/django/channels/blob/master/CONTRIBUTING.rst>`_.
That also contains advice on how to set up the development environment and run the tests.
Maintenance and Security Maintenance and Security
------------------------ ------------------------

View File

@ -115,7 +115,7 @@ class Server(object):
if channels: if channels:
delay = 0.01 delay = 0.01
try: try:
channel, message = self.channel_layer.receive_many(channels, block=False) channel, message = self.channel_layer.receive(channels, block=False)
except Exception as e: except Exception as e:
logger.error('Error at trying to receive messages: %s' % e) logger.error('Error at trying to receive messages: %s' % e)
delay = 5.00 delay = 5.00
@ -142,7 +142,7 @@ class Server(object):
channels = self.factory.reply_channels() channels = self.factory.reply_channels()
if channels: if channels:
try: try:
channel, message = yield self.channel_layer.receive_many_twisted(channels) channel, message = yield self.channel_layer.receive_twisted(channels)
except Exception as e: except Exception as e:
logger.error('Error at trying to receive messages: %s' % e) logger.error('Error at trying to receive messages: %s' % e)
yield self.sleep(5.00) yield self.sleep(5.00)

View File

@ -30,7 +30,7 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer # Get the resulting message off of the channel layer
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
self.assertEqual(message['http_version'], "1.1") self.assertEqual(message['http_version'], "1.1")
self.assertEqual(message['method'], "GET") self.assertEqual(message['method'], "GET")
self.assertEqual(message['scheme'], "http") self.assertEqual(message['scheme'], "http")
@ -64,7 +64,7 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer, check root_path # Get the resulting message off of the channel layer, check root_path
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
self.assertEqual(message['root_path'], "/foobar /bar") self.assertEqual(message['root_path'], "/foobar /bar")
def test_http_disconnect_sets_path_key(self): def test_http_disconnect_sets_path_key(self):
@ -78,7 +78,7 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the request message # Get the request message
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
# Send back an example response # Send back an example response
self.factory.dispatch_reply( self.factory.dispatch_reply(
@ -91,7 +91,7 @@ class TestHTTPProtocol(TestCase):
) )
# Get the disconnection notification # Get the disconnection notification
_, disconnect_message = self.channel_layer.receive_many(["http.disconnect"]) _, disconnect_message = self.channel_layer.receive(["http.disconnect"])
self.assertEqual(disconnect_message['path'], "/te st-à/") self.assertEqual(disconnect_message['path'], "/te st-à/")
def test_x_forwarded_for_ignored(self): def test_x_forwarded_for_ignored(self):
@ -106,7 +106,7 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer # Get the resulting message off of the channel layer
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
self.assertEqual(message['client'], ['192.168.1.1', 54321]) self.assertEqual(message['client'], ['192.168.1.1', 54321])
def test_x_forwarded_for_parsed(self): def test_x_forwarded_for_parsed(self):
@ -123,7 +123,7 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer # Get the resulting message off of the channel layer
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
self.assertEqual(message['client'], ['10.1.2.3', 80]) self.assertEqual(message['client'], ['10.1.2.3', 80])
def test_x_forwarded_for_port_missing(self): def test_x_forwarded_for_port_missing(self):
@ -139,5 +139,5 @@ class TestHTTPProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer # Get the resulting message off of the channel layer
_, message = self.channel_layer.receive_many(["http.request"]) _, message = self.channel_layer.receive(["http.request"])
self.assertEqual(message['client'], ['10.1.2.3', 0]) self.assertEqual(message['client'], ['10.1.2.3', 0])

View File

@ -33,7 +33,7 @@ class TestWebSocketProtocol(TestCase):
b"\r\n" b"\r\n"
) )
# Get the resulting message off of the channel layer # Get the resulting message off of the channel layer
_, message = self.channel_layer.receive_many(["websocket.connect"]) _, message = self.channel_layer.receive(["websocket.connect"])
self.assertEqual(message['path'], "/chat") self.assertEqual(message['path'], "/chat")
self.assertEqual(message['query_string'], "") self.assertEqual(message['query_string'], "")
self.assertEqual( self.assertEqual(

View File

@ -23,7 +23,7 @@ setup(
packages=find_packages() + ['twisted.plugins'], packages=find_packages() + ['twisted.plugins'],
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'asgiref>=0.13', 'asgiref>=1.0.0',
'twisted>=16.0', 'twisted>=16.0',
'autobahn>=0.12', 'autobahn>=0.12',
], ],
@ -40,6 +40,7 @@ setup(
'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP',
], ],

8
tox.ini Normal file
View File

@ -0,0 +1,8 @@
# We test against the oldest supported Twisted release, and the current release.
[tox]
envlist = py{27,34,35}-twisted-{old,new}
[testenv]
deps =
twisted-old: twisted==16.0.0
commands = python -m unittest discover