Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
5f2a9a2
Added basic unit testing framework
FrostByte266 Sep 2, 2021
195b525
Merge branch 'master' into unittest
FrostByte266 Sep 14, 2021
7db8949
Merge branch 'master' into unittest
FrostByte266 Oct 8, 2021
4eb61f1
WIP unit testing support, NOT USABLE YET
FrostByte266 Oct 8, 2021
2937439
Improved unit testing framework
FrostByte266 Nov 3, 2021
8d4ec4b
Merge pull request #391 from Pycord-Development/master
Lulalaby Nov 4, 2021
a9d7543
General code cleanup
FrostByte266 Nov 6, 2021
f4d1c82
Fixed another spelling error 🤦
FrostByte266 Nov 6, 2021
46009bf
Merge remote-tracking branch 'origin/unittest'
Lulalaby Jan 7, 2022
a15def3
x
Lulalaby Jan 7, 2022
c3ed286
Merge branch 'master' into unittest
Lulalaby Jan 7, 2022
dc84017
Add A Test
VincentRPS Dec 3, 2021
6ff7165
Ex:
VincentRPS Dec 3, 2021
07910d3
Typo
VincentRPS Dec 3, 2021
a4d354c
Merge branch 'master' into unittest
BobDotCom Oct 6, 2022
9d0719a
Finish merge
BobDotCom Oct 6, 2022
785d339
Run pre-commit
BobDotCom Oct 6, 2022
656f028
Migrate to pytest
BobDotCom Oct 7, 2022
5c4b54a
Specify proxy.py version
BobDotCom Oct 7, 2022
09b7a8d
Handle if env var is empty string
BobDotCom Oct 7, 2022
9460ee0
Update CI
BobDotCom Oct 7, 2022
b86d592
Fix syntax
BobDotCom Oct 7, 2022
6085937
Add install step
BobDotCom Oct 7, 2022
5d1420b
Merge branch 'master' into unittest
BobDotCom Oct 9, 2022
4a0608c
Merge branch 'master' into unittest
BobDotCom Oct 11, 2022
dbfb5a8
Implemented minimal working test runner
FrostByte266 Oct 12, 2022
c70c811
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 12, 2022
24ce3de
Bump proxy.py requirement
BobDotCom Oct 13, 2022
fdf99d3
Remove old conf value
BobDotCom Oct 13, 2022
60c508f
Update test workflow
BobDotCom Oct 13, 2022
785433d
temporarily remove linux
BobDotCom Oct 13, 2022
3614eb4
Pin test requirements
BobDotCom Oct 13, 2022
187e5b9
Install libmagic on mac
BobDotCom Oct 13, 2022
acb3907
Specify shell
BobDotCom Oct 13, 2022
702f0aa
Change libmagic installation
BobDotCom Oct 13, 2022
377f29a
Temporarily remove windows
BobDotCom Oct 13, 2022
292a286
Revert "Specify shell"
BobDotCom Oct 13, 2022
4a0be83
Add debug steps
BobDotCom Oct 13, 2022
865b5c0
Check file perms
BobDotCom Oct 13, 2022
4397761
Add debug checks
BobDotCom Oct 13, 2022
85e78d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2022
3360c62
Add more debug
BobDotCom Oct 13, 2022
250a048
CI debugging
BobDotCom Oct 13, 2022
6ecc7e8
Add certifi to requirements
BobDotCom Oct 13, 2022
6800aba
Switch to python-magic
BobDotCom Oct 13, 2022
b5f2833
Add codecov token
BobDotCom Oct 13, 2022
713bacf
Remove debug steps
BobDotCom Oct 13, 2022
e4b56fa
Add linux to matrix
BobDotCom Oct 13, 2022
cf45419
Add windows to matrix
BobDotCom Oct 13, 2022
ed60c25
Use pytest-cov
BobDotCom Oct 13, 2022
4c58400
Reorganize requirements
BobDotCom Oct 13, 2022
0b66694
Use Client instead of HTTPClient
BobDotCom Oct 13, 2022
d0bc3af
python 3.8 support
BobDotCom Oct 13, 2022
38279f5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2022
a1d611b
Install base requirements in make install
BobDotCom Oct 13, 2022
5f6e02f
Modify coverage options
BobDotCom Oct 13, 2022
155c63e
Remove redundant lines in tests
BobDotCom Oct 13, 2022
ca259db
Add libmagic binaries for windows
BobDotCom Oct 13, 2022
9b9d9d5
Pin exact versions
BobDotCom Oct 13, 2022
01f9f70
Fix permission error (del queue after proxy)
BobDotCom Oct 13, 2022
9bd7702
Implement get_guild test
BobDotCom Oct 14, 2022
968dda1
Improve import tests
BobDotCom Oct 14, 2022
711669c
Merge branch 'master' into unittest
BobDotCom Oct 14, 2022
079abbf
Merge branch 'master' into unittest
BobDotCom Oct 17, 2022
1ff6a37
Merge branch 'master' into unittest
BobDotCom Oct 17, 2022
59583a3
Merge branch 'master' into unittest
BobDotCom Oct 20, 2022
ca7ea23
Merge branch 'master' into unittest
BobDotCom Oct 20, 2022
c033bfb
Merge branch 'master' into unittest
BobDotCom Oct 21, 2022
6adb0e1
Merge branch 'master' into unittest
BobDotCom Oct 24, 2022
592898b
Merge branch 'master' into unittest
BobDotCom Oct 24, 2022
efaaa5f
Merge branch 'master' into unittest
BobDotCom Oct 25, 2022
edae7bf
Alternate implementation of unit testing (#1727)
BobDotCom Oct 25, 2022
43a362b
Add __eq__ to Route
BobDotCom Oct 26, 2022
7234fe3
Add route checking
BobDotCom Oct 26, 2022
6a3325c
Alter codecov flags
BobDotCom Oct 26, 2022
16fb22c
Update test action python versions
BobDotCom Oct 26, 2022
bbc6254
Remove old test code
BobDotCom Oct 26, 2022
7a95d7e
Improve coverage and categorize tests
BobDotCom Oct 26, 2022
5b25da9
Merge branch 'master' into unittest
BobDotCom Oct 26, 2022
3d71b2e
Improve coverage
BobDotCom Oct 26, 2022
1679047
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Oct 26, 2022
3cc1bb7
Improve coverage
BobDotCom Oct 26, 2022
0a09432
Merge branch 'master' into unittest
BobDotCom Oct 26, 2022
a038889
Merge branch 'master' into unittest
BobDotCom Oct 26, 2022
44125b2
Merge branch 'master' into unittest
BobDotCom Oct 26, 2022
3f9921b
Add codecov badge
BobDotCom Oct 26, 2022
d4fed1e
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Oct 26, 2022
52e4041
Use event loop
BobDotCom Oct 26, 2022
997e9a6
Merge branch 'master' into unittest
BobDotCom Oct 27, 2022
1d38bf8
Merge branch 'master' into unittest
BobDotCom Oct 27, 2022
9fb4b9b
categorize tests and improve coverage
BobDotCom Oct 27, 2022
bacf88a
Add __future__ annotations import
BobDotCom Oct 27, 2022
079c76b
Merge branch 'master' into unittest
BobDotCom Oct 28, 2022
d0adb13
Improve send tests
BobDotCom Oct 28, 2022
0114719
Improve edit_files branch coverage
BobDotCom Oct 28, 2022
afb891d
Improve coverage
BobDotCom Oct 28, 2022
12e0f2d
Add reaction tests
BobDotCom Oct 28, 2022
27ee87f
Improve coverage
BobDotCom Oct 28, 2022
fbae2c0
Improve coverage
BobDotCom Oct 28, 2022
b6e6e22
Add route_eq test
BobDotCom Oct 28, 2022
fa68c1d
Improve coverage
BobDotCom Oct 28, 2022
7af9169
Merge branch 'master' into unittest
BobDotCom Oct 28, 2022
8620c37
Complete member coverage
BobDotCom Oct 31, 2022
c5f1bbb
Add edit_channel coverage
BobDotCom Oct 31, 2022
24da993
Add pytest-randomly
BobDotCom Oct 31, 2022
5a672f7
Finish channel coverage
BobDotCom Oct 31, 2022
fefb9e7
Merge branch 'master' into unittest
BobDotCom Nov 4, 2022
d45a552
Merge branch 'master' into unittest
BobDotCom Nov 7, 2022
4609427
Merge branch 'master' into unittest
BobDotCom Nov 7, 2022
4cd8210
Merge branch 'master' into unittest
BobDotCom Nov 7, 2022
95b6136
Merge branch 'master' into unittest
BobDotCom Nov 8, 2022
4085be5
Merge branch 'master' into unittest
BobDotCom Nov 14, 2022
88dec77
fix(deps): Fix bad merge
BobDotCom Nov 14, 2022
9d19050
Merge branch 'master' into unittest
BobDotCom Nov 14, 2022
69a1361
Merge branch 'master' into unittest
BobDotCom Nov 15, 2022
ef8d483
Add gateway tests
BobDotCom Nov 16, 2022
3d355bc
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Nov 16, 2022
0c7984e
Add some thread tests
BobDotCom Nov 16, 2022
d47c900
Merge branch 'master' into unittest
BobDotCom Nov 16, 2022
7ac4458
Improve thread tests
BobDotCom Nov 16, 2022
48f7fe1
Add client.http typehints
BobDotCom Nov 16, 2022
4c3e0eb
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Nov 16, 2022
f7aa735
Finish thread tests
BobDotCom Nov 16, 2022
d5dc9d8
Improve randomization
BobDotCom Nov 16, 2022
64aac9e
Add http coverage flag
BobDotCom Nov 16, 2022
99ce931
Use automatic flag management
BobDotCom Nov 16, 2022
c1202ca
Use bespoke flag management
BobDotCom Nov 16, 2022
b5cae3c
Update codecov.yml
BobDotCom Nov 16, 2022
84e5adc
Merge branch 'master' into unittest
BobDotCom Nov 16, 2022
8d50a44
Try using regex path
BobDotCom Nov 16, 2022
f1ca7f0
move back to automatic flag management
BobDotCom Nov 16, 2022
1f785ad
Try carryforward flag
BobDotCom Nov 17, 2022
a34d2b3
Merge branch 'master' into unittest
BobDotCom Nov 17, 2022
8c60766
Try new codecov config
BobDotCom Nov 17, 2022
4df459f
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Nov 17, 2022
ef12bc7
Add webhook tests
BobDotCom Nov 17, 2022
d09b223
Add applied_tags to test_start_forum_thread
BobDotCom Nov 17, 2022
6775daf
Add some guild tests
BobDotCom Nov 17, 2022
f2e646e
restructure: move fixtures to ext.testing
BobDotCom Nov 17, 2022
274de19
remove extra imports
BobDotCom Nov 17, 2022
99cf7dd
Merge branch 'master' into unittest
BobDotCom Nov 19, 2022
96ef126
Merge branch 'master' into unittest
BobDotCom Nov 20, 2022
def1e1a
Merge branch 'master' into unittest
BobDotCom Nov 30, 2022
9708797
Merge branch 'master' into unittest
BobDotCom Nov 30, 2022
cab332a
Merge branch 'master' into unittest
Lulalaby Jan 5, 2023
bb77385
Merge branch 'master' into unittest
BobDotCom Jan 5, 2023
d3ce28e
Merge branch 'master' into unittest
BobDotCom Jan 9, 2023
c467f40
start coverage for guilds
BobDotCom Jan 9, 2023
da3cf27
implement flag fixture
BobDotCom Jan 9, 2023
47cf7c6
add comment
BobDotCom Jan 9, 2023
8393cc5
Merge branch 'master' into unittest
BobDotCom Jan 10, 2023
f1af17d
Merge remote-tracking branch 'origin/unittest' into unittest
BobDotCom Jan 10, 2023
bb29e3c
chore: improve guild coverage
BobDotCom Jan 10, 2023
14fe917
fix: add __future__.annotations import
BobDotCom Jan 10, 2023
ac9b2b1
Merge branch 'master' into unittest
BobDotCom Jan 10, 2023
751c24d
chore: improve guild coverage
BobDotCom Jan 10, 2023
e59a535
Merge branch 'master' into unittest
BobDotCom Jan 18, 2023
c2db9a4
Merge branch 'master' into unittest
BobDotCom Apr 17, 2023
9069984
Merge branch 'master' into unittest
Lulalaby Apr 18, 2023
674b7e9
Merge branch 'master' into unittest
Lulalaby May 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
cache-dependency-path: "requirements/test.txt"
check-latest: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
pip install -r requirements/dev.txt
pip install -r requirements/test.txt
- name: Setup cache
id: cache-pytest
uses: actions/cache@v3
Expand All @@ -47,8 +47,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Run code coverage with pytest
run: |
coverage run -m pytest
coverage xml
pytest
- name: Upload code coverage to codecov.io
uses: codecov/codecov-action@v3
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,10 @@ __pycache__
test.py
node_modules/*

# Tests
!discord/ext/testing/mock_responses/*.json
!tests/assets/*.png
!tests/assets/*.json

# changelog is autogenerated from CHANGELOG.md
docs/changelog.md
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Pycord
.. image:: https://img.shields.io/github/v/release/Pycord-Development/pycord?include_prereleases&label=Latest%20Release&logo=github&sort=semver&style=for-the-badge&logoColor=white
:target: https://github.com/Pycord-Development/pycord/releases
:alt: Latest release
.. image:: https://img.shields.io/codecov/c/github/Pycord-Development/pycord?style=for-the-badge&token=15RRquov0F
:target: https://codecov.io/gh/Pycord-Development/pycord
:alt: Codecov

A fork of discord.py. Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.

Expand Down
28 changes: 15 additions & 13 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ coverage:
status:
project:
default:
target: 0%
target: auto
threshold: 1%
paths:
- discord
http:
target: 0%
flags:
- http
target: 55%
paths:
- tests/http
- discord/http.py
patch:
default:
target: 0%
target: 90%
paths:
- discord
http:
target: 0%
flags:
- http

flags:
http:
paths:
- discord/http.py
target: 100%
paths:
- tests/http
- discord/http.py
8 changes: 1 addition & 7 deletions tests/helpers.py → discord/ext/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
Expand All @@ -22,10 +21,5 @@
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import TypeVar

V = TypeVar("V")


async def coroutine(val: V) -> V:
return val
from .core import *
153 changes: 153 additions & 0 deletions discord/ext/testing/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
"""
The MIT License (MIT)

Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations

import inspect
import json
import os
from typing import Any, Callable, Iterable, Literal, Sequence
from unittest.mock import AsyncMock, MagicMock, patch

from ... import MISSING, File
from ...client import Client
from ...http import HTTPClient, Route

__all__ = (
"Test",
"Mocked",
"get_mock_response",
)


def get_mock_response(name: str) -> dict[str, Any]:
with open(
os.path.join(os.path.dirname(__file__), "mock_responses", f"{name}.json")
) as f:
return json.load(f)


class Mocked:
def __init__(
self,
name: str,
return_value: Any | Callable[[...], Any] | None = None,
approach: Literal["merge", "replace"] = "replace",
):
self.name = name
self.mock: MagicMock | AsyncMock | None = None

if callable(return_value):

async def wrapped(*args, **kwargs):
inner = return_value(*args, **kwargs)
if inspect.isawaitable(inner):
inner = await inner
if approach == "merge":
inner = dict(**get_mock_response(self.name), **inner)
return inner

self.patcher = patch.object(HTTPClient, self.name, wrapped)
self.return_value = None
else:
if return_value is None:
return_value = {}
approach = "merge"
if approach == "merge":
return_value = dict(**get_mock_response(self.name), **return_value)
self.patcher = patch.object(HTTPClient, self.name, autospec=True)
self.return_value = return_value

def __enter__(self) -> MagicMock | AsyncMock:
self.mock = self.patcher.start()
if self.return_value is not None:

async def _coro():
return self.return_value

self.mock.return_value = _coro()
return self.mock

def __exit__(self, exc_type, exc_val, exc_tb):
self.patcher.stop()


class Test:
http: HTTPClient

def __init__(self, client: Client):
self.__client = client

def patch(
self,
name: str,
return_value: Any | Callable[[...], Any] | None = None,
approach: Literal["merge", "replace"] = "replace",
) -> Mocked:
return Mocked(name, return_value, approach)

def makes_request(
self,
route: Route,
*,
files: Sequence[File] | None | MISSING = MISSING,
form: Iterable[dict[str, Any]] | None | MISSING = MISSING,
side_effect: Any | Callable[[...], Any] | None = None,
**kwargs: Any,
):
class _Request:
def __init__(
self, client: Client, route, files, form, *, side_effect, **kwargs
):
if side_effect is None:
self.patcher = patch.object(client.http, "request", autospec=True)
else:
self.patcher = patch.object(
client.http, "request", side_effect=side_effect
)
self.route = route
self.files = files
self.form = form
self.kwargs = kwargs

def __enter__(self):
self.mock = self.patcher.start()
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.patcher.stop()
if self.form is not MISSING:
self.kwargs["form"] = self.form
if self.files is not MISSING:
self.kwargs["files"] = self.files
self.mock.assert_called_once_with(
self.route,
**self.kwargs,
)

return _Request(
self.__client, route, files, form, side_effect=side_effect, **kwargs
)

def __getattr__(self, name: str) -> Any:
return getattr(self.__client, name)
25 changes: 25 additions & 0 deletions discord/ext/testing/fixtures/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
The MIT License (MIT)

Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from .core import *
from .http import *
Loading
Loading