mirror of
https://github.com/django/daphne.git
synced 2025-07-14 18:02:17 +03:00
Separate tests into own directory. (#531)
* Move project tests to its own directory. * Install mock test dependency for Python2 only. * Do not install tox inside tox environment. * Exclude tests from sdist. * Use recent pip on Travis-CI.
This commit is contained in:
parent
13472369eb
commit
672de2b2a3
|
@ -1,12 +1,12 @@
|
||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = channels
|
source = channels
|
||||||
omit = channels/tests/*
|
omit = tests/*
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
show_missing = True
|
show_missing = True
|
||||||
skip_covered = True
|
skip_covered = True
|
||||||
omit = channels/tests/*
|
omit = tests/*
|
||||||
|
|
||||||
[html]
|
[html]
|
||||||
directory = coverage_html
|
directory = coverage_html
|
||||||
|
@ -21,4 +21,3 @@ django_18 =
|
||||||
.tox/py27-django-19/lib/python2.7
|
.tox/py27-django-19/lib/python2.7
|
||||||
.tox/py34-django-19/lib/python3.4
|
.tox/py34-django-19/lib/python3.4
|
||||||
.tox/py35-django-19/lib/python3.5
|
.tox/py35-django-19/lib/python3.5
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,12 @@ env:
|
||||||
- DJANGO="Django>=1.9,<1.10"
|
- DJANGO="Django>=1.9,<1.10"
|
||||||
- DJANGO="Django>=1.10,<1.11"
|
- DJANGO="Django>=1.10,<1.11"
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.cache/pip/wheels
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
- pip install -U pip wheel setuptools
|
||||||
- pip install $DJANGO -e .[tests]
|
- pip install $DJANGO -e .[tests]
|
||||||
- pip freeze
|
- pip freeze
|
||||||
|
|
||||||
|
|
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
recursive-exclude tests *
|
2
channels/test/__init__.py
Normal file
2
channels/test/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
from .base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip
|
||||||
|
from .http import HttpClient # NOQA isort:skip
|
|
@ -1,2 +1,9 @@
|
||||||
from .base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip
|
import warnings
|
||||||
from .http import HttpClient # NOQA isort:skip
|
|
||||||
|
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
|
||||||
|
|
|
@ -13,7 +13,7 @@ however, so you can easily write tests and check what your consumers are sending
|
||||||
ChannelTestCase
|
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
|
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.
|
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::
|
any test method on a ``ChannelTestCase`` subclass, like so::
|
||||||
|
|
||||||
from channels import Channel
|
from channels import Channel
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
class MyTests(ChannelTestCase):
|
class MyTests(ChannelTestCase):
|
||||||
def test_a_thing(self):
|
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 import Channel
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
class MyTests(ChannelTestCase):
|
class MyTests(ChannelTestCase):
|
||||||
def test_a_thing(self):
|
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::
|
use the ``reply_channel`` property on the ``Message`` object. For example::
|
||||||
|
|
||||||
from channels import Channel
|
from channels import Channel
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
from myapp.consumers import MyConsumer
|
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::
|
do group adds and sends during a test. For example::
|
||||||
|
|
||||||
from channels import Group
|
from channels import Group
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
class MyTests(ChannelTestCase):
|
class MyTests(ChannelTestCase):
|
||||||
def test_a_thing(self):
|
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
|
Very often you may need to ``send`` and than call a consumer one by one, for this
|
||||||
purpose use ``send_and_consume`` method::
|
purpose use ``send_and_consume`` method::
|
||||||
|
|
||||||
from channels.tests import ChannelTestCase, Client
|
from channels.test import ChannelTestCase, Client
|
||||||
|
|
||||||
class MyTests(ChannelTestCase):
|
class MyTests(ChannelTestCase):
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ For example::
|
||||||
|
|
||||||
# tests.py
|
# tests.py
|
||||||
from channels import Group
|
from channels import Group
|
||||||
from channels.tests import ChannelTestCase, HttpClient
|
from channels.test import ChannelTestCase, HttpClient
|
||||||
|
|
||||||
|
|
||||||
class RoomsTests(ChannelTestCase):
|
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``.
|
simpler with ``apply_routes`` contextmanager and decorator for your ``ChannelTestCase``.
|
||||||
It takes list of routes that you want to use and overwrite existing routes::
|
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):
|
class MyTests(ChannelTestCase):
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ make some changes with target model and check received message.
|
||||||
Lets test ``IntegerValueBinding`` from :doc:`data binding <binding>`
|
Lets test ``IntegerValueBinding`` from :doc:`data binding <binding>`
|
||||||
with creating::
|
with creating::
|
||||||
|
|
||||||
from channels.tests import ChannelTestCase, HttpClient
|
from channels.test import ChannelTestCase, HttpClient
|
||||||
from channels.signals import consumer_finished
|
from channels.signals import consumer_finished
|
||||||
|
|
||||||
class TestIntegerValueBinding(ChannelTestCase):
|
class TestIntegerValueBinding(ChannelTestCase):
|
||||||
|
|
|
@ -121,9 +121,9 @@ global_transforms = [
|
||||||
Replacement(r"from channels import", r"from django.channels import"),
|
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 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 .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"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"),
|
Replacement(r"django.core.urlresolvers", r"django.urls"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -201,22 +201,22 @@ class Patchinator(object):
|
||||||
),
|
),
|
||||||
# Tests
|
# Tests
|
||||||
FileMap(
|
FileMap(
|
||||||
"channels/tests/base.py", "django/test/channels.py", python_transforms,
|
"channels/test/base.py", "django/test/channels.py", python_transforms,
|
||||||
),
|
),
|
||||||
NewFile(
|
NewFile(
|
||||||
"tests/channels_tests/__init__.py",
|
"tests/channels_tests/__init__.py",
|
||||||
),
|
),
|
||||||
FileMap(
|
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(
|
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(
|
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(
|
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
|
# Docs
|
||||||
FileMap(
|
FileMap(
|
||||||
|
|
|
@ -7,9 +7,9 @@ from django.conf import settings
|
||||||
from django.test.utils import get_runner
|
from django.test.utils import get_runner
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = "channels.tests.settings"
|
os.environ['DJANGO_SETTINGS_MODULE'] = "tests.settings"
|
||||||
django.setup()
|
django.setup()
|
||||||
TestRunner = get_runner(settings)
|
TestRunner = get_runner(settings)
|
||||||
test_runner = TestRunner()
|
test_runner = TestRunner()
|
||||||
failures = test_runner.run_tests(["channels.tests"])
|
failures = test_runner.run_tests(["tests"])
|
||||||
sys.exit(bool(failures))
|
sys.exit(bool(failures))
|
||||||
|
|
9
setup.py
9
setup.py
|
@ -9,7 +9,7 @@ setup(
|
||||||
author_email='foundation@djangoproject.com',
|
author_email='foundation@djangoproject.com',
|
||||||
description="Brings event-driven capabilities to Django with a channel system. Django 1.8 and up only.",
|
description="Brings event-driven capabilities to Django with a channel system. Django 1.8 and up only.",
|
||||||
license='BSD',
|
license='BSD',
|
||||||
packages=find_packages(),
|
packages=find_packages(exclude=['tests']),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'Django>=1.8',
|
'Django>=1.8',
|
||||||
|
@ -17,7 +17,12 @@ setup(
|
||||||
'daphne>=1.0.0',
|
'daphne>=1.0.0',
|
||||||
],
|
],
|
||||||
extras_require={
|
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=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
|
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
|
@ -7,7 +7,7 @@ INSTALLED_APPS = (
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'channels',
|
'channels',
|
||||||
'channels.delay',
|
'channels.delay',
|
||||||
'channels.tests'
|
'tests',
|
||||||
)
|
)
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
|
@ -22,7 +22,7 @@ CHANNEL_LAYERS = {
|
||||||
'ROUTING': [],
|
'ROUTING': [],
|
||||||
},
|
},
|
||||||
'fake_channel': {
|
'fake_channel': {
|
||||||
'BACKEND': 'channels.tests.test_management.FakeChannelLayer',
|
'BACKEND': 'tests.test_management.FakeChannelLayer',
|
||||||
'ROUTING': [],
|
'ROUTING': [],
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,8 @@ from channels import route
|
||||||
from channels.binding.base import CREATE, DELETE, UPDATE
|
from channels.binding.base import CREATE, DELETE, UPDATE
|
||||||
from channels.binding.websockets import WebsocketBinding
|
from channels.binding.websockets import WebsocketBinding
|
||||||
from channels.generic.websockets import WebsocketDemultiplexer
|
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()
|
User = get_user_model()
|
||||||
|
|
|
@ -8,7 +8,7 @@ from django.utils import timezone
|
||||||
from channels import DEFAULT_CHANNEL_LAYER, Channel, channel_layers
|
from channels import DEFAULT_CHANNEL_LAYER, Channel, channel_layers
|
||||||
from channels.delay.models import DelayedMessage
|
from channels.delay.models import DelayedMessage
|
||||||
from channels.delay.worker import Worker
|
from channels.delay.worker import Worker
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from unittest import mock
|
from unittest import mock
|
|
@ -5,7 +5,7 @@ from django.test import override_settings
|
||||||
from channels import route_class
|
from channels import route_class
|
||||||
from channels.exceptions import SendNotAvailableOnDemultiplexer
|
from channels.exceptions import SendNotAvailableOnDemultiplexer
|
||||||
from channels.generic import BaseConsumer, websockets
|
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")
|
@override_settings(SESSION_ENGINE="django.contrib.sessions.backends.cache")
|
|
@ -9,7 +9,7 @@ from six import BytesIO
|
||||||
|
|
||||||
from channels import Channel
|
from channels import Channel
|
||||||
from channels.handler import AsgiHandler
|
from channels.handler import AsgiHandler
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
|
|
||||||
class FakeAsgiHandler(AsgiHandler):
|
class FakeAsgiHandler(AsgiHandler):
|
|
@ -2,8 +2,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.http.cookie import parse_cookie
|
from django.http.cookie import parse_cookie
|
||||||
|
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase, HttpClient
|
||||||
from channels.tests.http import HttpClient
|
|
||||||
|
|
||||||
|
|
||||||
class HttpClientTests(ChannelTestCase):
|
class HttpClientTests(ChannelTestCase):
|
|
@ -5,7 +5,7 @@ from django.utils import six
|
||||||
from channels import Channel
|
from channels import Channel
|
||||||
from channels.exceptions import RequestAborted, RequestTimeout
|
from channels.exceptions import RequestAborted, RequestTimeout
|
||||||
from channels.handler import AsgiRequest
|
from channels.handler import AsgiRequest
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
|
|
||||||
|
|
||||||
class RequestTests(ChannelTestCase):
|
class RequestTests(ChannelTestCase):
|
|
@ -168,7 +168,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
Tests inclusion without a prefix
|
Tests inclusion without a prefix
|
||||||
"""
|
"""
|
||||||
router = Router([
|
router = Router([
|
||||||
include("channels.tests.test_routing.chatroom_routing"),
|
include("tests.test_routing.chatroom_routing"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
||||||
|
@ -196,7 +196,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
Tests route_class with/without prefix
|
Tests route_class with/without prefix
|
||||||
"""
|
"""
|
||||||
router = Router([
|
router = Router([
|
||||||
include("channels.tests.test_routing.class_routing"),
|
include("tests.test_routing.class_routing"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
||||||
|
@ -222,7 +222,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
Tests inclusion with a prefix
|
Tests inclusion with a prefix
|
||||||
"""
|
"""
|
||||||
router = Router([
|
router = Router([
|
||||||
include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"),
|
include("tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
||||||
|
@ -252,7 +252,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
)
|
)
|
||||||
# Check it works without the ^s too.
|
# Check it works without the ^s too.
|
||||||
router = Router([
|
router = Router([
|
||||||
include("channels.tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P<version>[0-9]+)"),
|
include("tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P<version>[0-9]+)"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
||||||
|
@ -279,7 +279,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
# Unicode patterns, byte message
|
# Unicode patterns, byte message
|
||||||
router = Router([
|
router = Router([
|
||||||
route("websocket.connect", consumer_1, path="^/foo/"),
|
route("websocket.connect", consumer_1, path="^/foo/"),
|
||||||
include("channels.tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"),
|
include("tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[0-9]+)"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
||||||
|
@ -303,7 +303,7 @@ class RoutingTests(SimpleTestCase):
|
||||||
# Byte patterns, unicode message
|
# Byte patterns, unicode message
|
||||||
router = Router([
|
router = Router([
|
||||||
route("websocket.connect", consumer_1, path=b"^/foo/"),
|
route("websocket.connect", consumer_1, path=b"^/foo/"),
|
||||||
include("channels.tests.test_routing.chatroom_routing", path=b"^/ws/v(?P<version>[0-9]+)"),
|
include("tests.test_routing.chatroom_routing", path=b"^/ws/v(?P<version>[0-9]+)"),
|
||||||
])
|
])
|
||||||
self.assertRoute(
|
self.assertRoute(
|
||||||
router,
|
router,
|
|
@ -8,7 +8,7 @@ from channels.message import Message
|
||||||
from channels.sessions import (
|
from channels.sessions import (
|
||||||
channel_and_http_session, channel_session, enforce_ordering, http_session, session_for_reply_channel,
|
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")
|
@override_settings(SESSION_ENGINE="django.contrib.sessions.backends.cache")
|
|
@ -6,7 +6,7 @@ from channels import DEFAULT_CHANNEL_LAYER, Channel, route
|
||||||
from channels.asgi import channel_layers
|
from channels.asgi import channel_layers
|
||||||
from channels.exceptions import ConsumeLater
|
from channels.exceptions import ConsumeLater
|
||||||
from channels.signals import worker_ready
|
from channels.signals import worker_ready
|
||||||
from channels.tests import ChannelTestCase
|
from channels.test import ChannelTestCase
|
||||||
from channels.worker import Worker, WorkerGroup
|
from channels.worker import Worker, WorkerGroup
|
||||||
|
|
||||||
try:
|
try:
|
Loading…
Reference in New Issue
Block a user