Skip to main content

A tool for testing what happens if base functions of python except

Project description

MayhemMonkey

MayhemMonkey is a testing tool designed to simulate how your program might react to unexpected errors that can occur when executing basic built-in functions in Python. It helps ensure that your code is robust enough to handle a variety of errors gracefully.

Goal

The main goal of MayhemMonkey is to simulate errors in basic built-in functions to test how your program responds to unexpected failures. With mayhemmonkey, you can introduce different types of errors in critical Python functions like open, print, eval, etc., and ensure your application remains stable under these conditions.

Installation

Install MayhemMonkey easily using pip:

pip3 install mayhemmonkey

Usage

Here is a simple example of how to use MayhemMonkey in a Python project:

from mayhemmonkey import MayhemMonkey

mayhemmonkey = MayhemMonkey()

print(mayhemmonkey.get_function_categories())
print(mayhemmonkey.get_function_categories_as_list())

mayhemmonkey.set_function_error_rate("open", 0.5)
mayhemmonkey.set_function_group_error_rate("io", 0.3)
mayhemmonkey.set_global_error_rate(0.2)

with open("test.txt", "w") as f:  # 50% Chance that it'll fail
    f.write("Hello world!")

print("This should be printed.")  # 30% it'll fail because it's in the group "io"

Error Configuration

MayhemMonkey allows you to configure the error probability for various functions, function groups, or globally. The error probability is given as a decimal number between 0 and 1, where 0 means no errors and 1 guarantees an error.

Configuring Error Probabilities

Function/Group Description Error Probability Example
Individual Functions Set error probability for a specific function. Float 0 to 1 mayhemmonkey.set_function_error_rate("open", 0.5)
Function Groups Set error probability for a group of functions. Float 0 to 1 mayhemmonkey.set_function_group_error_rate("io", 0.3)
Global Set global error probability for all functions. Float 0 to 1 mayhemmonkey.set_global_error_rate(0.2)

Function Groups and Their Functions

Error Group Functions
io open, input, print
math abs, divmod, max, min, pow, round
conversion ascii, bin, chr, hex, oct, ord, repr
iteration aiter, anext, iter, next
evaluation eval, exec, compile

Error Types for Functions

MayhemMonkey can generate specific types of errors for each function. Here’s a list of the possible errors and their meanings:

Function Error Type Description
open FileNotFoundError File not found
PermissionError No permission for the file
OSError Too many open files
input EOFError End of file reached
KeyboardInterrupt Input was interrupted
print OSError Error during printing
eval SyntaxError Invalid syntax
TypeError Invalid expression
RuntimeError Unexpected runtime error
exec SyntaxError Invalid syntax
RuntimeError Unexpected runtime error
compile SyntaxError Error during compilation
max ValueError Empty sequence
TypeError Incompatible types for comparison
min ValueError Empty sequence
TypeError Incompatible types for comparison
divmod ZeroDivisionError Division by zero
TypeError Invalid operand
pow ZeroDivisionError 0.0 cannot be raised to a negative exponent
TypeError Invalid operand
round TypeError Second argument must be an integer

Frequently Asked Questions

How can I use MayhemMonkey in my application?

MayhemMonkey is easy to use to simulate errors in basic Python functions. You can install mayhemmonkey in your project and then configure error probabilities for specific functions, function groups, or globally. This helps ensure that your application is robust enough to handle different error conditions.

What happens if an error occurs?

When an error occurs due to the configured error probability, an exception will be raised that you can handle with a try-except block. You can ensure that your application is prepared for these errors by adding appropriate error handling.

Contributing

If you want to contribute to the development of MayhemMonkey, you can open a pull request or file an issue on GitHub.

Caveats

Load this as last module, as currently, all imports will fail when this module is loaded.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mayhemmonkey-2025.2.20.post1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mayhemmonkey-2025.2.20.post1-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file mayhemmonkey-2025.2.20.post1.tar.gz.

File metadata

  • Download URL: mayhemmonkey-2025.2.20.post1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mayhemmonkey-2025.2.20.post1.tar.gz
Algorithm Hash digest
SHA256 547722e883beb84a1b9040374add9d85c1851982affdb6be90416f268b7e1771
MD5 4ea116c0d2d9e5eab40411fb9090de94
BLAKE2b-256 e75a89c336c92ee8a71a7611ed705e293559518d41db34595ada1ee81cab78b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mayhemmonkey-2025.2.20.post1.tar.gz:

Publisher: python-publish.yml on NormanTUD/MayhemMonkey

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mayhemmonkey-2025.2.20.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for mayhemmonkey-2025.2.20.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 86a4a9b82964ea75ee03b5056d7f623620bb37c9fedbed2d083866bda49c35b7
MD5 dd320634ef6dd5d36aac140537b16c26
BLAKE2b-256 4aa3a975dd0334ebc7b7a8705c5371240840a9b9f25a9cb55abdbebacd95b44d

See more details on using hashes here.

Provenance

The following attestation bundles were made for mayhemmonkey-2025.2.20.post1-py3-none-any.whl:

Publisher: python-publish.yml on NormanTUD/MayhemMonkey

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page