Toby Harradine ae7b912ac8
Major dependency update (#1974)
* [V3] Stop `tmp` dir showing up

* [V3] Remove requirements.txt and declare in install_requires

* Remove requirements.txt from tox.ini

* Update and pin all dependencies and sub-dependencies

* Update for breaking changes

* Reformat

* Update docs/requirements.txt and tox.ini requirements

* Add 3.7 to identifiers and travis/tox builds

* Attempt at fixing the travis build matrix

* Attempt #2

* Attempt 3

* aiohttp.ClientSession.close() -> detach() in sync code

* Add raven-aiohttp to requirements

* Fix stuff in setup.py

 - Added discord.py back into requirements list
 - Fix typo in alabaster extra requirement

Also in the Pipfile:
 - Removed allow_prereleases and explicitly pinned black, since this is the only dep we want a prerelease for.

* Update to Rapptz/discord.py@8ccb98d395

* Add proper 3.7 build in Travis

See travis-ci/travis-ci#9815

* Which version of 3.6 does Xenial install then?

* Maybe we should stop pipenv installing useless stuff

* Nevermind, back to specific minor version

* Remove lots of WET dependency stuff

* Fix egg fragment for dependency link
2018-08-15 12:10:55 +10:00

185 lines
3.8 KiB
Python

import random
from collections import namedtuple
from pathlib import Path
import pytest
from _pytest.monkeypatch import MonkeyPatch
from redbot.core import Config
from redbot.core.bot import Red
from redbot.core.drivers import red_json
__all__ = [
"monkeysession",
"override_data_path",
"coroutine",
"json_driver",
"config",
"config_fr",
"red",
"guild_factory",
"empty_guild",
"empty_channel",
"empty_member",
"empty_message",
"empty_role",
"empty_user",
"member_factory",
"user_factory",
"ctx",
]
@pytest.fixture(scope="session")
def monkeysession(request):
mpatch = MonkeyPatch()
yield mpatch
mpatch.undo()
@pytest.fixture(autouse=True)
def override_data_path(tmpdir):
from redbot.core import data_manager
data_manager.basic_config = data_manager.basic_config_default
data_manager.basic_config["DATA_PATH"] = str(tmpdir)
@pytest.fixture()
def coroutine():
async def some_coro(*args, **kwargs):
return args, kwargs
return some_coro
@pytest.fixture()
def json_driver(tmpdir_factory):
import uuid
rand = str(uuid.uuid4())
path = Path(str(tmpdir_factory.mktemp(rand)))
driver = red_json.JSON("PyTest", identifier=str(uuid.uuid4()), data_path_override=path)
return driver
@pytest.fixture()
def config(json_driver):
conf = Config(
cog_name="PyTest", unique_identifier=json_driver.unique_cog_identifier, driver=json_driver
)
yield conf
conf._defaults = {}
@pytest.fixture()
def config_fr(json_driver):
"""
Mocked config object with force_register enabled.
"""
conf = Config(
cog_name="PyTest",
unique_identifier=json_driver.unique_cog_identifier,
driver=json_driver,
force_registration=True,
)
yield conf
conf._defaults = {}
# region Dpy Mocks
@pytest.fixture()
def guild_factory():
mock_guild = namedtuple("Guild", "id members")
class GuildFactory:
def get(self):
return mock_guild(random.randint(1, 999999999), [])
return GuildFactory()
@pytest.fixture()
def empty_guild(guild_factory):
return guild_factory.get()
@pytest.fixture(scope="module")
def empty_channel():
mock_channel = namedtuple("Channel", "id")
return mock_channel(random.randint(1, 999999999))
@pytest.fixture(scope="module")
def empty_role():
mock_role = namedtuple("Role", "id")
return mock_role(random.randint(1, 999999999))
@pytest.fixture()
def member_factory(guild_factory):
mock_member = namedtuple("Member", "id guild display_name")
class MemberFactory:
def get(self):
return mock_member(random.randint(1, 999999999), guild_factory.get(), "Testing_Name")
return MemberFactory()
@pytest.fixture()
def empty_member(member_factory):
return member_factory.get()
@pytest.fixture()
def user_factory():
mock_user = namedtuple("User", "id")
class UserFactory:
def get(self):
return mock_user(random.randint(1, 999999999))
return UserFactory()
@pytest.fixture()
def empty_user(user_factory):
return user_factory.get()
@pytest.fixture(scope="module")
def empty_message():
mock_msg = namedtuple("Message", "content")
return mock_msg("No content.")
@pytest.fixture()
def ctx(empty_member, empty_channel, red):
mock_ctx = namedtuple("Context", "author guild channel message bot")
return mock_ctx(empty_member, empty_member.guild, empty_channel, empty_message, red)
# endregion
# region Red Mock
@pytest.fixture()
def red(config_fr):
from redbot.core.cli import parse_cli_flags
cli_flags = parse_cli_flags(["ignore_me"])
description = "Red v3 - Alpha"
Config.get_core_conf = lambda *args, **kwargs: config_fr
red = Red(cli_flags=cli_flags, description=description, pm_help=None)
yield red
red.http._session.detach()
# endregion