flowchart TD
Start([pytest runs plugin_test.py]) --> Setup["Setup:
FakeLogger, monkeypatch,
mock dependencies"]
Setup --> UtilTests["Utility Functions Tests"]
Setup --> SettingsTests["Settings Tests"]
Setup --> LoggingTests["Logging Tests"]
Setup --> UptimeTests["Uptime Retrieval Tests"]
Setup --> APITests["API Tests"]
Setup --> HookTests["Hook Tests"]
Setup --> ReloadTests["Reload Tests"]
UtilTests --> Format["test_format_uptime_*
- Format variants
- DHM/DH/D formats"]
Format --> FormatOK{All variants
pass?}
SettingsTests --> ValidateSave["test_validate_and_sanitize_*
test_log_settings_save_*
- Validation logic
- Data structure checks
- Defaults handling"]
ValidateSave --> SettingsOK{Settings
valid?}
LoggingTests --> DebugThrottle["test_log_debug_throttle
test_log_debug_*
- Throttling behavior
- Exception handling
- Multiple calls"]
DebugThrottle --> LogOK{Logging
works?}
UptimeTests --> GetUptime["test_get_uptime_*
- /proc/uptime parsing
- psutil fallback
- Error handling
- Boot time handling"]
GetUptime --> UptimeOK{Uptime
retrieved?}
APITests --> OnAPI["test_on_api_get*
test_fallback_uptime_*
- Flask integration
- Permission checks
- JSON responses
- Error responses"]
OnAPI --> APIOK{API
works?}
HookTests --> SafeInvoke["test_hook_inspection_*
test_on_settings_*
- Hook detection
- Safe invocation
- Parameter validation"]
SafeInvoke --> HookOK{Hooks
safe?}
ReloadTests --> PluginReload["test_reload_*
- Module reloading
- Dependency checking
- Fallback handling"]
PluginReload --> ReloadOK{Reload
works?}
FormatOK -->|PASS| TestPass["All tests pass"]
SettingsOK -->|PASS| TestPass
LogOK -->|PASS| TestPass
UptimeOK -->|PASS| TestPass
APIOK -->|PASS| TestPass
HookOK -->|PASS| TestPass
ReloadOK -->|PASS| TestPass
FormatOK -->|FAIL| TestFail["Test fails"]
SettingsOK -->|FAIL| TestFail
LogOK -->|FAIL| TestFail
UptimeOK -->|FAIL| TestFail
APIOK -->|FAIL| TestFail
HookOK -->|FAIL| TestFail
ReloadOK -->|FAIL| TestFail
TestPass --> Coverage["Generate Coverage Report
--cov=octoprint_uptime"]
TestFail --> FailReport["Report Failures"]
Coverage --> Success([Coverage Report Generated])
FailReport --> Fail([Tests Failed])
classDef category fill:#3b82f6,stroke:#1e40af,color:#fff
classDef process fill:#ecfeff,stroke:#06b6d4
classDef check fill:#fef3c7,stroke:#f59e0b
classDef success fill:#d1fae5,stroke:#10b981,color:#000
classDef error fill:#fee2e2,stroke:#ef4444,color:#000
class UtilTests,SettingsTests,LoggingTests,UptimeTests,APITests,HookTests,ReloadTests category
class Format,ValidateSave,DebugThrottle,GetUptime,OnAPI,SafeInvoke,PluginReload process
class FormatOK,SettingsOK,LogOK,UptimeOK,APIOK,HookOK,ReloadOK check
class TestPass,Success success
class TestFail,Fail,FailReport error
| Category | Test Functions | Focus Areas |
|---|---|---|
| Utility Functions | test_format_uptime_* | Uptime formatting with various time units |
| Settings |
test_validate_and_sanitize_*
test_log_settings_* |
Settings validation, defaults, sanitization |
| Logging | test_log_debug_* | Debug throttling, error logging, exceptions |
| Uptime Retrieval | test_get_uptime_* | /proc/uptime, psutil, boot time, error cases |
| API |
test_on_api_get*
test_fallback_uptime_* |
Flask integration, permissions, JSON responses |
| Hooks |
test_hook_inspection_*
test_on_settings_* |
Hook detection, safe invocation, OctoPrint integration |
| Plugin Reload | test_reload_* | Module reloading, dependency handling, fallbacks |
pytest # Run with coverage report pytest --cov=octoprint_uptime --cov-report=html # Run specific test category pytest tests/plugin_test.py::test_format_uptime_variants