Skip to content

Commit d061fe3

Browse files
authored
Merge pull request #227 from davidhozic/develop
Automatic testing
2 parents d13c7df + 26f183f commit d061fe3

19 files changed

+519
-266
lines changed

.github/workflows/python-tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Run auto tests
2+
3+
on:
4+
push:
5+
branches: [ "master"]
6+
pull_request:
7+
branches: [ "master" , "develop"]
8+
workflow_dispatch:
9+
10+
jobs:
11+
pytest:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
max-parallel: 1
15+
fail-fast: false
16+
matrix:
17+
python-version: ["3.8", "3.10"]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v3
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
sudo apt update
28+
sudo apt install -y ffmpeg
29+
python -m pip install --upgrade pip
30+
python -m pip install .[all]
31+
python -m pip install .[testing]
32+
- name: Test with pytest
33+
env:
34+
DISCORD_TOKEN: ${{secrets.DATT}}
35+
run: |
36+
pytest -v

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**/__pycache__/**
22
settings.json
33
dist/**
4-
test**
5-
build**
4+
build**
5+
**.egg-info

optional.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"voice" : ["PyNaCl", "yt-dlp"],
33
"proxy" : ["aiohttp_socks"],
44
"sql" : ["sqlalchemy[asyncio]", "aiosqlite", "pymssql", "asyncpg", "asyncmy"],
5+
"testing" : ["pytest", "pytest-xdist", "pytest-asyncio"],
56
"docs" : ["sphinx", "sphinx-autobuild", "sphinx-copybutton", "furo", "enum-tools[sphinx]", "sphinx-design[furo]", "readthedocs-sphinx-search"]
67
}

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
optional_install = None
1717
with open("./optional.json", "r", encoding="utf-8") as rf:
1818
optional_install: dict = json.load(rf)
19+
all_ = optional_install.copy()
20+
all_.pop("testing")
21+
all_.pop("docs")
22+
1923
# Make a key that will install all requirements
2024
all_deps = []
21-
for key, deps in optional_install.items():
22-
if key == "docs":
23-
continue
24-
25+
for key, deps in all_.items():
2526
all_deps.extend(deps)
2627

2728
optional_install["all"] = all_deps

src/daf/message/text_based.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Contains definitions for message classes that are text based."""
33

44

5-
from pickle import GLOBAL
65
from typing import Any, Dict, List, Iterable, Optional, Union, Literal
76
from datetime import datetime, timedelta
87
from typeguard import typechecked
@@ -363,11 +362,10 @@ async def _send_channel(self,
363362
if (self.mode in {"send" , "clear-send"} or # Mode dictates to send new message or delete previous and then send new message or mode dictates edit but message was never sent to this channel before
364363
self.mode == "edit" and self.sent_messages.get(channel.id, None) is None
365364
):
366-
discord_sent_msg = await channel.send( text,
365+
self.sent_messages[channel.id] = await channel.send( text,
367366
embed=embed,
368367
# Create discord.File objects here so it is catched by the except block and then logged
369368
files=[discord.File(fwFILE.filename) for fwFILE in files])
370-
self.sent_messages[channel.id] = discord_sent_msg
371369
# Mode is edit and message was already send to this channel
372370
elif self.mode == "edit":
373371
await self.sent_messages[channel.id].edit ( text,

testing/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pytest
2+
3+
pytest_plugins = [
4+
"fixtures.main",
5+
]

testing/direct_main_send_multiple.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

testing/find_promo_channels.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

testing/fixtures/__init__.py

Whitespace-only changes.

testing/fixtures/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import asyncio
2+
import pytest
3+
import pytest_asyncio
4+
import os
5+
import daf
6+
7+
8+
TEST_TOKEN = os.environ.get("DISCORD_TOKEN")
9+
TEST_GUILD_ID = 863071397207212052
10+
TEST_CATEGORY_NAME = "RUNNING-TEST"
11+
TEST_TEXT_CHANNEL_NAME_FORM = "PYTEST"
12+
TEST_TEXT_CHANNEL_NUM = 3
13+
TEST_VOICE_CHANNEL_NAME_FORM = "PYTEST_VOICE"
14+
TEST_VOICE_CHANNEL_NUM = 2
15+
16+
17+
@pytest.fixture(scope="session")
18+
def event_loop():
19+
try:
20+
loop = asyncio.get_running_loop()
21+
except RuntimeError:
22+
loop = asyncio.new_event_loop()
23+
yield loop
24+
loop.close()
25+
26+
27+
@pytest.fixture(scope="session", autouse=True)
28+
def start_daf(event_loop: asyncio.AbstractEventLoop):
29+
event_loop.run_until_complete(daf.initialize(TEST_TOKEN))
30+
return event_loop
31+
32+
33+
@pytest_asyncio.fixture(scope="session")
34+
async def category():
35+
client = daf.get_client()
36+
guild: daf.discord.Guild = client.get_guild(TEST_GUILD_ID)
37+
cat = await guild.create_category(TEST_CATEGORY_NAME)
38+
yield cat
39+
await cat.delete()
40+
41+
42+
@pytest_asyncio.fixture(scope="session")
43+
async def text_channels(category: daf.discord.CategoryChannel):
44+
ret = []
45+
for i in range(TEST_TEXT_CHANNEL_NUM):
46+
ret.append(await category.create_text_channel(TEST_TEXT_CHANNEL_NAME_FORM))
47+
48+
yield ret
49+
for c in ret:
50+
await c.delete()
51+
52+
53+
@pytest_asyncio.fixture(scope="session")
54+
async def voice_channels(category: daf.discord.CategoryChannel):
55+
ret = []
56+
for i in range(TEST_VOICE_CHANNEL_NUM):
57+
ret.append(await category.create_voice_channel(TEST_VOICE_CHANNEL_NAME_FORM))
58+
59+
yield ret
60+
for c in ret:
61+
await c.delete()

0 commit comments

Comments
 (0)