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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
547722e883beb84a1b9040374add9d85c1851982affdb6be90416f268b7e1771
|
|
| MD5 |
4ea116c0d2d9e5eab40411fb9090de94
|
|
| BLAKE2b-256 |
e75a89c336c92ee8a71a7611ed705e293559518d41db34595ada1ee81cab78b6
|
Provenance
The following attestation bundles were made for mayhemmonkey-2025.2.20.post1.tar.gz:
Publisher:
python-publish.yml on NormanTUD/MayhemMonkey
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mayhemmonkey-2025.2.20.post1.tar.gz -
Subject digest:
547722e883beb84a1b9040374add9d85c1851982affdb6be90416f268b7e1771 - Sigstore transparency entry: 172827770
- Sigstore integration time:
-
Permalink:
NormanTUD/MayhemMonkey@f3467b9e6bdcc157fa623856570a42da7e887b90 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/NormanTUD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f3467b9e6bdcc157fa623856570a42da7e887b90 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mayhemmonkey-2025.2.20.post1-py3-none-any.whl.
File metadata
- Download URL: mayhemmonkey-2025.2.20.post1-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86a4a9b82964ea75ee03b5056d7f623620bb37c9fedbed2d083866bda49c35b7
|
|
| MD5 |
dd320634ef6dd5d36aac140537b16c26
|
|
| BLAKE2b-256 |
4aa3a975dd0334ebc7b7a8705c5371240840a9b9f25a9cb55abdbebacd95b44d
|
Provenance
The following attestation bundles were made for mayhemmonkey-2025.2.20.post1-py3-none-any.whl:
Publisher:
python-publish.yml on NormanTUD/MayhemMonkey
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mayhemmonkey-2025.2.20.post1-py3-none-any.whl -
Subject digest:
86a4a9b82964ea75ee03b5056d7f623620bb37c9fedbed2d083866bda49c35b7 - Sigstore transparency entry: 172827771
- Sigstore integration time:
-
Permalink:
NormanTUD/MayhemMonkey@f3467b9e6bdcc157fa623856570a42da7e887b90 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/NormanTUD
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f3467b9e6bdcc157fa623856570a42da7e887b90 -
Trigger Event:
release
-
Statement type: