diff --git a/.gitignore b/.gitignore index 8b3cba2..72302f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ storage.db storage.json *.dca .eggs/ +.cache/ # Documentation stuff docs/api/ diff --git a/.travis.yml b/.travis.yml index 4e6a402..ec028e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ python: - '3.4' - '3.5' - '3.6' - - 'nightly' + +install: + - pip install -U pip setuptools pytest script: 'python setup.py test' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8f214ee --- /dev/null +++ b/setup.cfg @@ -0,0 +1,5 @@ +[aliases] +test=pytest + +[tool:pytest] +python_files = tests/*.py diff --git a/setup.py b/setup.py index 7d6cc57..aa2d6fb 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,8 @@ setup( install_requires=requirements, extras_require=extras_require, test_suite='tests', + setup_requires=['pytest-runner==2.11.1'], + tests_require=['pytest==3.1.3', 'pytest-benchmark==3.1.0a2'], classifiers=[ 'Development Status :: 4 - Beta', 'License :: OSI Approved :: MIT License', diff --git a/tests/api/__init__.py b/tests/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_reason.py b/tests/api/reason.py similarity index 76% rename from tests/test_reason.py rename to tests/api/reason.py index 4582467..cd9c5fa 100644 --- a/tests/test_reason.py +++ b/tests/api/reason.py @@ -1,18 +1,18 @@ from unittest import TestCase +from tests.utils import APIClient + class TestReason(TestCase): def test_set_unicode_reason(self): - from tests.utils import TestAPIClient - api = TestAPIClient() + api = APIClient() api.guilds_channels_modify(1, 2, 3, reason=u'yo \U0001F4BF test') _, kwargs = api.http.calls[0] self.assertEqual(kwargs['headers']['X-Audit-Log-Reason'], 'yo%20%F0%9F%92%BF%20test') def test_null_reason(self): - from tests.utils import TestAPIClient - api = TestAPIClient() + api = APIClient() api.guilds_channels_modify(1, 2, 3, reason=None) _, kwargs = api.http.calls[0] diff --git a/tests/bot/__init__.py b/tests/bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_bot.py b/tests/bot/bot.py similarity index 100% rename from tests/test_bot.py rename to tests/bot/bot.py diff --git a/tests/gateway/__init__.py b/tests/gateway/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/gateway/events.py b/tests/gateway/events.py new file mode 100644 index 0000000..2714a5a --- /dev/null +++ b/tests/gateway/events.py @@ -0,0 +1,20 @@ +from disco.gateway.events import GatewayEvent, Resumed + + +def create_resumed_payload(): + return GatewayEvent.from_dispatch(None, { + 't': 'RESUMED', + 'd': { + '_trace': ['test', '1', '2', '3'], + } + }) + + +def test_from_dispatch(): + event = create_resumed_payload() + assert isinstance(event, Resumed) + assert event.trace == ['test', '1', '2', '3'] + + +def test_event_creation(benchmark): + benchmark(create_resumed_payload) diff --git a/tests/test_imports.py b/tests/imports.py similarity index 100% rename from tests/test_imports.py rename to tests/imports.py diff --git a/tests/types/__init__.py b/tests/types/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_channel.py b/tests/types/channel.py similarity index 78% rename from tests/test_channel.py rename to tests/types/channel.py index 56d5227..88695ea 100644 --- a/tests/test_channel.py +++ b/tests/types/channel.py @@ -4,7 +4,7 @@ from disco.types.channel import Channel, ChannelType class TestChannel(TestCase): - def test_nsfw_channel(self): + def test_deprecated_nsfw_channel(self): channel = Channel( name='nsfw-testing', type=ChannelType.GUILD_TEXT) @@ -19,3 +19,7 @@ class TestChannel(TestCase): name='nsfw_testing', type=ChannelType.GUILD_TEXT) self.assertFalse(channel.is_nsfw) + + def test_nsfw_channel(self): + channel = Channel(name='test', nsfw=True, type=ChannelType.GUILD_TEXT) + assert channel.is_nsfw diff --git a/tests/test_embeds.py b/tests/types/embeds.py similarity index 100% rename from tests/test_embeds.py rename to tests/types/embeds.py diff --git a/tests/test_types.py b/tests/types/types.py similarity index 100% rename from tests/test_types.py rename to tests/types/types.py diff --git a/tests/test_user.py b/tests/types/user.py similarity index 100% rename from tests/test_user.py rename to tests/types/user.py diff --git a/tests/util/__init__.py b/tests/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_util_limiter.py b/tests/util/limiter.py similarity index 100% rename from tests/test_util_limiter.py rename to tests/util/limiter.py diff --git a/tests/utils.py b/tests/utils.py index c0c615e..36fde6f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,6 +1,4 @@ -import time -import contextlib -from disco.api.client import APIClient +from disco.api.client import APIClient as _APIClient class CallContainer(object): @@ -11,28 +9,7 @@ class CallContainer(object): self.calls.append((args, kwargs)) -class TestAPIClient(APIClient): +class APIClient(_APIClient): def __init__(self): self.client = None self.http = CallContainer() - - -def bench(times, func): - main_start = time.time() - - worst = None - best = None - - for _ in range(times): - start = time.time() - func() - dur = time.time() - start - - if not worst or dur > worst: - worst = dur - - if not best or dur < best: - best = dur - - main_dur = time.time() - main_start - return main_dur, worst, best diff --git a/tests/voice/__init__.py b/tests/voice/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/tests_voice_queue.py b/tests/voice/queue.py similarity index 100% rename from tests/tests_voice_queue.py rename to tests/voice/queue.py