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

Commit 868d1a1

Browse files
committed
Merge branch 'release/0.5.0'
2 parents 48160b4 + 6e220c5 commit 868d1a1

24 files changed

Lines changed: 358 additions & 81 deletions

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: JakeCover

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "daily"
12+
open-pull-requests-limit: 2
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
build-n-publish:
10+
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@2
14+
- name: Set up Python 3.9
15+
uses: actions/setup-python@v1
16+
with:
17+
python-version: 3.9
18+
- name: Install pypa/build
19+
run: >-
20+
python -m
21+
pip install
22+
build
23+
- name: Build a binary wheel and a source tarball
24+
run: >-
25+
python -m
26+
build
27+
--sdist
28+
--wheel
29+
--outdir dist/
30+
.
31+
- name: Publish distribution 📦 to Test PyPI
32+
uses: pypa/gh-action-pypi-publish@master
33+
with:
34+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
35+
repository_url: https://test.pypi.org/legacy/
36+
- name: Publish distribution 📦 to PyPI
37+
if: startsWith(github.ref, 'refs/tags')
38+
uses: pypa/gh-action-pypi-publish@master
39+
with:
40+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/run_tests.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Tests distest on 3.9 only. Faster, so run every push
2+
name: Run Tests (single version)
3+
4+
on:
5+
push:
6+
branches-ignore: [ develop, master, release/**, dependabot/** ]
7+
pull_request:
8+
branches-ignore: [ develop ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.9
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements.txt
24+
pip install .
25+
26+
- name: Test with distest
27+
run: |
28+
./run_tests.sh
29+
env:
30+
TARGET_ID: "582625299611648042"
31+
CHANNEL: "586041924129914910"
32+
TESTER_TOKEN: ${{ secrets.TESTER_TOKEN }}
33+
TARGET_TOKEN: ${{ secrets.TARGET_TOKEN }}
34+
35+
36+
test_docs:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@v2
40+
with:
41+
clean: false
42+
fetch-depth: 20
43+
- name: Set up Python
44+
uses: actions/setup-python@v2
45+
with:
46+
python-version: 3.9
47+
- name: Install dependencies
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install -r requirements.txt
51+
pip install -r requirements-dev.txt
52+
pip install .
53+
- name: Test Docs
54+
run: ./test_sphinx.sh
55+
shell: bash
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Runs tests on many versions of python, slower so only run on develop
2+
name: Run Tests Matrix
3+
4+
on:
5+
push:
6+
branches: [ develop, master, release/**, dependabot/** ]
7+
pull_request:
8+
branches: [ develop ]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: [3.6, 3.7, 3.8, 3.9]
17+
max-parallel: 1
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: 3.9
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
pip install .
30+
31+
- name: Test with distest
32+
run: |
33+
./run_tests.sh
34+
env:
35+
TARGET_ID: "582625299611648042"
36+
CHANNEL: "586041924129914910"
37+
TESTER_TOKEN: ${{ secrets.TESTER_TOKEN }}
38+
TARGET_TOKEN: ${{ secrets.TARGET_TOKEN }}
39+
40+
test_docs:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
with:
45+
clean: false
46+
fetch-depth: 20
47+
- name: Set up Python
48+
uses: actions/setup-python@v2
49+
with:
50+
python-version: 3.9
51+
- name: Install dependencies
52+
run: |
53+
python -m pip install --upgrade pip
54+
pip install -r requirements.txt
55+
pip install -r requirements-dev.txt
56+
pip install .
57+
- name: Test Docs
58+
run: ./test_sphinx.sh
59+
shell: bash

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
.run
2+
13
# Compiled python modules.
24
*.py[cod]
35

46
# virtualenv
5-
/venv/
7+
/venv*
68

79
# Setuptools distribution folder.
810
/dist/
@@ -91,3 +93,4 @@ fkjdfkasdfkh\.txt
9193
docs/build/
9294

9395
.idea/
96+
.run/

distest/TestInterface/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import enum
2+
import discord
3+
from typing import Optional
24

35

46
class TestResult(enum.Enum):
@@ -48,17 +50,17 @@ class TestInterface:
4850
``Message`` to be passed to them. This allows for more flexibility when you need it and an easier
4951
option when you don't.
5052
51-
:param discord.Client client: The discord client of the tester.
53+
:param DiscordCliInterface client: The discord client of the tester.
5254
:param discord.TextChannel channel: The discord channel in which to run the tests.
5355
:param discord.Member target: The bot we're testing.
5456
"""
5557

5658
def __init__(self, client, channel, target):
5759
self.client = client
58-
self.channel = channel
59-
self.target = target
60-
self.voice_client = None
61-
self.voice_channel = None
60+
self.channel: discord.TextChannel = channel
61+
self.target: discord.Member = target
62+
self.voice_client: Optional[discord.VoiceClient] = None
63+
self.voice_channel: Optional[discord.VoiceChannel] = None
6264

6365
# Imported Methods
6466
from ._helpers import send_message, _check_message, edit_message

distest/TestInterface/_oddballs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from concurrent.futures import _base
2+
from asyncio.exceptions import TimeoutError, CancelledError
23
from discord import Reaction
34
from distest.exceptions import (
45
UnexpectedResponseError,
@@ -16,7 +17,7 @@ async def ensure_silence(self):
1617
await self.client.wait_for(
1718
"message", timeout=self.client.timeout, check=self._check_message
1819
)
19-
except _base.TimeoutError:
20+
except (_base.TimeoutError, TimeoutError, CancelledError):
2021
pass
2122
else:
2223
raise UnexpectedResponseError

distest/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ def run_command_line_bot(target, token, tests, channel_id, stats, collector, tim
139139
:param TestCollector collector: The collector that gathered our tests.
140140
:param int timeout: The amount of time to wait for responses before failing tests.
141141
"""
142-
bot = DiscordCliInterface(target, collector, tests, channel_id, stats, timeout)
143-
failed = bot.run(token) # returns True if a test failed
142+
m_bot = DiscordCliInterface(target, collector, tests, channel_id, stats, timeout)
143+
failed = m_bot.run(token) # returns True if a test failed
144144
sys.exit(1 if failed else 0) # Calls sys.exit based on the state of `failed`

distest/bot.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:py:class:`DiscordCliInterface` is a subclass of :py:class:`DiscordInteractiveInterface` and simply contains logic to
99
start the bot when it wakes up
1010
"""
11+
1112
import discord
1213

1314
from .TestInterface import TestResult, Test, TestInterface
@@ -24,6 +25,7 @@
2425

2526
intents = discord.Intents.default()
2627
intents.members = True
28+
intents.presences = True
2729

2830

2931
class DiscordBot(discord.Client):
@@ -50,18 +52,21 @@ def _find_target(self, server: discord.Guild) -> discord.Member:
5052
for member in server.members:
5153
if self._target_name == member.id:
5254
if member.status == discord.Status.offline:
53-
print("Looks like the target bot is on the server but offline, you might want to check on that!")
55+
print("Looks like the target bot is on the server but offline, "
56+
"you might want to check on that!")
5457
return member
58+
print("Looks like I can't see any server members! You may need to enable the privileged gateway intent, see "
59+
"here for how to do so: https://discordpy.readthedocs.io/en/latest/intents.html")
5560
raise KeyError("Could not find member with id {}".format(self._target_name))
5661

5762
async def run_test(
58-
self, test: Test, channel: discord.TextChannel, stop_error=False
63+
self, test: Test, channel: discord.TextChannel, stop_error=False
5964
) -> TestResult:
6065
""" Run a single test in a given channel.
6166
6267
Updates the test with the result and returns it
6368
64-
:param Test test: The :py:class:`Test` that is to be run
69+
:param Test test: The :py:class:`Test <distest.TestInterface.Test>` that is to be run
6570
:param discord.TextChannel channel: The
6671
:param stop_error: Weather or not to stop the program on error. Not currently in use.
6772
:return: Result of the test
@@ -128,9 +133,9 @@ async def _build_stats(self, tests) -> str:
128133
if test.result is TestResult.UNRUN:
129134
response += "⚫ Not run\n"
130135
elif test.result is TestResult.SUCCESS:
131-
response += "✔️ Passed\n"
136+
response += " Passed\n"
132137
elif test.result is TestResult.FAILED:
133-
response += " Failed\n"
138+
response += " Failed\n"
134139
self.failure = True
135140
response += "```\n"
136141
return response
@@ -217,7 +222,6 @@ def __init__(self, target_id, collector, test, channel_id, stats, timeout):
217222
self._stats = stats
218223
self._channel = None
219224

220-
#
221225
def run(self, token) -> int:
222226
""" Override of the default run() that returns failure state after completion.
223227
Allows the failure to cascade back up until it is processed into an exit code by

0 commit comments

Comments
 (0)