Skip to content
Draft
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4f4caf4
Implement minor config fixes
MattyTheHacker May 31, 2025
b644f3a
Implement minor workflow fixes
MattyTheHacker May 31, 2025
2567f2b
fix stuff
MattyTheHacker May 31, 2025
a458f3b
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 31, 2025
d1387ab
Start work on utils tests
MattyTheHacker Jun 2, 2025
75b85e0
Merge branch 'testing-workflow-changes' into test-utils
MattyTheHacker Jun 2, 2025
57fb108
Merge branch 'main' into test-utils
MattyTheHacker Jun 3, 2025
e93bd2c
Merge main into test-utils
cssbhamdev Jun 12, 2025
cb7cf6c
Merge main into test-utils
cssbhamdev Jun 13, 2025
dfa40e7
Merge main into test-utils
cssbhamdev Jun 13, 2025
c942229
Merge main into test-utils
cssbhamdev Jun 14, 2025
1a6ff75
Allow committee-elect to update actions (and appear in auto-complete)…
Thatsmusic99 Jun 15, 2025
44d3ea1
Merge main into test-utils
cssbhamdev Jun 15, 2025
74bd977
Merge main into test-utils
cssbhamdev Jun 15, 2025
dbfd694
Merge main into test-utils
cssbhamdev Jun 15, 2025
ff96866
Merge main into test-utils
cssbhamdev Jun 15, 2025
4a5578c
Merge main into test-utils
cssbhamdev Jun 16, 2025
873f25e
Merge branch 'main' into test-utils
MattyTheHacker Jun 21, 2025
6e7318c
fix
MattyTheHacker Jun 21, 2025
10ddb69
Merge main into test-utils
cssbhamdev Jun 22, 2025
1cd4acb
Merge main into test-utils
cssbhamdev Jun 24, 2025
bcb6b1d
Merge main into test-utils
cssbhamdev Jun 24, 2025
0ffd171
Merge main into test-utils
cssbhamdev Jun 24, 2025
24dc67d
Merge main into test-utils
cssbhamdev Jun 25, 2025
31bdf10
Merge main into test-utils
cssbhamdev Jun 30, 2025
96d9ae6
Merge main into test-utils
automatic-pr-updater[bot] Jun 30, 2025
e06dfd5
Merge main into test-utils
automatic-pr-updater[bot] Jul 2, 2025
a7d9db5
Merge main into test-utils
automatic-pr-updater[bot] Jul 2, 2025
7811ce2
Merge main into test-utils
automatic-pr-updater[bot] Jul 3, 2025
1f34612
Merge main into test-utils
automatic-pr-updater[bot] Jul 3, 2025
e29f85a
Merge main into test-utils
automatic-pr-updater[bot] Jul 3, 2025
13bc29b
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
7b83124
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
0f5e39a
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
a043af5
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
58d96da
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
d344286
Merge main into test-utils
automatic-pr-updater[bot] Jul 4, 2025
4b2be90
Merge main into test-utils
automatic-pr-updater[bot] Jul 5, 2025
d6a7d70
Merge main into test-utils
automatic-pr-updater[bot] Jul 5, 2025
d3236b4
Merge main into test-utils
automatic-pr-updater[bot] Jul 5, 2025
f077f25
Merge main into test-utils
automatic-pr-updater[bot] Jul 5, 2025
b6650c0
Merge main into test-utils
automatic-pr-updater[bot] Jul 5, 2025
34a1e4a
Merge main into test-utils
automatic-pr-updater[bot] Jul 6, 2025
e6acc4c
Merge main into test-utils
automatic-pr-updater[bot] Jul 7, 2025
1794b23
Merge main into test-utils
automatic-pr-updater[bot] Jul 9, 2025
7eb1e79
Merge main into test-utils
automatic-pr-updater[bot] Jul 9, 2025
dcf6b30
Merge main into test-utils
automatic-pr-updater[bot] Jul 11, 2025
21dada1
Merge main into test-utils
automatic-pr-updater[bot] Jul 14, 2025
f79c415
Merge main into test-utils
automatic-pr-updater[bot] Jul 21, 2025
9f61b85
Merge main into test-utils
automatic-pr-updater[bot] Jul 21, 2025
b5abd66
Merge main into test-utils
automatic-pr-updater[bot] Jul 22, 2025
4d6d68c
Merge main into test-utils
automatic-pr-updater[bot] Jul 28, 2025
fff6226
Merge main into test-utils
automatic-pr-updater[bot] Jul 29, 2025
7943fd4
Merge main into test-utils
automatic-pr-updater[bot] Aug 1, 2025
11a806c
Merge main into test-utils
automatic-pr-updater[bot] Aug 4, 2025
fcffd36
Merge main into test-utils
automatic-pr-updater[bot] Aug 5, 2025
5170217
Merge main into test-utils
automatic-pr-updater[bot] Aug 5, 2025
bea5123
Merge main into test-utils
automatic-pr-updater[bot] Aug 7, 2025
8367d59
Merge main into test-utils
automatic-pr-updater[bot] Aug 9, 2025
2356360
Merge main into test-utils
automatic-pr-updater[bot] Aug 11, 2025
db8bfed
Merge main into test-utils
automatic-pr-updater[bot] Aug 11, 2025
2d1b24b
Merge main into test-utils
automatic-pr-updater[bot] Aug 12, 2025
4bd3072
Merge main into test-utils
automatic-pr-updater[bot] Aug 18, 2025
a56dbf4
Merge main into test-utils
automatic-pr-updater[bot] Aug 26, 2025
00f9e4f
Merge main into test-utils
automatic-pr-updater[bot] Aug 26, 2025
e37b192
Merge main into test-utils
automatic-pr-updater[bot] Aug 28, 2025
007fb50
Merge main into test-utils
automatic-pr-updater[bot] Aug 29, 2025
98181f9
Merge main into test-utils
automatic-pr-updater[bot] Aug 29, 2025
21e4805
Merge main into test-utils
automatic-pr-updater[bot] Aug 29, 2025
2adc2c5
Merge main into test-utils
automatic-pr-updater[bot] Aug 30, 2025
055a2a2
Merge main into test-utils
automatic-pr-updater[bot] Sep 2, 2025
d1b2977
Merge main into test-utils
automatic-pr-updater[bot] Sep 2, 2025
676ecf4
Merge main into test-utils
automatic-pr-updater[bot] Sep 4, 2025
4e49a67
Merge main into test-utils
automatic-pr-updater[bot] Sep 4, 2025
709fc61
Merge main into test-utils
automatic-pr-updater[bot] Sep 5, 2025
e407400
Merge main into test-utils
automatic-pr-updater[bot] Sep 5, 2025
ec2864c
Merge main into test-utils
automatic-pr-updater[bot] Sep 7, 2025
1510e0d
Merge main into test-utils
automatic-pr-updater[bot] Sep 9, 2025
92ed304
Merge main into test-utils
automatic-pr-updater[bot] Sep 9, 2025
4a6d771
Merge main into test-utils
automatic-pr-updater[bot] Sep 12, 2025
a30ce60
Merge main into test-utils
automatic-pr-updater[bot] Sep 12, 2025
555a987
Merge main into test-utils
automatic-pr-updater[bot] Sep 13, 2025
64e3ea0
Merge main into test-utils
automatic-pr-updater[bot] Sep 15, 2025
0449882
Merge main into test-utils
automatic-pr-updater[bot] Sep 16, 2025
b975096
Merge main into test-utils
automatic-pr-updater[bot] Sep 16, 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
86 changes: 20 additions & 66 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test suite for utils package."""

import asyncio
import random
import re
from typing import TYPE_CHECKING
Expand All @@ -12,72 +13,6 @@

__all__: "Sequence[str]" = ()

# TODO(CarrotManMatt): Move to stats_tests # noqa: FIX002
# https://github.com/CSSUoB/TeX-Bot-Py-V2/issues/57
# class TestPlotBarChart:
# """Test case to unit-test the plot_bar_chart function."""
#
# def test_bar_chart_generates(self) -> None:
# """Test that the bar chart generates successfully when valid arguments are passed.""" # noqa: ERA001, E501, W505
# FILENAME: Final[str] = "output_chart.png" # noqa: ERA001
# DESCRIPTION: Final[str] = "Bar chart of the counted value of different roles." # noqa: ERA001, E501, W505
#
# bar_chart_image: discord.File = plot_bar_chart(
# data={"role1": 5, "role2": 7}, # noqa: ERA001
# x_label="Role Name", # noqa: ERA001
# y_label="Counted value", # noqa: ERA001
# title="Counted Value Of Each Role", # noqa: ERA001
# filename=FILENAME, # noqa: ERA001
# description=DESCRIPTION, # noqa: ERA001
# extra_text="This is extra text" # noqa: ERA001
# ) # noqa: ERA001, RUF100
#
# assert bar_chart_image.filename == FILENAME # noqa: ERA001
# assert bar_chart_image.description == DESCRIPTION # noqa: ERA001
# assert bool(bar_chart_image.fp.read()) is True # noqa: ERA001


# TODO(CarrotManMatt): Move to stats_tests # noqa: FIX002
# https://github.com/CSSUoB/TeX-Bot-Py-V2/issues/57
# class TestAmountOfTimeFormatter:
# """Test case to unit-test the amount_of_time_formatter function."""
#
# @pytest.mark.parametrize(
# "time_value",
# (1, 1.0, 0.999999, 1.000001) # noqa: ERA001
# ) # noqa: ERA001, RUF100
# def test_format_unit_value(self, time_value: float) -> None:
# """Test that a value of one only includes the time_scale."""
# TIME_SCALE: Final[str] = "day" # noqa: ERA001
#
# formatted_amount_of_time: str = amount_of_time_formatter(time_value, TIME_SCALE) # noqa: ERA001, E501, W505
#
# assert formatted_amount_of_time == TIME_SCALE # noqa: ERA001
# assert not formatted_amount_of_time.endswith("s") # noqa: ERA001
#
# @pytest.mark.parametrize(
# "time_value",
# (*range(2, 21), 2.00, 0, 0.0, 25.0, -0, -0.0, -25.0) # noqa: ERA001
# ) # noqa: ERA001, RUF100
# def test_format_integer_value(self, time_value: float) -> None:
# """Test that an integer value includes the value and time_scale pluralized."""
# TIME_SCALE: Final[str] = "day" # noqa: ERA001
#
# assert amount_of_time_formatter(
# time_value,
# TIME_SCALE
# ) == f"{int(time_value)} {TIME_SCALE}s"
#
# @pytest.mark.parametrize("time_value", (3.14159, 0.005, 25.0333333))
# def test_format_float_value(self, time_value: float) -> None:
# """Test that a float value includes the rounded value and time_scale pluralized."""
# TIME_SCALE: Final[str] = "day" # noqa: ERA001
#
# assert amount_of_time_formatter(
# time_value,
# TIME_SCALE
# ) == f"{time_value:.2f} {TIME_SCALE}s"


class TestGenerateInviteURL:
"""Test case to unit-test the generate_invite_url utility function."""
Expand Down Expand Up @@ -106,3 +41,22 @@ def test_url_generates() -> None:
),
invite_url,
)


class TestIsRunningInAsync:
"""Test case to unit-test the is_running_in_async utility function."""

@staticmethod
def test_is_running_in_async() -> None:
"""Test that the is_running_in_async function returns True when called in an async context.""" # noqa: E501, W505

async def async_test() -> None:
"""Async function to test the is_running_in_async utility."""
assert utils.is_running_in_async() is True

asyncio.run(async_test())

@staticmethod
def test_is_not_running_in_async() -> None:
"""Test that the is_running_in_async function returns False when called in a non-async context.""" # noqa: E501, W505
assert utils.is_running_in_async() is False