From cf94ec01fa0d2979fd413d0d81d790398bfee527 Mon Sep 17 00:00:00 2001 From: Maik Hoepfel Date: Tue, 31 Jan 2017 02:24:17 +0100 Subject: [PATCH] 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 --- .gitignore | 1 + .travis.yml | 15 +++++++++++---- README.rst | 13 +++++++++++++ daphne/server.py | 4 ++-- daphne/tests/test_http.py | 14 +++++++------- daphne/tests/test_ws.py | 2 +- setup.py | 3 ++- tox.ini | 8 ++++++++ 8 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index bbe7d22..33dfc28 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ dist/ build/ +/.tox diff --git a/.travis.yml b/.travis.yml index 6f34248..5ee9ae1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,16 @@ sudo: false + language: python + python: - "2.7" + - "3.4" - "3.5" -install: - - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install unittest2; fi - - pip install asgiref twisted autobahn -script: if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then python -m unittest2; else python -m unittest; fi + +env: + - TWISTED_RELEASE="twisted" + - TWISTED_RELEASE="twisted==16.0.0" + +install: pip install $TWISTED_RELEASE -e . + +script: python -m unittest discover diff --git a/README.rst b/README.rst index 0cf9b92..a31b571 100644 --- a/README.rst +++ b/README.rst @@ -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 +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 `_. +That also contains advice on how to set up the development environment and run the tests. + Maintenance and Security ------------------------ diff --git a/daphne/server.py b/daphne/server.py index 4f79fd2..7b05a55 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -115,7 +115,7 @@ class Server(object): if channels: delay = 0.01 try: - channel, message = self.channel_layer.receive_many(channels, block=False) + channel, message = self.channel_layer.receive(channels, block=False) except Exception as e: logger.error('Error at trying to receive messages: %s' % e) delay = 5.00 @@ -142,7 +142,7 @@ class Server(object): channels = self.factory.reply_channels() if channels: try: - channel, message = yield self.channel_layer.receive_many_twisted(channels) + channel, message = yield self.channel_layer.receive_twisted(channels) except Exception as e: logger.error('Error at trying to receive messages: %s' % e) yield self.sleep(5.00) diff --git a/daphne/tests/test_http.py b/daphne/tests/test_http.py index de9bef3..c9f5c7b 100644 --- a/daphne/tests/test_http.py +++ b/daphne/tests/test_http.py @@ -30,7 +30,7 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # 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['method'], "GET") self.assertEqual(message['scheme'], "http") @@ -64,7 +64,7 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # 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") def test_http_disconnect_sets_path_key(self): @@ -78,7 +78,7 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # Get the request message - _, message = self.channel_layer.receive_many(["http.request"]) + _, message = self.channel_layer.receive(["http.request"]) # Send back an example response self.factory.dispatch_reply( @@ -91,7 +91,7 @@ class TestHTTPProtocol(TestCase): ) # 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-à/") def test_x_forwarded_for_ignored(self): @@ -106,7 +106,7 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # 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]) def test_x_forwarded_for_parsed(self): @@ -123,7 +123,7 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # 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]) def test_x_forwarded_for_port_missing(self): @@ -139,5 +139,5 @@ class TestHTTPProtocol(TestCase): b"\r\n" ) # 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]) diff --git a/daphne/tests/test_ws.py b/daphne/tests/test_ws.py index 01e64d1..c534479 100644 --- a/daphne/tests/test_ws.py +++ b/daphne/tests/test_ws.py @@ -33,7 +33,7 @@ class TestWebSocketProtocol(TestCase): b"\r\n" ) # 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['query_string'], "") self.assertEqual( diff --git a/setup.py b/setup.py index 462cece..e5bf8a6 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( packages=find_packages() + ['twisted.plugins'], include_package_data=True, install_requires=[ - 'asgiref>=0.13', + 'asgiref>=1.0.0', 'twisted>=16.0', 'autobahn>=0.12', ], @@ -40,6 +40,7 @@ setup( 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Topic :: Internet :: WWW/HTTP', ], diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7554262 --- /dev/null +++ b/tox.ini @@ -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