nat.tool.code_execution.test_code_execution_sandbox#
Test suite for Code Execution Sandbox using pytest.
This module provides comprehensive testing for the code execution sandbox service, replacing the original bash script with a more maintainable Python implementation.
Classes#
Test suite for the Code Execution Sandbox service. |
Functions#
|
Add custom command-line options for pytest. |
|
Setup environment variables from command-line options. |
Module Contents#
- class TestCodeExecutionSandbox#
Test suite for the Code Execution Sandbox service.
- sandbox_config()#
Configuration for sandbox testing.
- check_sandbox_running(sandbox_config)#
Check if sandbox server is running before running tests.
- execute_code( ) dict[str, Any] #
Execute code in the sandbox and return the response.
- Args:
sandbox_config: Configuration dictionary code: Code to execute language: Programming language (default: python)
- Returns:
dictionary containing the response from the sandbox
- test_simple_print(sandbox_config)#
Test simple print statement execution.
- test_basic_arithmetic(sandbox_config)#
Test basic arithmetic operations.
- test_numpy_operations(sandbox_config)#
Test numpy dependency availability and operations.
- test_pandas_operations(sandbox_config)#
Test pandas dependency availability and operations.
- test_plotly_import(sandbox_config)#
Test plotly dependency availability.
- test_syntax_error_handling(sandbox_config)#
Test handling of syntax errors.
- test_runtime_error_handling(sandbox_config)#
Test handling of runtime errors.
- test_import_error_handling(sandbox_config)#
Test handling of import errors.
- test_mixed_output(sandbox_config)#
Test code that produces both stdout and stderr output.
- test_long_running_code(sandbox_config)#
Test code that takes some time to execute but completes within timeout.
- test_file_operations(sandbox_config)#
Test basic file operations in the sandbox.
- test_file_persistence_create(sandbox_config)#
Test file persistence - create various file types.
- test_file_persistence_read(sandbox_config)#
Test file persistence - read back created files.
- test_json_operations(sandbox_config)#
Test JSON file operations for persistence.
- test_missing_generated_code_field(sandbox_config)#
Test request missing the generated_code field.
- test_missing_timeout_field(sandbox_config)#
Test request missing the timeout field.
- test_invalid_json(sandbox_config)#
Test request with invalid JSON.
- test_non_json_request(sandbox_config)#
Test request with non-JSON content.
- test_timeout_too_low(sandbox_config)#
Test request with timeout too low.
- pytest_addoption(parser)#
Add custom command-line options for pytest.
- setup_environment(request)#
Setup environment variables from command-line options.