Test Code Functionality

Functions to test code snippets using the library:

create_test_script


def create_test_script(
    code:str, # The Python code snippet to wrap in a test script
    config:Optional=None, # Optional configuration
)->str: # A complete Python script with imports and the provided code

Create a test script with necessary imports and the provided code.


execute_test_code


def execute_test_code(
    code:str, # The code to test
    show_imports:bool=False, # Whether to show the generated imports
    timeout:int=10, # Timeout in seconds
)->Tuple: # (success, stdout, stderr)

Execute test code in a safe environment.

Export