Decorators
provide.testkit.quality.decorators
¶
Quality decorators for easy integration of quality checks.
Classes¶
Functions¶
complexity_gate
¶
complexity_gate(
max_complexity: int | None = None,
min_grade: str | None = None,
min_score: float | None = None,
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
) -> Callable[[F], F]
Decorator to enforce complexity requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_complexity
|
int | None
|
Maximum complexity allowed |
None
|
min_grade
|
str | None
|
Minimum complexity grade required |
None
|
min_score
|
float | None
|
Minimum complexity score required |
None
|
path
|
Path | str | None
|
Path to analyze |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@complexity_gate(max_complexity=10, min_grade="B") def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
coverage_gate
¶
coverage_gate(
min_coverage: float,
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
) -> Callable[[F], F]
Decorator to enforce minimum coverage requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_coverage
|
float
|
Minimum coverage percentage required |
required |
path
|
Path | str | None
|
Path to analyze |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@coverage_gate(80.0) def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
documentation_gate
¶
documentation_gate(
min_coverage: float | None = None,
min_grade: str | None = None,
min_score: float | None = None,
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
) -> Callable[[F], F]
Decorator to enforce documentation requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_coverage
|
float | None
|
Minimum documentation coverage percentage |
None
|
min_grade
|
str | None
|
Minimum documentation grade required |
None
|
min_score
|
float | None
|
Minimum documentation score required |
None
|
path
|
Path | str | None
|
Path to analyze |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@documentation_gate(min_coverage=80.0, min_grade="B") def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
performance_gate
¶
performance_gate(
max_memory_mb: float | None = None,
max_execution_time: float | None = None,
min_score: float | None = None,
) -> Callable[[F], F]
Decorator to enforce performance requirements on function execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_memory_mb
|
float | None
|
Maximum memory usage in MB |
None
|
max_execution_time
|
float | None
|
Maximum execution time in seconds |
None
|
min_score
|
float | None
|
Minimum performance score |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@performance_gate(max_memory_mb=50.0, max_execution_time=1.0) def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
quality_check
¶
quality_check(
coverage: float | bool | None = None,
security: float | bool | None = None,
complexity: dict[str, Any] | bool | None = None,
documentation: dict[str, Any] | bool | None = None,
performance: dict[str, Any] | None = None,
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
fail_fast: bool = True,
) -> Callable[[F], F]
Comprehensive quality check decorator with multiple dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coverage
|
float | bool | None
|
Coverage requirements (percentage or boolean) |
None
|
security
|
float | bool | None
|
Security requirements (score or boolean) |
None
|
complexity
|
dict[str, Any] | bool | None
|
Complexity requirements (config dict or boolean) |
None
|
documentation
|
dict[str, Any] | bool | None
|
Documentation requirements (config dict or boolean) |
None
|
performance
|
dict[str, Any] | None
|
Performance requirements (config dict) |
None
|
path
|
Path | str | None
|
Path to analyze |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
fail_fast
|
bool
|
Whether to stop on first failure |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@quality_check( coverage=80.0, security=True, complexity={"max_complexity": 10, "min_grade": "B"}, documentation={"min_coverage": 80.0}, performance={"max_memory_mb": 50.0} ) def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
quality_gate
¶
quality_gate(
gates: dict[str, Any],
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
fail_fast: bool = True,
) -> Callable[[F], F]
Decorator to apply quality gates to a function or test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gates
|
dict[str, Any]
|
Quality gate requirements |
required |
path
|
Path | str | None
|
Path to analyze (defaults to function's module file) |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
fail_fast
|
bool
|
Whether to stop on first failure |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@quality_gate({"coverage": 80.0, "security": True}) def test_my_function(): # Test implementation pass
Source code in provide/testkit/quality/decorators.py
security_gate
¶
security_gate(
min_score: float = 90.0,
path: Path | str | None = None,
artifact_dir: Path | str | None = None,
) -> Callable[[F], F]
Decorator to enforce security scanning requirements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_score
|
float
|
Minimum security score required |
90.0
|
path
|
Path | str | None
|
Path to analyze |
None
|
artifact_dir
|
Path | str | None
|
Directory for artifacts |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function |
Example
@security_gate(95.0) def test_my_function(): # Test implementation pass