forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Setup a fully featured test setup and add initial tests on utils #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Paillat-dev
wants to merge
108
commits into
master
Choose a base branch
from
feat/tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 97 commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
17766df
Move utils.py to utils/
Paillat-dev 195e2a0
:fire: Remove `filter_params`
Paillat-dev fafa149
:recycle: Merge `time_snowflake` and `generate_snowflake`, move `basi…
Paillat-dev e2d8eb1
:recycle: Merge `time_snowflake` and `generate_snowflake`, move `basi…
Paillat-dev 86bd168
:fire: Remove `utils.sleep_until`
Paillat-dev 23c2c49
chore: Start migration to uv & ruff & hatch (#4)
Paillat-dev 97ccda5
Setup CHANGELOG.md (#6)
Paillat-dev f2a4eb6
chore: update docs workflows to use 'uv' for dependency management (#33)
Paillat-dev 40e20c0
:fire: Move stuff to private
Paillat-dev 6e5ccb5
Merge branch 'master' into refactor-utils
Paillat-dev 1da5de0
:refactor: move parse_time function to private utils and update refer…
Paillat-dev 88180b2
:memo: update CHANGELOG to reflect utility function changes
Paillat-dev b5c8a58
:art: Format
Paillat-dev 0cdcb31
:recycle: move deprecation utilities to private utils and update refe…
Paillat-dev 09a11a9
:recycle: move snowflake_time function to public.py
Paillat-dev 4a2753c
:recycle: move oauth_url and Undefined class to public.py; update imp…
Paillat-dev ca89539
Merge branch 'master' into refactor-utils
Paillat-dev 1cf53ab
:memo: remove deprecated utility functions from documentation
Paillat-dev 2ac8152
:memo: remove (re)moved utility functions from documentation
Paillat-dev 24a367c
:memo: add utils.resolve_template to changelog and remove from docume…
Paillat-dev 0c6270a
:bug: fix import path for warn_deprecated utility function
Paillat-dev 84ff9df
:refactor: reorganize utility function imports and move evaluate_anno…
Paillat-dev 8474f05
:recycle: update import paths for utility functions to use relative i…
Paillat-dev c8ddcb5
:recycle: move delay_task function to private
Paillat-dev 8a02d54
:recycle: removed `utils.get` in favor of `utils.find`
Paillat-dev 39aef0f
:recycle: removed `utils._unique`
Paillat-dev 6b0379c
:recycle: move `async_all` to private
Paillat-dev cc8f27f
:recycle: move `maybe_coroutine` to private
Paillat-dev 1d70dec
:recycle: rename `maybe_coroutine` to `maybe_awaitable`
Paillat-dev b2b8625
:recycle: move `sane_wait_for` to private
Paillat-dev d0a094d
:recycle: move `format_dt` to public
Paillat-dev fb554fd
:recycle: remove `as_chunks` function
Paillat-dev 1a551cb
:memo: update `utils.sleep_until` and `utils.parse_time` changelog to…
Paillat-dev 295ed46
:recycle: move `compute_timedelta` function
Paillat-dev 4afe54a
:recycle: move `valid_icon_size` to `asset.py`
Paillat-dev a021450
:recycle: refactor `utils.get` to `utils.find` across multiple files
Paillat-dev c6f7914
:recycle: refactor markdown and mention handling functions in `__init…
Paillat-dev c29cdc2
:recycle: move SnowflakeList to `private.py`
Paillat-dev 6c57d5e
:recycle: move `find` function from `__init__.py` to `public.py`
Paillat-dev d079c7c
:recycle: move `copy_doc` to private
Paillat-dev 611c7c7
:recycle: refactor `get` to `find` in onboarding and sticker modules
Paillat-dev cd4e436
:bug: fix `copy_doc` decorator usage in context.py
Paillat-dev ad777e4
Merge branch 'master' into refactor-utils
Paillat-dev aec45a2
:recycle: move SequenceProxy to private module
Paillat-dev 9755fe8
:recycle: move cached_slot_property to private
Paillat-dev 006a7f8
:rotating_light: add noqa comments to prevent linting errors
Paillat-dev d5263c7
:recycle: move get_slots function to private module
Paillat-dev 44f753e
:recycle: refactor JSON serialization functions to private module
Paillat-dev c961e36
:recycle: replace custom cached_property implementation with functool…
Paillat-dev a4bda5f
:pencil2: fix typo in CHANGELOG-V3.md
Paillat-dev b81d2d5
:heavy_minus_sign: remove unused dependencies from pyproject.toml and…
Paillat-dev a84e06d
:coffin: remove test.py
Paillat-dev 330161c
:recycle: remove duplicate import of raw_mentions in __init__.py
Paillat-dev b3f919e
:bug: fix raw_role_mentions import in utils/__init__.py
Paillat-dev 8d76921
:bug: fix dictionary access in test_typing_annotated.py to be type safe
Paillat-dev 77bf9c3
:coffin: Remove dead tests
Paillat-dev c7a7a77
Merge branch 'refactor-utils' into feat/tests
Paillat-dev d93aa3d
:white_check_mark: add tox configuration and update dependencies in p…
Paillat-dev 15449c6
:coffin: remove unused reveal_type calls in private.py
Paillat-dev a3b6eb9
:white_check_mark: add test workflow to GitHub Actions for multiple O…
Paillat-dev f3a8f1e
:pushpin: move pytest and pytest-asyncio to test dependencies in pypr…
Paillat-dev e2a4367
:white_check_mark: add unit tests for markdown related utils
Paillat-dev 414e0fe
:white_check_mark: add unit tests for format_dt
Paillat-dev 3870d73
:white_check_mark: add unit tests for snowflake generation and time c…
Paillat-dev 96e5cce
:white_check_mark: add unit tests for discord.utils.find functionality
Paillat-dev 352d1b6
:page_facing_up: add license headers to test files
Paillat-dev e58e310
:bug: fix test for find function to use == instead of is
Paillat-dev 0c9272d
:fire: Duplicate `Iterable` import
Paillat-dev 2b981dd
Apply suggestion from @Lumabots
Paillat-dev 488c4de
Merge branch 'master' into refactor-utils
Paillat-dev df155d6
:fire: Simplify imports
Paillat-dev 7d92da0
:fire: Simplify imports number 2
Paillat-dev 856853f
:fire: Simplify imports number 3 omg this is amazing
Paillat-dev e32ba97
:fire: Simplify imports number 4 omg this is amazing yee
Paillat-dev d1be746
:fire: Simplify imports number 5
Paillat-dev bd59784
Update discord/ext/commands/converter.py
Paillat-dev 34d5fde
Apply suggestions from code review
Paillat-dev 5ef78ca
Update discord/state.py
Paillat-dev 0acef26
Update discord/state.py
Paillat-dev c7db59c
:recycle: Remove _ prefix in from and to json
Paillat-dev 0ca346d
:recycle: Make import less weird
Paillat-dev 2a0427c
Update utils.po
Paillat-dev 11e311d
empty commit
Paillat-dev 32ed673
Update discord/poll.py
Paillat-dev 0df56df
Update discord/utils/private.py
Paillat-dev cb5b0cd
Merge branch 'master' into refactor-utils
Paillat-dev 51df432
:bug: Fix broken import after merge
Paillat-dev 6ec99f2
:bug: Fix emojis.json path
Paillat-dev 68a0fe3
:bug: Fix broken imports
Paillat-dev 3dd1216
:art: Format stuff
Paillat-dev 0d27afe
:bug: Fix import
Paillat-dev e202d7e
Merge branch 'master' into refactor-utils
Paillat-dev 049517e
chore(deps): upgrade pre-commit hook astral-sh/ruff-pre-commit to v0.…
renovate[bot] 580435a
Merge branch 'refactor-utils' into feat/tests
Paillat-dev 052b54c
Merge branch 'master' into feat/tests
Paillat-dev 26b4fe3
Merge branch 'master' into feat/tests
Paillat-dev 55c49b4
Merge branch 'master' into feat/tests
Paillat-dev b05b56f
Apply suggestions from code review
Paillat-dev 6ea3e05
Merge branch 'master' into feat/tests
Paillat-dev c085a07
feat: Add type annotations and refactor test utilities (#133)
Lumabots 8bdde08
Merge branch 'master' into feat/tests
Paillat-dev 2b34e3d
:bug: Fix Luma introduced issues cuz typing
Paillat-dev 5391fa0
:rotating_light: Fix pytest warnings
Paillat-dev 1dadf88
:bug: Use mypy suggested method for array.array genericness
Paillat-dev a1221d9
:art: Format code
Paillat-dev 93d095e
fix: type annotations and import order in utils and tests (#138)
Lumabots 174b2c1
Update pyproject.toml
Paillat-dev f4fd0b7
Merge branch 'master' into feat/tests
Paillat-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
* @Pycord-Development/pycord-next-contributors | ||
* @Pycord-Development/pycord-next-contributors | ||
|
||
/.github @Lulalaby | ||
/crowdin.yml @Pycord-Development/maintain-translations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
Union, | ||
Coroutine, | ||
Awaitable, | ||
reveal_type, | ||
Generic, | ||
Sequence, | ||
Iterator, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
""" | ||
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. | ||
""" | ||
|
||
import pytest | ||
from discord.utils import find | ||
|
||
|
||
def is_even(x): | ||
return x % 2 == 0 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("seq", "predicate", "expected"), | ||
[ | ||
([], lambda x: True, None), | ||
([1, 2, 3], lambda x: x > 3, None), | ||
([1, 2, 3], lambda x: x == 1, 1), | ||
([1, 2, 3], lambda x: x == 2, 2), | ||
("abc", lambda c: c == "b", "b"), | ||
((10, 20, 30), lambda x: x == 30, 30), | ||
([None, False, 0], lambda x: x is None, None), | ||
([1, 2, 3, 4], is_even, 2), | ||
], | ||
) | ||
def test_find_basic_parametrized(seq, predicate, expected): | ||
result = find(predicate, seq) | ||
if expected is None: | ||
assert result is None | ||
else: | ||
assert result == expected | ||
|
||
|
||
def test_find_with_truthy_non_boolean_predicate(): | ||
seq = [2, 4, 5, 6] | ||
result = find(lambda x: x % 2, seq) | ||
assert result == 5 | ||
|
||
|
||
def test_find_on_generator_and_stop_early(): | ||
def bad_gen(): | ||
yield "first" | ||
raise RuntimeError("should not be reached") | ||
|
||
assert find(lambda x: x == "first", bad_gen()) == "first" | ||
|
||
|
||
def test_find_does_not_evaluate_rest(): | ||
calls = [] | ||
|
||
def predicate(x): | ||
calls.append(x) | ||
return x == "stop" | ||
|
||
seq = ["go", "stop", "later"] | ||
result = find(predicate, seq) | ||
assert result == "stop" | ||
assert calls == ["go", "stop"] | ||
|
||
|
||
def test_find_with_set_returns_first_iterated_element(): | ||
data = {"a", "b", "c"} | ||
result = find(lambda x: x in data, data) | ||
assert result in data | ||
|
||
|
||
def test_find_none_predicate(): | ||
seq = [42, 43, 44] | ||
result = find(lambda x: True, seq) | ||
assert result == 42 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
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. | ||
""" | ||
|
||
import datetime | ||
import random | ||
import pytest | ||
from discord.utils import format_dt | ||
|
||
# Fix seed so that time tests are reproducible | ||
random.seed(42) | ||
|
||
ALL_STYLES = ["t", "T", "d", "D", "f", "F", "R", None] | ||
|
||
DATETIME_CASES = [ | ||
(datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc), 0), | ||
(datetime.datetime(2000, 2, 29, 12, 0, 0, tzinfo=datetime.timezone.utc), 951825600), | ||
(datetime.datetime(1999, 12, 31, 23, 59, 59, tzinfo=datetime.timezone.utc), 946684799), | ||
(datetime.datetime(2023, 1, 2, 3, 4, 5, tzinfo=datetime.timezone.utc), 1672628645), | ||
(datetime.datetime(2050, 6, 15, 7, 30, 0, tzinfo=datetime.timezone.utc), 2538891000), | ||
] | ||
|
||
|
||
def random_time(): | ||
return datetime.time( | ||
random.randint(0, 23), | ||
random.randint(0, 59), | ||
random.randint(0, 59), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize(("dt", "expected_ts"), DATETIME_CASES) | ||
@pytest.mark.parametrize("style", ALL_STYLES) | ||
def test_format_dt_formats_datetime(dt, expected_ts, style): | ||
if style is None: | ||
expected = f"<t:{expected_ts}>" | ||
else: | ||
expected = f"<t:{expected_ts}:{style}>" | ||
result = format_dt(dt, style=style) | ||
assert result == expected | ||
|
||
|
||
@pytest.mark.parametrize("style", ALL_STYLES) | ||
def test_format_dt_formats_time_equivalence(style): | ||
tm = random_time() | ||
today = datetime.datetime.now().date() | ||
result_time = format_dt(tm, style=style) | ||
dt = datetime.datetime.combine(today, tm) | ||
result_dt = format_dt(dt, style=style) | ||
assert result_time == result_dt |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.