Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
46a3b40
Most functions typed (the ones that have been left, have been left du…
mplatypus Mar 3, 2025
85b4897
replace object() with mock.Mock()
mplatypus Mar 4, 2025
81c7897
replace object() with mock.Mock()
mplatypus Mar 4, 2025
2b06574
Use Snowflake() instead of bare number.
mplatypus Mar 4, 2025
cedfab7
Add pyright test for tests in nox and to github workflows.
mplatypus Mar 16, 2025
656ef3c
Mass update of all test files (no specific error was targeted, just f…
mplatypus Mar 16, 2025
70fd372
formatting
mplatypus Mar 16, 2025
9a6a152
Added a few more FIXME's to look at, and fixed a few more tests.
mplatypus Mar 17, 2025
7e9a562
Renaming of test, and updated workflow.
mplatypus Mar 17, 2025
c14246c
Remove unnecessary fixtures
davfsa Mar 17, 2025
643f351
Add pipelines folder to pytest norecursedirs
davfsa Mar 17, 2025
b86a135
Fix CI
davfsa Mar 17, 2025
72ba12f
Fix tests leaking their context
davfsa Mar 17, 2025
f9a72bc
Merge branch 'master' into fix/typing-tests
davfsa Mar 17, 2025
c21d8e8
Reformat code
davfsa Mar 17, 2025
c4ecd29
Update pyright-tests pipeline to use new format
davfsa Mar 17, 2025
0536325
Fix failing tests
davfsa Mar 17, 2025
f0c664c
Remove duplicate mocked applications (traits.RESTAware) and move to c…
mplatypus Mar 18, 2025
0948635
Add license.
mplatypus Mar 18, 2025
ae44409
Merge branch 'master' into fix/typing-tests
davfsa Apr 8, 2025
bc8eb98
Merge branch 'master' into fix/typing-tests
davfsa Apr 8, 2025
26618df
Switch uses of MutableMapping and Mapping to dict
davfsa Apr 8, 2025
07c0ed2
Merge branch 'master' into fix/typing-tests
davfsa Apr 18, 2025
0b24f6a
Add missing dependencies
davfsa Apr 19, 2025
b975075
Merge branch 'master' into fix/typing-tests
mplatypus Apr 19, 2025
3e7f901
Removal of errors. Almost passing tests.
mplatypus Apr 19, 2025
0302010
Add pyright configuration for tests
davfsa Apr 19, 2025
4584aec
Make the pyright tests config more restrictive
davfsa Apr 19, 2025
b569258
Even more restrictive
davfsa Apr 19, 2025
7de7ee0
Cleanup MockedUser class
davfsa Apr 19, 2025
9f2331e
Use executionEnvironments for split config
davfsa Apr 19, 2025
ba71098
Fix failing tests and some more types
davfsa Apr 20, 2025
9fd4888
Fix rest of failing tests
davfsa Apr 20, 2025
f49d111
Merge branch 'fix/typing-tests' of https://github.com/mplatypus/hikar…
mplatypus May 10, 2025
fb4a613
Merge branch 'master' into fix/typing-tests
mplatypus May 12, 2025
e4dfc34
Merge branch 'master' into fix/typing-tests
mplatypus Oct 10, 2025
4d121ce
Fix workflows
mplatypus Oct 10, 2025
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ jobs:
run: |
nox -s verify-types

- name: Verify test types
if: always()
run: |
nox -s verify-test-types

- name: Flake8
if: always()
run: |
Expand Down
11 changes: 10 additions & 1 deletion pipelines/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@


# Default sessions should be defined here
_options.sessions = ["reformat-code", "codespell", "pytest", "flake8", "slotscheck", "mypy", "verify-types"]
_options.sessions = [
"reformat-code",
"codespell",
"pytest",
"flake8",
"slotscheck",
"mypy",
"verify-types",
"verify-test-types",
]
_options.default_venv_backend = venv_backend

_NoxCallbackSig = _typing.Callable[[Session], None]
Expand Down
7 changes: 7 additions & 0 deletions pipelines/pyright.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def verify_types(session: nox.Session) -> None:
"""Verify the "type completeness" of types exported by the library using Pyright."""
session.install(".", *nox.dev_requirements("pyright"))
session.run("pyright", "--verifytypes", config.MAIN_PACKAGE, "--ignoreexternal")


@nox.session()
def verify_test_types(session: nox.Session) -> None:
"""Verify the "type completeness" of the test types using Pyright."""
session.install(".", *nox.dev_requirements("pyright"))
session.run("pyright", config.TEST_PACKAGE)
126 changes: 126 additions & 0 deletions tests/hikari/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from __future__ import annotations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems a bit arbitrary, what's the idea behind it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conftest.py is a pytest feature, that allows any fixtures placed within, to be accessable to any tests within that directory (recursively). The goal for this, is to put all the fixtures that are identical, and used in more than one file, here, to minimize the amount of duplicated fixtures. I simply have not gotten around to moving them, its on my list of todo's

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats nice to know, didnt know about that feature. Would be nice to document it in the files docstring (as well as add the missing license :P)


import datetime

import mock
import pytest

from hikari import channels
from hikari import emojis
from hikari import guilds
from hikari import messages
from hikari import snowflakes
from hikari import stickers
from hikari import users


@pytest.fixture
def hikari_partial_guild() -> guilds.PartialGuild:
return guilds.PartialGuild(
app=mock.Mock(), id=snowflakes.Snowflake(123), icon_hash="partial_guild_icon_hash", name="partial_guild"
)


@pytest.fixture
def hikari_guild_text_channel() -> channels.GuildTextChannel:
return channels.GuildTextChannel(
app=mock.Mock(),
id=snowflakes.Snowflake(4560),
name="guild_text_channel_name",
type=channels.ChannelType.GUILD_TEXT,
guild_id=mock.Mock(), # FIXME: Can this be pulled from the actual fixture?
parent_id=mock.Mock(), # FIXME: Can this be pulled from the actual fixture?
Comment on lines +58 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing .id would work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, I did have it get the hikari_partial_guild object, and then use the id from it, but I kinda changed how I internally used it. This is more a me problem.

position=0,
is_nsfw=False,
permission_overwrites={},
topic=None,
last_message_id=None,
rate_limit_per_user=datetime.timedelta(seconds=10),
last_pin_timestamp=None,
default_auto_archive_duration=datetime.timedelta(seconds=10),
)


@pytest.fixture
def hikari_user() -> users.User:
return users.UserImpl(
id=snowflakes.Snowflake(789),
app=mock.Mock(),
discriminator="0",
username="user_username",
global_name="user_global_name",
avatar_hash="user_avatar_hash",
banner_hash="user_banner_hash",
accent_color=None,
is_bot=False,
is_system=False,
flags=users.UserFlag.NONE,
)


@pytest.fixture
def hikari_message() -> messages.Message:
return messages.Message(
id=snowflakes.Snowflake(101),
app=mock.Mock(),
channel_id=snowflakes.Snowflake(456),
guild_id=None,
author=mock.Mock(),
member=mock.Mock(),
content=None,
timestamp=datetime.datetime.fromtimestamp(6000),
edited_timestamp=None,
is_tts=False,
user_mentions={},
role_mention_ids=[],
channel_mentions={},
mentions_everyone=False,
attachments=[],
embeds=[],
reactions=[],
is_pinned=False,
webhook_id=snowflakes.Snowflake(432),
type=messages.MessageType.DEFAULT,
activity=None,
application=None,
message_reference=None,
flags=messages.MessageFlag.NONE,
stickers=[],
nonce=None,
referenced_message=None,
interaction=None,
application_id=None,
components=[],
thread=None,
)


@pytest.fixture
def hikari_partial_sticker() -> stickers.PartialSticker:
return stickers.PartialSticker(
id=snowflakes.Snowflake(222), name="sticker_name", format_type=stickers.StickerFormatType.PNG
)


@pytest.fixture
def hikari_guild_sticker() -> stickers.GuildSticker:
return stickers.GuildSticker(
id=snowflakes.Snowflake(2220),
name="guild_sticker_name",
format_type=stickers.StickerFormatType.PNG,
description="guild_sticker_description",
guild_id=snowflakes.Snowflake(123),
is_available=True,
tag="guild_sticker_tag",
user=None,
)


@pytest.fixture
def hikari_custom_emoji() -> emojis.CustomEmoji:
return emojis.CustomEmoji(id=snowflakes.Snowflake(444), name="custom_emoji_name", is_animated=False)


@pytest.fixture
def hikari_unicode_emoji() -> emojis.UnicodeEmoji:
return emojis.UnicodeEmoji("🙂")
15 changes: 8 additions & 7 deletions tests/hikari/events/test_base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,30 @@ def error(self):
return ex

@pytest.fixture
def event(self, error):
def event(self, error: RuntimeError) -> base_events.ExceptionEvent[mock.Mock]:
return base_events.ExceptionEvent(
exception=error, failed_event=mock.Mock(base_events.Event), failed_callback=mock.AsyncMock()
)

def test_app_property(self, event):
def test_app_property(self, event: base_events.ExceptionEvent[mock.Mock]):
app = mock.Mock()
event.failed_event.app = app
assert event.app is app

@pytest.mark.parametrize("has_shard", [True, False])
def test_shard_property(self, has_shard, event):
def test_shard_property(self, has_shard: bool, event: base_events.ExceptionEvent[mock.Mock]):
shard = mock.Mock(spec_set=gateway_shard.GatewayShard)
if has_shard:
event.failed_event.shard = shard
assert event.shard is shard
else:
assert event.shard is None

def test_exc_info_property(self, event, error):
def test_exc_info_property(self, event: base_events.ExceptionEvent[mock.Mock], error: RuntimeError):
assert event.exc_info == (type(error), error, error.__traceback__)

@pytest.mark.asyncio
async def test_retry(self, event):
await event.retry()
event.failed_callback.assert_awaited_once_with(event.failed_event)
async def test_retry(self, event: base_events.ExceptionEvent[mock.Mock]):
with mock.patch.object(event, "failed_callback") as patched_failed_callback:
await event.retry()
patched_failed_callback.assert_awaited_once_with(event.failed_event)
Loading