Strategies
provide.testkit.chaos.strategies
¶
Core Hypothesis strategies for chaos testing.
Provides foundational strategies for generating chaotic test inputs that explore edge cases, boundary conditions, and failure scenarios.
Functions¶
chaos_timings
¶
chaos_timings(
draw: DrawFn,
min_value: float = 0.001,
max_value: float = 10.0,
allow_zero: bool = False,
) -> float
Generate chaotic timing values for unpredictable delays.
Useful for testing timeout handling, race conditions, and time-sensitive code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_value
|
float
|
Minimum timing value in seconds |
0.001
|
max_value
|
float
|
Maximum timing value in seconds |
10.0
|
allow_zero
|
bool
|
Whether to allow zero delay |
False
|
Returns:
| Type | Description |
|---|---|
float
|
A floating-point timing value in seconds |
Source code in provide/testkit/chaos/strategies.py
edge_values
¶
Generate boundary and edge-case values for a given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
value_type
|
type
|
Type to generate edge values for |
int
|
Returns:
| Type | Description |
|---|---|
Any
|
Edge-case value of the specified type |
Example
Source code in provide/testkit/chaos/strategies.py
failure_patterns
¶
failure_patterns(
draw: DrawFn,
max_failures: int = 10,
exception_types: (
tuple[type[Exception], ...] | None
) = None,
) -> list[tuple[int, type[Exception]]]
Generate patterns of when and how failures should occur.
Returns a list of (iteration_number, exception_type) tuples for failure injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
max_failures
|
int
|
Maximum number of failures to generate |
10
|
exception_types
|
tuple[type[Exception], ...] | None
|
Specific exception types to use (defaults to common types) |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, type[Exception]]]
|
List of (when_to_fail, exception_class) tuples |
Example
Source code in provide/testkit/chaos/strategies.py
malformed_inputs
¶
malformed_inputs(
draw: DrawFn,
include_huge: bool = True,
include_empty: bool = True,
include_special: bool = True,
) -> Any
Generate edge-case inputs for robust testing.
Creates various malformed, extreme, or unusual inputs that often expose bugs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
include_huge
|
bool
|
Include very large strings/data |
True
|
include_empty
|
bool
|
Include empty/None values |
True
|
include_special
|
bool
|
Include special numeric values (NaN, inf) |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
Various malformed input values |
Example
Source code in provide/testkit/chaos/strategies.py
resource_limits
¶
resource_limits(
draw: DrawFn,
min_memory: int = 1024,
max_memory: int = 1024 * 1024 * 100,
min_timeout: float = 0.01,
max_timeout: float = 60.0,
) -> dict[str, Any]
Generate resource constraint scenarios.
Creates various resource limit configurations for testing behavior under constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
min_memory
|
int
|
Minimum memory limit in bytes |
1024
|
max_memory
|
int
|
Maximum memory limit in bytes |
1024 * 1024 * 100
|
min_timeout
|
float
|
Minimum timeout in seconds |
0.01
|
max_timeout
|
float
|
Maximum timeout in seconds |
60.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with resource limit configuration |
Example
Source code in provide/testkit/chaos/strategies.py
unicode_chaos
¶
unicode_chaos(
draw: DrawFn,
include_emoji: bool = True,
include_rtl: bool = True,
include_zero_width: bool = True,
include_surrogates: bool = False,
) -> str
Generate problematic Unicode strings for testing.
Creates strings with emoji, RTL text, zero-width characters, and other Unicode edge cases that often cause issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
draw
|
DrawFn
|
Hypothesis draw function |
required |
include_emoji
|
bool
|
Include emoji characters |
True
|
include_rtl
|
bool
|
Include right-to-left text |
True
|
include_zero_width
|
bool
|
Include zero-width characters |
True
|
include_surrogates
|
bool
|
Include surrogate pairs (can be problematic) |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A Unicode string with chaotic properties |