Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cobular committed Feb 1, 2021
2 parents 7ad2060 + c157fdd commit 41c243d
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 60 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ name: Run Tests (single version)

on:
push:
branches-ignore: [ develop, master, release/**, dependabot/** ]
pull_request:
branches-ignore: [ develop ]
branches-ignore: [ develop, master, release/**]

jobs:
build:
Expand Down
44 changes: 22 additions & 22 deletions .github/workflows/run_tests_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ name: Run Tests Matrix
on:
workflow_dispatch:
push:
branches: [ develop, master, release/**, dependabot/** ]
pull_request:
branches: [ develop ]
branches: [ develop, master, release/** ]

jobs:
build-matrix:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [ 3.6, 3.7, 3.8, 3.9 ]
discordpy-version: [ 1.5.0, 1.6.0 ]
max-parallel: 1

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install .
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies, discord.py version ${{ matrix.discordpy-version }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install discord.py==${{ matrix.discordpy-version }}
pip install .
- name: Test with distest
run: |
./run_tests.sh
env:
TARGET_ID: "582625299611648042"
CHANNEL: "586041924129914910"
TESTER_TOKEN: ${{ secrets.TESTER_TOKEN }}
TARGET_TOKEN: ${{ secrets.TARGET_TOKEN }}
- name: Test with distest
run: |
./run_tests.sh
env:
TARGET_ID: "582625299611648042"
CHANNEL: "586041924129914910"
TESTER_TOKEN: ${{ secrets.TESTER_TOKEN }}
TARGET_TOKEN: ${{ secrets.TARGET_TOKEN }}

test_docs_matrix:
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion distest/TestInterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ def __init__(self, client, channel, target):
assert_reply_equals,
assert_reply_contains,
assert_reply_embed_equals,
assert_reply_embed_regex,
assert_reply_matches,
assert_reply_has_image,
get_delayed_reply,
)
from ._embeds import assert_embed_equals
from ._embeds import (
assert_embed_equals,
assert_embed_regex,
)
from ._wait_for import (
wait_for_message,
wait_for_reaction,
Expand All @@ -102,3 +106,4 @@ def __init__(self, client, channel, target):
assert_message_has_image = staticmethod(assert_message_has_image)
assert_message_matches = staticmethod(assert_message_matches)
assert_embed_equals = staticmethod(assert_embed_equals)
assert_embed_regex = staticmethod(assert_embed_regex)
35 changes: 34 additions & 1 deletion distest/TestInterface/_embeds.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from discord import Message, Embed
from typing import Dict

from distest.exceptions import ResponseDidNotMatchError

import re


async def assert_embed_equals(
message: Message, matches: Embed, attributes_to_prove: list = None,
Expand All @@ -11,7 +14,7 @@ async def assert_embed_equals(
Checks only the attributes from ``attributes_to_prove``.
:param message: original message
:param matches: embed object to compare to
:param matches: :py:class:`embed <discord.Embed>` object to compare to
:param attributes_to_prove: a string list with the attributes of the embed, which are to compare
This are all the Attributes you can prove: "title", "description", "url", "color",
"author", "video", "image" and "thumbnail".
Expand Down Expand Up @@ -75,3 +78,33 @@ async def assert_embed_equals(
)
raise ResponseDidNotMatchError
return message


async def assert_embed_regex(message: Message, patterns: Dict[str, str]):
"""If regex patterns ``patterns`` cannot be found in the embed of ``message``, fail the test.
Checks only the attributes from the dictionary keys of ``patterns``.
:param message: original message
:param patterns: a dict with keys of the attributes and regex values.
:return: message
:rtype: discord.Message
"""

possible_attributes = [
"title",
"description",
"color",
]

for embed in message.embeds:
for attribute, regex in patterns.items():
if not re.search(regex, getattr(embed, attribute)):
print(
"Regex did not match:",
attribute,
getattr(embed, attribute),
regex,
)
raise ResponseDidNotMatchError
return message
35 changes: 33 additions & 2 deletions distest/TestInterface/_reply.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from asyncio import sleep
from inspect import signature, _ParameterKind
from typing import Dict

from discord import Embed, Message
from asyncio import sleep


async def assert_reply_equals(self, contents, matches):
Expand Down Expand Up @@ -32,14 +34,43 @@ async def assert_reply_contains(self, contents, substring):


async def assert_reply_embed_equals(
self, message: str, equals: Embed, attributes_to_check: list = None
self, message: str, equals: Embed, attributes_to_check: list = None
):
""" Send a message and wait for an embed response. If the response does not match the given embed in the listed
attributes, fail the test
See examples in example_target.py for examples of use.
:param message:
:param equals: :py:class:`embed <discord.Embed>` object to compare to
:param attributes_to_check: a string list with the attributes of the embed, which are to compare
This are all the Attributes you can prove: "title", "description", "url", "color",
"author", "video", "image" and "thumbnail".
:return: message
:rtype: discord.Message
"""
response = await self.wait_for_reply(message)
return await self.assert_embed_equals(
response, equals, attributes_to_prove=attributes_to_check
)


async def assert_reply_embed_regex(self, message: str, patterns: Dict[str, str]):
""" Send a message and wait for a response. If the response is not an embed or does not match the regex,
fail the test.
See examples in example_target.py for examples of use.
:param message:
:param patterns: A dict of the attributes to check. See
:py:meth:`assert_message_contains <distest.TestInterface.assert_embed_regex>` for more info on this.
:return: message
:rtype: discord.Message
"""
response = await self.wait_for_reply(message)
return await self.assert_embed_regex(response, patterns)


async def assert_reply_matches(self, contents: str, regex):
""" Send a message and wait for a response. If the response does not match a regex, fail the test.
Expand Down
2 changes: 1 addition & 1 deletion distest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from .bot import DiscordInteractiveInterface, DiscordCliInterface
from .collector import TestCollector
from .TestInterface import TestInterface

__version__ = "0.6.0"

def run_dtest_bot(sysargs, test_collector, timeout=5):
""" This is the function you will call in your test suite's ``if __name__ == "__main__":`` statement to
Expand Down
24 changes: 12 additions & 12 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
# built documents.
#
# The short X.Y version.
version = "0.4.9"
version = "0.6.0"
# The full version, including alpha/beta/rc tags.
release = "0.4.9"
release = "0.6.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -130,15 +130,15 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "alabaster"
html_sidebars = {"**": ["about.html", "navigation.html", "searchbox.html"]}
html_theme_options = {
"description": "A Testivus for the rest of us!",
"fixed_sidebar": "true",
"github_banner": "true",
"github_user": "JakeCover",
"github_repo": "Distest",
}
html_theme = "furo"
# html_sidebars = {"**": ["about.html", "navigation.html", "searchbox.html"]}
# html_theme_options = {
# "description": "A Testivus for the rest of us!",
# "fixed_sidebar": "true",
# "github_banner": "true",
# "github_user": "JakeCover",
# "github_repo": "Distest",
# }

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -449,7 +449,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ("https://docs.python.org/", None),
"python": ("https://docs.python.org/3/", None),
"discord": ("https://discordpy.readthedocs.io/en/latest/", None),
}

Expand Down
3 changes: 1 addition & 2 deletions docs/source/distest/interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ This is the most important class in the library for you, as it contains all the
.. todo::
Re-organize this file more sensibly

.. autoclass:: distest.TestInterface
:no-private-members:
.. autoclass:: distest.TestInterface.TestInterface
:members:

----------------------------------
Expand Down
14 changes: 8 additions & 6 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ See the :ref:`interface <interface>` reference for a list of assertions this lib
.. note::
Two quick note about recent changes:

1. You NEED to enable the ``members`` intent on the tester bot. For more information, see :ref:`Member Intent <member_intent>`
2. If you're using the :py:class:`ext.commands.Bot <discord.ext.commands.Bot>` system, you will need to patch your ``Bot`` to allow it to listen to other discord bots, as usually commands ignore other bots. This is really easy, we provide the patching function, just take a look at the :ref:`patching <patches>` documentation page.
1. You NEED to enable the ``members`` intent on the tester bot. For more information, see :ref:`Member Intent <member_intent>`
2. If you're using the :py:class:`ext.commands.Bot <discord.ext.commands.Bot>` system, you will need to patch your ``Bot`` to allow it to listen to other discord bots, as usually commands ignore other bots. This is really easy, we provide the patching function, just take a look at the :ref:`patching <patches>` documentation page.

.. toctree::
:maxdepth: 2
Expand All @@ -22,7 +22,8 @@ See the :ref:`interface <interface>` reference for a list of assertions this lib
distest/member_intent

.. toctree::
:maxdepth: 1
:maxdepth: 2
:glob:
:caption: Reference

distest
Expand All @@ -31,16 +32,17 @@ See the :ref:`interface <interface>` reference for a list of assertions this lib
distest/bot
distest/collector
distest/exceptions
distest/patches

.. toctree::
:maxdepth: 2
:caption: Other

distest/getting-started-documentation
distest/contributing
distest/member_intent
distest/patches

Meta Documentation Pages
========================
________________________

* :ref:`genindex`
* :ref:`modindex`
Expand Down
12 changes: 11 additions & 1 deletion example_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
python example_target.py TARGET_TOKEN
"""
import asyncio
import random
import sys

import discord
Expand Down Expand Up @@ -68,6 +69,13 @@ async def on_message(message):
await asyncio.sleep(1)
embed = discord.Embed(title="Testing Title.", description="Right Description!")
sent = await message.channel.send(embed=embed)
if message.content.startswith("Test the Embed regex!"):
await asyncio.sleep(1)
embed = discord.Embed(
title="Test the Embed regex!",
description="Random Number: " + str(random.randint(10, 99)),
)
sent = await message.channel.send(embed=embed)
if message.content.startswith("Say some stuff, but at 4 seconds, say 'yeet'"):
await asyncio.sleep(1)
await message.channel.send("hahaha!")
Expand All @@ -88,7 +96,9 @@ async def on_message(message):
print("Message sent: {}".format(sent.clean_content))
if message.content.startswith("Say stuff in another channel"):
await asyncio.sleep(1)
await client.get_channel(694397509958893640).send("here is a message in another channel")
await client.get_channel(694397509958893640).send(
"here is a message in another channel"
)


@client.event
Expand Down
19 changes: 15 additions & 4 deletions example_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ async def test_embed_matches(interface):
url="http://www.example.com",
color=0x00FFCC,
)
.set_author(name="Author")
.set_thumbnail(
.set_author(name="Author")
.set_thumbnail(
url="https://upload.wikimedia.org/wikipedia/commons/4/40/Test_Example_%28cropped%29.jpg"
)
.set_image(
.set_image(
url="https://upload.wikimedia.org/wikipedia/commons/4/40/Test_Example_%28cropped%29.jpg"
)
)
Expand All @@ -105,6 +105,15 @@ async def test_embed_matches(interface):
await interface.assert_reply_embed_equals("Test the Embed!", embed)


@test_collector()
async def test_embed_regex(interface):
patterns = {
"title": "Test",
"description": r"Random Number: [0-9]+",
}
await interface.assert_reply_embed_regex("Test the Embed regex!", patterns)


@test_collector()
async def test_embed_part_matches(interface):
embed = Embed(title="Testing Title.", description="Wrong Description")
Expand All @@ -129,7 +138,9 @@ async def test_reply_on_edit(interface):
@test_collector()
async def test_send_message_in_channel(interface):
message = await interface.send_message("Say stuff in another channel")
await interface.wait_for_message_in_channel("here is a message in another channel", 694397509958893640)
await interface.wait_for_message_in_channel(
"here is a message in another channel", 694397509958893640
)


# Actually run the bot
Expand Down
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Sphinx~=2.3.0
black==20.8b1
Sphinx~=3.4.0
black==20.8b1
furo==2020.12.30b24

0 comments on commit 41c243d

Please sign in to comment.