import pytest
from ri import (
RiAppBuilder,
RiAppRuntime,
RiConfig,
RiConfigManager,
RiLogger,
RiLogConfig,
RiLogLevel,
RiFileSystem,
RiError,
RiServiceContext,
RiHookBus,
RiHookEvent,
RiHookKind,
RiModulePhase,
RiHealthStatus,
RiHealthCheckResult,
RiHealthCheckConfig,
RiHealthReport,
RiHealthChecker,
RiLifecycleObserver,
)
class TestRiAppBuilder:
def test_app_builder_creation(self):
builder = RiAppBuilder()
assert builder is not None
def test_app_builder_with_config(self):
builder = RiAppBuilder()
builder.with_config("config.yaml")
assert builder is not None
def test_app_builder_with_logging(self):
builder = RiAppBuilder()
log_config = RiLogConfig()
builder.with_logging(log_config)
assert builder is not None
def test_app_builder_chain(self):
builder = RiAppBuilder()
result = builder.with_config("config.yaml").with_logging(RiLogConfig())
assert result is builder
class TestRiConfig:
def test_config_creation(self):
config = RiConfig()
assert config is not None
def test_config_with_values(self):
config = RiConfig()
config.set("database.host", "localhost")
config.set("database.port", "5432")
assert config.get("database.host") == "localhost"
assert config.get("database.port") == "5432"
class TestRiConfigManager:
def test_config_manager_creation(self):
manager = RiConfigManager()
assert manager is not None
def test_config_manager_add_source(self):
manager = RiConfigManager()
manager.add_file_source("config.yaml")
assert manager is not None
class TestRiLogger:
def test_logger_creation(self):
fs = RiFileSystem(".")
log_config = RiLogConfig()
logger = RiLogger(log_config, fs)
assert logger is not None
def test_logger_levels(self):
fs = RiFileSystem(".")
log_config = RiLogConfig()
logger = RiLogger(log_config, fs)
assert logger is not None
class TestRiFileSystem:
def test_file_system_creation(self):
fs = RiFileSystem(".")
assert fs is not None
def test_file_operations(self):
fs = RiFileSystem(".")
exists = fs.exists("pyproject.toml")
assert isinstance(exists, bool)
class TestRiError:
def test_error_creation(self):
error = RiError.from_str("Test error message")
assert str(error) == "Test error message"
def test_io_error(self):
error = RiError.io("IO operation failed")
assert error.is_io()
def test_serde_error(self):
error = RiError.serde("Serialization failed")
assert error.is_serde()
class TestRiHookBus:
def test_hook_bus_creation(self):
hook_bus = RiHookBus()
assert hook_bus is not None
class TestRiHookEvent:
def test_hook_event_module_phase(self):
phases = [
RiModulePhase.Init,
RiModulePhase.BeforeStart,
RiModulePhase.Start,
RiModulePhase.AfterStart,
RiModulePhase.BeforeShutdown,
RiModulePhase.Shutdown,
RiModulePhase.AfterShutdown,
]
assert len(phases) == 7
class TestRiHealthCheck:
def test_health_check_config(self):
config = RiHealthCheckConfig(
check_interval=30,
timeout=5,
failure_threshold=3,
success_threshold=2,
enabled=True
)
assert config.check_interval == 30
assert config.timeout == 5
def test_health_check_result(self):
result = RiHealthCheckResult(
name="test_check",
status=RiHealthStatus.Healthy,
message="Service is healthy"
)
assert result.name == "test_check"
assert "healthy" in str(result.status).lower()
def test_health_report(self):
report = RiHealthReport()
assert hasattr(report, 'overall_status')
class TestRiLifecycleObserver:
def test_lifecycle_observer_creation(self):
observer = RiLifecycleObserver()
assert observer is not None
class TestRiServiceContext:
def test_service_context_creation(self):
context = RiServiceContext()
assert context is not None
def test_service_context_with_logger(self):
context = RiServiceContext()
assert hasattr(context, 'logger')
class TestRiAppBuilderWrapper:
def test_method_chaining_returns_same_instance(self):
builder = RiAppBuilder()
result = builder.with_config("config.yaml")
assert result is builder, "with_config should return the same instance"
def test_multiple_chained_calls(self):
builder = RiAppBuilder()
result = (builder
.with_config("config.yaml")
.with_logging(RiLogConfig()))
assert result is builder, "Chained calls should return the same instance"
def test_wrapper_has_internal_builder(self):
builder = RiAppBuilder()
assert hasattr(builder, '_builder'), "Wrapper should have _builder attribute"
assert builder._builder is not None, "Internal _builder should not be None"
def test_build_returns_runtime_wrapper(self):
builder = RiAppBuilder()
try:
runtime = builder.build()
assert isinstance(runtime, RiAppRuntime), "build() should return RiAppRuntime"
except Exception:
pass
class TestRiAppRuntimeWrapper:
def test_runtime_wrapper_creation(self):
builder = RiAppBuilder()
try:
runtime = builder.build()
assert runtime is not None, "Runtime should be created"
except Exception:
pass
def test_runtime_has_internal_instance(self):
builder = RiAppBuilder()
try:
runtime = builder.build()
assert hasattr(runtime, '_runtime'), "Wrapper should have _runtime attribute"
assert runtime._runtime is not None, "Internal _runtime should not be None"
except Exception:
pass
def test_get_context_method_exists(self):
builder = RiAppBuilder()
try:
runtime = builder.build()
assert hasattr(runtime, 'get_context'), "Runtime should have get_context method"
assert callable(runtime.get_context), "get_context should be callable"
except Exception:
pass
def test_run_method_exists(self):
builder = RiAppBuilder()
try:
runtime = builder.build()
assert hasattr(runtime, 'run'), "Runtime should have run method"
assert callable(runtime.run), "run should be callable"
except Exception:
pass
if __name__ == "__main__":
pytest.main([__file__, "-v"])