Skip to content

mock

Mock Plugin for Tux Bot.

This plugin provides error testing and debugging functionality, allowing developers to trigger various error conditions and test error handling mechanisms in the bot.

Classes:

  • MockParameter

    Mock parameter object for testing purposes.

  • MockFlag

    Mock flag object for testing purposes.

  • MockObject

    A simple mock object that accepts arbitrary attributes.

  • ErrorTestDefinition

    Defines how to construct and test a specific error type.

  • ErrorTestRegistry

    Dynamic registry of errors that can be tested, based on the actual error handler.

  • Mock

    Mock plugin for Tux Bot.

Functions:

  • setup

    Cog setup for event handler.

Classes

MockParameter

Python
MockParameter(name: str)

Mock parameter object for testing purposes.

Initialize a mock parameter.

Parameters:

  • name (str) –

    The name of the parameter.

Methods:

  • __repr__

    Return string representation of the mock parameter.

Functions

__repr__
Python
__repr__() -> str

Return string representation of the mock parameter.

Returns:

  • str

    String representation.

MockFlag

Python
MockFlag(name: str)

Mock flag object for testing purposes.

Initialize a mock flag.

Parameters:

  • name (str) –

    The name of the flag.

Methods:

  • __repr__

    Return string representation of the mock flag.

Functions

__repr__
Python
__repr__() -> str

Return string representation of the mock flag.

Returns:

  • str

    String representation.

MockObject

Python
MockObject(**kwargs: Any)

A simple mock object that accepts arbitrary attributes.

Initialize the mock object with arbitrary attributes.

Parameters:

  • **kwargs (Any, default: {} ) –

    Arbitrary keyword arguments to set as attributes.

Methods:

  • __repr__

    Return a string representation of the mock object.

Functions

__repr__
Python
__repr__() -> str

Return a string representation of the mock object.

Returns:

  • str

    String representation showing all attributes.

ErrorTestDefinition

Python
ErrorTestDefinition(
    error_class: type[Exception],
    args: tuple[Any, ...] = (),
    kwargs: dict[str, Any] | None = None,
    description: str = "",
    category: str = "General",
)

Defines how to construct and test a specific error type.

Initialize an error test definition.

Parameters:

  • error_class (type[Exception]) –

    The exception class to test.

  • args (tuple[Any, ...], default: () ) –

    Positional arguments for error construction.

  • kwargs (dict[str, Any] | None, default: None ) –

    Keyword arguments for error construction.

  • description (str, default: '' ) –

    Description of the error test.

  • category (str, default: 'General' ) –

    Category for organizing error tests.

Methods:

  • create_error

    Create an instance of this error for testing.

  • get_config

    Get the error handler configuration for this error type.

Functions

create_error
Python
create_error() -> Exception

Create an instance of this error for testing.

Returns:

  • Exception

    An instance of the configured error class.

get_config
Python
get_config() -> dict[str, Any] | None

Get the error handler configuration for this error type.

Returns:

  • dict[str, Any] | None

    Error handler configuration dict, or None if not configured.

ErrorTestRegistry

Python
ErrorTestRegistry()

Dynamic registry of errors that can be tested, based on the actual error handler.

Initialize the error test registry.

Methods:

Functions

_build_test_registry
Python
_build_test_registry() -> None

Build test cases dynamically from ERROR_CONFIG_MAP.

_add_test
Python
_add_test(
    name: str,
    error_class: type[Exception],
    args: tuple[Any, ...] = (),
    description: str = "",
    category: str = "General",
) -> None

Add a test case to the registry.

_add_app_command_test
Python
_add_app_command_test(error_type: type[Exception]) -> None

Add app command specific test cases.

_get_realistic_app_command_args
Python
_get_realistic_app_command_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for app command errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the error type.

_add_traditional_command_test
Python
_add_traditional_command_test(error_type: type[Exception]) -> None

Add traditional command specific test cases.

_get_realistic_traditional_command_args
Python
_get_realistic_traditional_command_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for traditional command errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the error type.

_add_discord_api_test
Python
_add_discord_api_test(error_type: type[Exception]) -> None

Add Discord API specific test cases.

_get_realistic_discord_args
Python
_get_realistic_discord_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for Discord API errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the error type.

_add_httpx_test
Python
_add_httpx_test(error_type: type[Exception]) -> None

Add HTTPX error test cases.

_add_builtin_test
Python
_add_builtin_test(error_type: type[Exception]) -> None

Add Python built-in error test cases for unhandled error testing.

_get_realistic_httpx_args
Python
_get_realistic_httpx_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for HTTPX errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the HTTPX error type.

_get_realistic_builtin_args
Python
_get_realistic_builtin_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for Python built-in errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the error type.

_add_custom_test
Python
_add_custom_test(error_type: type[Exception]) -> None

Add custom error test cases for tux module errors.

_get_realistic_custom_args
Python
_get_realistic_custom_args(error_name: str) -> tuple[Any, ...]

Get realistic arguments for custom tux errors.

Returns:

  • tuple[Any, ...]

    Arguments appropriate for the error type.

get_test_names
Python
get_test_names() -> list[str]

Get all test names.

Returns:

  • list[str]

    List of all registered test names.

get_test_names_by_category
Python
get_test_names_by_category() -> dict[str, list[str]]

Get test names grouped by category.

Returns:

  • dict[str, list[str]]

    Dictionary mapping category names to lists of test names.

get_test
Python
get_test(name: str) -> ErrorTestDefinition | None

Get a specific test by name.

Returns:

Mock

Python
Mock(bot: Tux)

Bases: BaseCog

Mock plugin for Tux Bot.

Initialize the Mock cog.

Parameters:

  • bot (Tux) –

    The bot instance.

Methods:

  • get_config

    Get a configuration value from CONFIG with support for nested keys.

  • __repr__

    Return a string representation of the cog instance.

  • unload_if_missing_config

    Check if required configuration is missing and log warning.

  • mock

    Command group for mocking various bot behaviors.

  • error_name_autocomplete

    Autocomplete function for error names based on the selected category.

  • mock_error

    Raise a specified error to test the global error handler.

  • error_type_autocomplete

    Autocomplete function for error types with category information.

  • mock_test

    Alternative error testing command with autocomplete support.

Attributes:

Attributes

db property

Get the database coordinator for accessing database controllers.

Returns:

  • DatabaseCoordinator

    Coordinator providing access to all database controllers.

Examples:

Python Console Session
>>> await self.db.guild_config.get_guild_config(guild_id)
>>> await self.db.cases.create_case(...)
Notes

This property provides convenient access to database operations without needing to access self.bot.db directly.

Functions

_setup_command_usage
Python
_setup_command_usage() -> None

Generate usage strings for all commands in this cog that lack explicit usage.

The generated usage follows the pattern: <qualified_name> <param tokens>

Where: - Required parameters are denoted as <name: Type> - Optional parameters are denoted as [name: Type] - The prefix is intentionally omitted (provided by ctx.prefix)

Examples:

ban <member: Member> [reason: str] config set <key: str> <value: str>

Notes

Respects explicit usage strings if already set on a command. Errors during generation are logged but don't prevent cog loading.

_generate_usage
Python
_generate_usage(command: Command[Any, ..., Any]) -> str

Generate a usage string with support for flags and positional parameters.

This method inspects the command's callback signature to detect: - FlagConverter parameters (e.g., --flag value) - Positional parameters (e.g., <required> or [optional])

Parameters:

  • command (Command) –

    The command to generate usage for.

Returns:

  • str

    Generated usage string, or qualified command name as fallback.

Notes

Delegates to shared usage generator for consistency across all cogs. Falls back gracefully to command name if generation fails.

get_config
Python
get_config(key: str, default: Any = None) -> Any

Get a configuration value from CONFIG with support for nested keys.

Parameters:

  • key (str) –

    The configuration key to retrieve. Supports dot notation for nested values (e.g., "BOT_INFO.BOT_NAME").

  • default (Any, default: None ) –

    Default value to return if key is not found, by default None.

Returns:

  • Any

    The configuration value or default if not found.

Examples:

Python Console Session
>>> self.get_config("BOT_INFO.BOT_NAME")
'Tux'
>>> self.get_config("MISSING_KEY", "fallback")
'fallback'
Notes

Errors during retrieval are logged but don't raise exceptions. Returns the default value on any error.

__repr__
Python
__repr__() -> str

Return a string representation of the cog instance.

Returns:

  • str

    String representation in format <CogName bot=BotUser>.

unload_if_missing_config
Python
unload_if_missing_config(condition: bool, config_name: str) -> bool

Check if required configuration is missing and log warning.

This allows cogs to detect missing configuration at load time and return early from init to prevent partial initialization.

Parameters:

  • condition (bool) –

    True if config is missing (should unload), False otherwise.

  • config_name (str) –

    Name of the missing configuration for logging purposes.

Returns:

  • bool

    True if config is missing (caller should return early), False if config is present.

Examples:

Python Console Session
>>> def __init__(self, bot: Tux):
...     super().__init__(bot)
...     if self.unload_if_missing_config(not CONFIG.GITHUB_TOKEN, "GITHUB_TOKEN"):
...         return  # Exit early, cog will be partially loaded but won't register commands
...     self.github_client = GitHubClient()
Notes

When this returns True, the cog's init should return early to avoid initializing services that depend on the missing config. The cog will be loaded but commands won't be registered properly, preventing runtime errors.

For complete cog unloading, the bot owner should remove the cog from the modules directory or use the reload system to unload it programmatically.

_unload_self async
Python
_unload_self(extension_name: str) -> None

Perform the actual cog unload operation.

Parameters:

  • extension_name (str) –

    Full extension name to unload.

Notes

This is called as a background task by unload_if_missing_config(). Errors during unload are logged but don't raise exceptions.

_create_error_info_embed async
Python
_create_error_info_embed(
    test_name: str, test_def: ErrorTestDefinition, ctx: Context[Tux]
) -> Embed

Create an informative embed showing error details and expected handler behavior.

Returns:

  • Embed

    The informational embed.

_send_test_summary async
Python
_send_test_summary(ctx: Context[Tux]) -> None

Send a summary of available error tests.

mock async
Python
mock(ctx: Context[Tux]) -> None

Command group for mocking various bot behaviors.

Requires System Administrator permissions (Level 8).

error_name_autocomplete async
Python
error_name_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]

Autocomplete function for error names based on the selected category.

Returns:

mock_error async
Python
mock_error(ctx: Context[Tux], category: str, error_name: str | None = None) -> None

Raise a specified error to test the global error handler.

This command shows detailed information about how the error will be handled, then raises the error to demonstrate the actual behavior.

Parameters:

  • ctx (Context[Tux]) –

    The command invocation context.

  • category (str) –

    The category of error to test (required for slash commands).

  • error_name (str, default: None ) –

    The specific error name to test. If not provided, shows available errors in the category.

Notes

This command intentionally raises various exceptions based on the input. These exceptions will propagate up to the global ErrorHandler cog. Requires System Administrator permissions (Level 8).

_send_category_summary async
Python
_send_category_summary(ctx: Context[Tux], category: str) -> None

Send a summary of available errors in a specific category.

_send_error_not_in_category async
Python
_send_error_not_in_category(ctx: Context[Tux], error_name: str, category: str) -> None

Send an error message when the error is not found in the specified category.

_send_error_not_found async
Python
_send_error_not_found(ctx: Context[Tux], error_name: str, category: str) -> None

Send an error message when the error is not found at all.

error_type_autocomplete async
Python
error_type_autocomplete(interaction: Interaction, current: str) -> list[Choice[str]]

Autocomplete function for error types with category information.

Returns:

  • list[Choice[str]]

    List of autocomplete choices with category prefix (max 25).

mock_test async
Python
mock_test(ctx: Context[Tux], *, error_type: str) -> None

Alternative error testing command with autocomplete support.

This provides the old interface for those who prefer typing error names directly.

Functions

setup async

Python
setup(bot: Tux) -> None

Cog setup for event handler.

Parameters:

  • bot (Tux) –

    The bot instance.