diff --git a/.coveragerc b/.coveragerc index ef6d66c..3f06bb6 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,12 +1,12 @@ [run] branch = True source = channels -omit = channels/tests/* +omit = tests/* [report] show_missing = True skip_covered = True -omit = channels/tests/* +omit = tests/* [html] directory = coverage_html @@ -21,4 +21,3 @@ django_18 = .tox/py27-django-19/lib/python2.7 .tox/py34-django-19/lib/python3.4 .tox/py35-django-19/lib/python3.5 - diff --git a/.travis.yml b/.travis.yml index 3886439..f38f5a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,12 @@ env: - DJANGO="Django>=1.9,<1.10" - DJANGO="Django>=1.10,<1.11" +cache: + directories: + - $HOME/.cache/pip/wheels + install: + - pip install -U pip wheel setuptools - pip install $DJANGO -e .[tests] - pip freeze diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..aae9579 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +recursive-exclude tests * diff --git a/channels/test/__init__.py b/channels/test/__init__.py new file mode 100644 index 0000000..0c957f3 --- /dev/null +++ b/channels/test/__init__.py @@ -0,0 +1,2 @@ +from .base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip +from .http import HttpClient # NOQA isort:skip diff --git a/channels/tests/base.py b/channels/test/base.py similarity index 100% rename from channels/tests/base.py rename to channels/test/base.py diff --git a/channels/tests/http.py b/channels/test/http.py similarity index 100% rename from channels/tests/http.py rename to channels/test/http.py diff --git a/channels/tests/__init__.py b/channels/tests/__init__.py index 0c957f3..27ae0e3 100644 --- a/channels/tests/__init__.py +++ b/channels/tests/__init__.py @@ -1,2 +1,9 @@ -from .base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip -from .http import HttpClient # NOQA isort:skip +import warnings + +warnings.warn( + "channels.tests package is deprecated. Use channels.test", + DeprecationWarning, +) + +from channels.test.base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip +from channels.test.http import HttpClient # NOQA isort:skip diff --git a/docs/testing.rst b/docs/testing.rst index efdfee5..1ac48bd 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -13,7 +13,7 @@ however, so you can easily write tests and check what your consumers are sending ChannelTestCase --------------- -If your tests inherit from the ``channels.tests.ChannelTestCase`` base class, +If your tests inherit from the ``channels.test.ChannelTestCase`` base class, whenever you run tests your channel layer will be swapped out for a captive in-memory layer, meaning you don't need an external server running to run tests. @@ -24,7 +24,7 @@ To inject a message onto the layer, simply call ``Channel.send()`` inside any test method on a ``ChannelTestCase`` subclass, like so:: from channels import Channel - from channels.tests import ChannelTestCase + from channels.test import ChannelTestCase class MyTests(ChannelTestCase): def test_a_thing(self): @@ -49,7 +49,7 @@ and post the square of it to the ``"result"`` channel:: from channels import Channel - from channels.tests import ChannelTestCase + from channels.test import ChannelTestCase class MyTests(ChannelTestCase): def test_a_thing(self): @@ -70,7 +70,7 @@ object from ``get_next_message`` to the constructor of the class. To test replie use the ``reply_channel`` property on the ``Message`` object. For example:: from channels import Channel - from channels.tests import ChannelTestCase + from channels.test import ChannelTestCase from myapp.consumers import MyConsumer @@ -95,7 +95,7 @@ the entire channel layer is flushed each time a test is run, so it's safe to do group adds and sends during a test. For example:: from channels import Group - from channels.tests import ChannelTestCase + from channels.test import ChannelTestCase class MyTests(ChannelTestCase): def test_a_thing(self): @@ -118,7 +118,7 @@ to run appointed consumer for the next message, ``receive`` to getting replies f Very often you may need to ``send`` and than call a consumer one by one, for this purpose use ``send_and_consume`` method:: - from channels.tests import ChannelTestCase, Client + from channels.test import ChannelTestCase, Client class MyTests(ChannelTestCase): @@ -146,7 +146,7 @@ For example:: # tests.py from channels import Group - from channels.tests import ChannelTestCase, HttpClient + from channels.test import ChannelTestCase, HttpClient class RoomsTests(ChannelTestCase): @@ -196,7 +196,7 @@ want to testing your consumers in more isolate and atomic way, it will be simpler with ``apply_routes`` contextmanager and decorator for your ``ChannelTestCase``. It takes list of routes that you want to use and overwrite existing routes:: - from channels.tests import ChannelTestCase, HttpClient, apply_routes + from channels.test import ChannelTestCase, HttpClient, apply_routes class MyTests(ChannelTestCase): @@ -220,7 +220,7 @@ make some changes with target model and check received message. Lets test ``IntegerValueBinding`` from :doc:`data binding ` with creating:: - from channels.tests import ChannelTestCase, HttpClient + from channels.test import ChannelTestCase, HttpClient from channels.signals import consumer_finished class TestIntegerValueBinding(ChannelTestCase): diff --git a/patchinator.py b/patchinator.py index fe787a1..661a659 100644 --- a/patchinator.py +++ b/patchinator.py @@ -121,9 +121,9 @@ global_transforms = [ Replacement(r"from channels import", r"from django.channels import"), Replacement(r"from channels.([a-zA-Z0-9_\.]+) import", r"from django.channels.\1 import"), Replacement(r"from .handler import", r"from django.core.handlers.asgi import"), - Replacement(r"from django.channels.tests import", r"from django.test.channels import"), + Replacement(r"from django.channels.test import", r"from django.test.channels import"), Replacement(r"from django.channels.handler import", r"from django.core.handlers.asgi import"), - Replacement(r"channels.tests.test_routing", r"channels_tests.test_routing"), + Replacement(r"tests.test_routing", r"channels_tests.test_routing"), Replacement(r"django.core.urlresolvers", r"django.urls"), ] @@ -201,22 +201,22 @@ class Patchinator(object): ), # Tests FileMap( - "channels/tests/base.py", "django/test/channels.py", python_transforms, + "channels/test/base.py", "django/test/channels.py", python_transforms, ), NewFile( "tests/channels_tests/__init__.py", ), FileMap( - "channels/tests/test_handler.py", "tests/channels_tests/test_handler.py", python_transforms, + "tests/test_handler.py", "tests/channels_tests/test_handler.py", python_transforms, ), FileMap( - "channels/tests/test_routing.py", "tests/channels_tests/test_routing.py", python_transforms, + "tests/test_routing.py", "tests/channels_tests/test_routing.py", python_transforms, ), FileMap( - "channels/tests/test_request.py", "tests/channels_tests/test_request.py", python_transforms, + "tests/test_request.py", "tests/channels_tests/test_request.py", python_transforms, ), FileMap( - "channels/tests/test_sessions.py", "tests/channels_tests/test_sessions.py", python_transforms, + "tests/test_sessions.py", "tests/channels_tests/test_sessions.py", python_transforms, ), # Docs FileMap( diff --git a/runtests.py b/runtests.py index 1d60d79..925b27b 100755 --- a/runtests.py +++ b/runtests.py @@ -7,9 +7,9 @@ from django.conf import settings from django.test.utils import get_runner if __name__ == "__main__": - os.environ['DJANGO_SETTINGS_MODULE'] = "channels.tests.settings" + os.environ['DJANGO_SETTINGS_MODULE'] = "tests.settings" django.setup() TestRunner = get_runner(settings) test_runner = TestRunner() - failures = test_runner.run_tests(["channels.tests"]) + failures = test_runner.run_tests(["tests"]) sys.exit(bool(failures)) diff --git a/setup.py b/setup.py index e69f558..e1adedd 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( author_email='foundation@djangoproject.com', description="Brings event-driven capabilities to Django with a channel system. Django 1.8 and up only.", license='BSD', - packages=find_packages(), + packages=find_packages(exclude=['tests']), include_package_data=True, install_requires=[ 'Django>=1.8', @@ -17,7 +17,12 @@ setup( 'daphne>=1.0.0', ], extras_require={ - 'tests': ['coverage', 'mock', 'tox', 'flake8>=2.0,<3.0', 'isort'] + 'tests': [ + 'coverage', + 'mock ; python_version < "3.0"', + 'flake8>=2.0,<3.0', + 'isort', + ] }, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/channels/tests/a_file b/tests/a_file similarity index 100% rename from channels/tests/a_file rename to tests/a_file diff --git a/channels/tests/models.py b/tests/models.py similarity index 100% rename from channels/tests/models.py rename to tests/models.py diff --git a/channels/tests/settings.py b/tests/settings.py similarity index 84% rename from channels/tests/settings.py rename to tests/settings.py index 47fc407..bebbd2a 100644 --- a/channels/tests/settings.py +++ b/tests/settings.py @@ -7,7 +7,7 @@ INSTALLED_APPS = ( 'django.contrib.admin', 'channels', 'channels.delay', - 'channels.tests' + 'tests', ) DATABASES = { @@ -22,7 +22,7 @@ CHANNEL_LAYERS = { 'ROUTING': [], }, 'fake_channel': { - 'BACKEND': 'channels.tests.test_management.FakeChannelLayer', + 'BACKEND': 'tests.test_management.FakeChannelLayer', 'ROUTING': [], } } diff --git a/channels/tests/test_binding.py b/tests/test_binding.py similarity index 99% rename from channels/tests/test_binding.py rename to tests/test_binding.py index edd5126..4f86f50 100644 --- a/channels/tests/test_binding.py +++ b/tests/test_binding.py @@ -6,7 +6,8 @@ from channels import route from channels.binding.base import CREATE, DELETE, UPDATE from channels.binding.websockets import WebsocketBinding from channels.generic.websockets import WebsocketDemultiplexer -from channels.tests import ChannelTestCase, HttpClient, apply_routes, models +from channels.test import ChannelTestCase, HttpClient, apply_routes +from tests import models User = get_user_model() diff --git a/channels/tests/test_delay.py b/tests/test_delay.py similarity index 98% rename from channels/tests/test_delay.py rename to tests/test_delay.py index 8d22d0f..08cb194 100644 --- a/channels/tests/test_delay.py +++ b/tests/test_delay.py @@ -8,7 +8,7 @@ from django.utils import timezone from channels import DEFAULT_CHANNEL_LAYER, Channel, channel_layers from channels.delay.models import DelayedMessage from channels.delay.worker import Worker -from channels.tests import ChannelTestCase +from channels.test import ChannelTestCase try: from unittest import mock diff --git a/channels/tests/test_generic.py b/tests/test_generic.py similarity index 98% rename from channels/tests/test_generic.py rename to tests/test_generic.py index 2938598..1751ecf 100644 --- a/channels/tests/test_generic.py +++ b/tests/test_generic.py @@ -5,7 +5,7 @@ from django.test import override_settings from channels import route_class from channels.exceptions import SendNotAvailableOnDemultiplexer from channels.generic import BaseConsumer, websockets -from channels.tests import ChannelTestCase, Client, HttpClient, apply_routes +from channels.test import ChannelTestCase, Client, HttpClient, apply_routes @override_settings(SESSION_ENGINE="django.contrib.sessions.backends.cache") diff --git a/channels/tests/test_handler.py b/tests/test_handler.py similarity index 99% rename from channels/tests/test_handler.py rename to tests/test_handler.py index 0c096cc..ffecf8b 100644 --- a/channels/tests/test_handler.py +++ b/tests/test_handler.py @@ -9,7 +9,7 @@ from six import BytesIO from channels import Channel from channels.handler import AsgiHandler -from channels.tests import ChannelTestCase +from channels.test import ChannelTestCase class FakeAsgiHandler(AsgiHandler): diff --git a/channels/tests/test_http.py b/tests/test_http.py similarity index 89% rename from channels/tests/test_http.py rename to tests/test_http.py index 1c7c29a..0ec9089 100644 --- a/channels/tests/test_http.py +++ b/tests/test_http.py @@ -2,8 +2,7 @@ from __future__ import unicode_literals from django.http.cookie import parse_cookie -from channels.tests import ChannelTestCase -from channels.tests.http import HttpClient +from channels.test import ChannelTestCase, HttpClient class HttpClientTests(ChannelTestCase): diff --git a/channels/tests/test_management.py b/tests/test_management.py similarity index 100% rename from channels/tests/test_management.py rename to tests/test_management.py diff --git a/channels/tests/test_request.py b/tests/test_request.py similarity index 99% rename from channels/tests/test_request.py rename to tests/test_request.py index aea1f47..39702ca 100644 --- a/channels/tests/test_request.py +++ b/tests/test_request.py @@ -5,7 +5,7 @@ from django.utils import six from channels import Channel from channels.exceptions import RequestAborted, RequestTimeout from channels.handler import AsgiRequest -from channels.tests import ChannelTestCase +from channels.test import ChannelTestCase class RequestTests(ChannelTestCase): diff --git a/channels/tests/test_routing.py b/tests/test_routing.py similarity index 94% rename from channels/tests/test_routing.py rename to tests/test_routing.py index 5a6145d..c246347 100644 --- a/channels/tests/test_routing.py +++ b/tests/test_routing.py @@ -168,7 +168,7 @@ class RoutingTests(SimpleTestCase): Tests inclusion without a prefix """ router = Router([ - include("channels.tests.test_routing.chatroom_routing"), + include("tests.test_routing.chatroom_routing"), ]) self.assertRoute( router, @@ -196,7 +196,7 @@ class RoutingTests(SimpleTestCase): Tests route_class with/without prefix """ router = Router([ - include("channels.tests.test_routing.class_routing"), + include("tests.test_routing.class_routing"), ]) self.assertRoute( router, @@ -222,7 +222,7 @@ class RoutingTests(SimpleTestCase): Tests inclusion with a prefix """ router = Router([ - include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P[0-9]+)"), + include("tests.test_routing.chatroom_routing", path="^/ws/v(?P[0-9]+)"), ]) self.assertRoute( router, @@ -252,7 +252,7 @@ class RoutingTests(SimpleTestCase): ) # Check it works without the ^s too. router = Router([ - include("channels.tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P[0-9]+)"), + include("tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P[0-9]+)"), ]) self.assertRoute( router, @@ -279,7 +279,7 @@ class RoutingTests(SimpleTestCase): # Unicode patterns, byte message router = Router([ route("websocket.connect", consumer_1, path="^/foo/"), - include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P[0-9]+)"), + include("tests.test_routing.chatroom_routing", path="^/ws/v(?P[0-9]+)"), ]) self.assertRoute( router, @@ -303,7 +303,7 @@ class RoutingTests(SimpleTestCase): # Byte patterns, unicode message router = Router([ route("websocket.connect", consumer_1, path=b"^/foo/"), - include("channels.tests.test_routing.chatroom_routing", path=b"^/ws/v(?P[0-9]+)"), + include("tests.test_routing.chatroom_routing", path=b"^/ws/v(?P[0-9]+)"), ]) self.assertRoute( router, diff --git a/channels/tests/test_sessions.py b/tests/test_sessions.py similarity index 99% rename from channels/tests/test_sessions.py rename to tests/test_sessions.py index 6af6edc..0f8bf00 100644 --- a/channels/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -8,7 +8,7 @@ from channels.message import Message from channels.sessions import ( channel_and_http_session, channel_session, enforce_ordering, http_session, session_for_reply_channel, ) -from channels.tests import ChannelTestCase +from channels.test import ChannelTestCase @override_settings(SESSION_ENGINE="django.contrib.sessions.backends.cache") diff --git a/channels/tests/test_worker.py b/tests/test_worker.py similarity index 99% rename from channels/tests/test_worker.py rename to tests/test_worker.py index 064f471..345b287 100644 --- a/channels/tests/test_worker.py +++ b/tests/test_worker.py @@ -6,7 +6,7 @@ from channels import DEFAULT_CHANNEL_LAYER, Channel, route from channels.asgi import channel_layers from channels.exceptions import ConsumeLater from channels.signals import worker_ready -from channels.tests import ChannelTestCase +from channels.test import ChannelTestCase from channels.worker import Worker, WorkerGroup try: