pub struct MockPlugin {
pub id: String,
pub metadata: PluginMetadata,
pub config: Option<PluginConfig>,
pub initialized: bool,
pub initialization_error: Option<String>,
pub validation_error: Option<String>,
pub cleanup_error: Option<String>,
pub call_counts: HashMap<String, usize>,
pub artificial_delays: HashMap<String, Duration>,
}Expand description
Mock plugin implementation for testing
MockPlugin provides a configurable test implementation of the Plugin trait that can be used for unit testing, integration testing, and validation scenarios.
§Features
- Configurable metadata and behavior
- Simulation of various plugin states and conditions
- Built-in test data generation
- Error injection capabilities
§Examples
ⓘ
use sklears_core::plugin::{MockPlugin, PluginCategory, PluginCapability};
use std::any::TypeId;
// Create a basic mock plugin
let mut mock = MockPlugin::new("test_plugin");
mock.metadata.category = PluginCategory::Algorithm;
mock.metadata.capabilities.push(PluginCapability::Parallel);
// Add supported types
mock.add_supported_type(TypeId::of::`<f64>`());
// Configure error behavior
mock.set_initialization_error(Some("Test error"));
// Use in tests
assert_eq!(mock.id(), "test_plugin");
assert!(mock.is_compatible(TypeId::of::`<f64>`()));Fields§
§id: StringPlugin identifier
metadata: PluginMetadataPlugin metadata
config: Option<PluginConfig>Configuration for the plugin
initialized: boolWhether plugin is initialized
initialization_error: Option<String>Simulated initialization error
validation_error: Option<String>Simulated validation error
cleanup_error: Option<String>Simulated cleanup error
call_counts: HashMap<String, usize>Call counters for testing
artificial_delays: HashMap<String, Duration>Artificial delays for performance testing
Implementations§
Source§impl MockPlugin
impl MockPlugin
Sourcepub fn for_category(id: &str, category: PluginCategory) -> Self
pub fn for_category(id: &str, category: PluginCategory) -> Self
Create a mock plugin for a specific algorithm category
§Arguments
id- The plugin identifiercategory- The plugin category
§Examples
ⓘ
use sklears_core::plugin::{MockPlugin, PluginCategory};
let transformer = MockPlugin::for_category("scaler", PluginCategory::Transformer);
assert_eq!(transformer.metadata.category, PluginCategory::Transformer);Sourcepub fn add_supported_type(&mut self, type_id: TypeId)
pub fn add_supported_type(&mut self, type_id: TypeId)
Sourcepub fn remove_supported_type(&mut self, type_id: TypeId)
pub fn remove_supported_type(&mut self, type_id: TypeId)
Sourcepub fn set_initialization_error(&mut self, error: Option<&str>)
pub fn set_initialization_error(&mut self, error: Option<&str>)
Set an initialization error to simulate failure
§Arguments
error- Optional error message (None to clear)
Sourcepub fn set_validation_error(&mut self, error: Option<&str>)
pub fn set_validation_error(&mut self, error: Option<&str>)
Set a validation error to simulate failure
§Arguments
error- Optional error message (None to clear)
Sourcepub fn set_cleanup_error(&mut self, error: Option<&str>)
pub fn set_cleanup_error(&mut self, error: Option<&str>)
Sourcepub fn add_artificial_delay(&mut self, method: &str, delay: Duration)
pub fn add_artificial_delay(&mut self, method: &str, delay: Duration)
Add an artificial delay for a specific method
§Arguments
method- The method namedelay- The delay duration
Sourcepub fn get_call_count(&self, method: &str) -> usize
pub fn get_call_count(&self, method: &str) -> usize
Sourcepub fn reset_call_counts(&mut self)
pub fn reset_call_counts(&mut self)
Reset all call counts
Trait Implementations§
Source§impl Clone for MockPlugin
impl Clone for MockPlugin
Source§fn clone(&self) -> MockPlugin
fn clone(&self) -> MockPlugin
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MockPlugin
impl Debug for MockPlugin
Source§impl Plugin for MockPlugin
impl Plugin for MockPlugin
Source§fn metadata(&self) -> PluginMetadata
fn metadata(&self) -> PluginMetadata
Plugin metadata Read more
Source§fn initialize(&mut self, config: &PluginConfig) -> Result<()>
fn initialize(&mut self, config: &PluginConfig) -> Result<()>
Initialize the plugin with configuration Read more
Source§fn is_compatible(&self, input_type: TypeId) -> bool
fn is_compatible(&self, input_type: TypeId) -> bool
Check if the plugin is compatible with the given input type Read more
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Get the plugin as mutable Any for downcasting Read more
Source§fn validate_config(&self, _config: &PluginConfig) -> Result<()>
fn validate_config(&self, _config: &PluginConfig) -> Result<()>
Validate plugin configuration Read more
Auto Trait Implementations§
impl Freeze for MockPlugin
impl RefUnwindSafe for MockPlugin
impl Send for MockPlugin
impl Sync for MockPlugin
impl Unpin for MockPlugin
impl UnwindSafe for MockPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more