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:
Artem Malyshev 2017-02-16 19:22:23 +01:00 committed by Andrew Godwin
parent 13472369eb
commit 672de2b2a3
25 changed files with 61 additions and 42 deletions

View File

@ -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

View File

@ -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

1
MANIFEST.in Normal file
View File

@ -0,0 +1 @@
recursive-exclude tests *

View File

@ -0,0 +1,2 @@
from .base import TransactionChannelTestCase, ChannelTestCase, Client, apply_routes # NOQA isort:skip
from .http import HttpClient # NOQA isort:skip

View File

@ -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

View File

@ -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 <binding>`
with creating::
from channels.tests import ChannelTestCase, HttpClient
from channels.test import ChannelTestCase, HttpClient
from channels.signals import consumer_finished
class TestIntegerValueBinding(ChannelTestCase):

View File

@ -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(

View File

@ -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))

View File

@ -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',

0
tests/__init__.py Normal file
View File

View File

@ -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': [],
}
}

View File

@ -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()

View File

@ -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

View File

@ -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")

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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<version>[0-9]+)"),
include("tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[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<version>[0-9]+)"),
include("tests.test_routing.chatroom_routing_nolinestart", path="/ws/v(?P<version>[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<version>[0-9]+)"),
include("tests.test_routing.chatroom_routing", path="^/ws/v(?P<version>[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<version>[0-9]+)"),
include("tests.test_routing.chatroom_routing", path=b"^/ws/v(?P<version>[0-9]+)"),
])
self.assertRoute(
router,

View File

@ -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")

View File

@ -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: