Skip to content

Commit 1a77549

Browse files
Merge pull request #68 from discord-modmail/tests/more-tests
more tests adds mocked objects, and a better test structure
2 parents 4aa8091 + 3d6b29d commit 1a77549

File tree

13 files changed

+1431
-95
lines changed

13 files changed

+1431
-95
lines changed

modmail/bot.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def __init__(self, **kwargs):
4949
# allow only user mentions by default.
5050
# ! NOTE: This may change in the future to allow roles as well
5151
allowed_mentions = AllowedMentions(everyone=False, users=True, roles=False, replied_user=True)
52+
# override passed kwargs if they are None
53+
kwargs["case_insensitive"] = kwargs.get("case_insensitive", True)
54+
# do not let the description be overridden.
55+
kwargs["description"] = "Modmail bot by discord-modmail."
56+
kwargs["status"] = kwargs.get("status", status)
57+
kwargs["activity"] = kwargs.get("activity", activity)
58+
kwargs["allowed_mentions"] = kwargs.get("allowed_mentions", allowed_mentions)
59+
kwargs["command_prefix"] = kwargs.get("command_prefix", prefix)
60+
kwargs["intents"] = kwargs.get("intents", REQUIRED_INTENTS)
5261
super().__init__(
53-
case_insensitive=True,
54-
description="Modmail bot by discord-modmail.",
55-
status=status,
56-
activity=activity,
57-
allowed_mentions=allowed_mentions,
58-
command_prefix=prefix,
59-
intents=REQUIRED_INTENTS,
6062
**kwargs,
6163
)
6264

modmail/extensions/utils/error_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
ERROR_COLOUR = discord.Colour.red()
2020

21-
ERROR_TITLE_REGEX = re.compile(r"(?<=[a-zA-Z])([A-Z])(?=[a-z])")
21+
ERROR_TITLE_REGEX = re.compile(r"((?<=[a-z])[A-Z]|(?<=[a-zA-Z])[A-Z](?=[a-z]))")
2222

2323
ANY_DEV_MODE = BOT_MODE & (BotModes.DEVELOP.value + BotModes.PLUGIN_DEV.value)
2424

poetry.lock

Lines changed: 43 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ isort = "^5.9.2"
4545
pep8-naming = "~=0.11"
4646
# testing
4747
codecov = "^2.1.11"
48-
coverage = { extras = ["toml"], version = "^5.5" }
48+
coverage = { extras = ["toml"], version = "^6.0.2" }
4949
pytest = "^6.2.4"
5050
pytest-asyncio = "^0.15.1"
51-
pytest-cov = "^2.12.1"
51+
pytest-cov = "^3.0.0"
5252
pytest-dependency = "^0.5.1"
5353
pytest-sugar = "^0.9.4"
5454
pytest-xdist = { version = "^2.3.0", extras = ["psutil"] }
@@ -63,13 +63,13 @@ build-backend = "poetry.core.masonry.api"
6363

6464
[tool.coverage.run]
6565
branch = true
66-
source_pkgs = ["modmail"]
66+
source_pkgs = ['modmail', 'tests.modmail']
6767
omit = ["modmail/plugins/**.*"]
6868

6969
[tool.pytest.ini_options]
7070
addopts = "--cov --cov-report="
7171
minversion = "6.0"
72-
testpaths = ["tests"]
72+
testpaths = ["tests/modmail"]
7373

7474
[tool.black]
7575
line-length = 110
@@ -89,3 +89,4 @@ lint = { cmd = "pre-commit run --all-files", help = "Checks all files for CI err
8989
precommit = { cmd = "pre-commit install --install-hooks", help = "Installs the precommit hook" }
9090
report = { cmd = "coverage report", help = "Show coverage report from previously run tests." }
9191
test = { cmd = "pytest -n auto --dist loadfile", help = "Runs tests and save results to a coverage report" }
92+
test_mocks = { cmd = 'pytest tests/test_mocks.py', help = 'Runs the tests on the mock files. They are excluded from the main test suite.' }

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

33

4-
def pytest_report_header(config):
4+
def pytest_report_header(config) -> str:
55
"""Pytest headers."""
66
return "package: modmail"

0 commit comments

Comments
 (0)