MockPlugin

Struct MockPlugin 

Source
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: String

Plugin identifier

§metadata: PluginMetadata

Plugin metadata

§config: Option<PluginConfig>

Configuration for the plugin

§initialized: bool

Whether 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

Source

pub fn new(id: &str) -> Self

Create a new mock plugin with default settings

§Arguments
  • id - The plugin identifier
§Examples
use sklears_core::plugin::MockPlugin;

let mock = MockPlugin::new("test_algorithm");
assert_eq!(mock.id(), "test_algorithm");
Source

pub fn for_category(id: &str, category: PluginCategory) -> Self

Create a mock plugin for a specific algorithm category

§Arguments
  • id - The plugin identifier
  • category - 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);
Source

pub fn add_supported_type(&mut self, type_id: TypeId)

Add a supported type to the plugin

§Arguments
  • type_id - The TypeId to add as supported
Source

pub fn remove_supported_type(&mut self, type_id: TypeId)

Remove a supported type from the plugin

§Arguments
  • type_id - The TypeId to remove
Source

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)
Source

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)
Source

pub fn set_cleanup_error(&mut self, error: Option<&str>)

Set a cleanup error to simulate failure

§Arguments
  • error - Optional error message (None to clear)
Source

pub fn add_artificial_delay(&mut self, method: &str, delay: Duration)

Add an artificial delay for a specific method

§Arguments
  • method - The method name
  • delay - The delay duration
Source

pub fn get_call_count(&self, method: &str) -> usize

Get the call count for a specific method

§Arguments
  • method - The method name
§Returns

The number of times the method was called

Source

pub fn reset_call_counts(&mut self)

Reset all call counts

Trait Implementations§

Source§

impl Clone for MockPlugin

Source§

fn clone(&self) -> MockPlugin

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockPlugin

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Plugin for MockPlugin

Source§

fn id(&self) -> &str

Unique identifier for the plugin Read more
Source§

fn metadata(&self) -> PluginMetadata

Plugin metadata Read more
Source§

fn initialize(&mut self, config: &PluginConfig) -> Result<()>

Initialize the plugin with configuration Read more
Source§

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(&self) -> &dyn Any

Get the plugin as Any for downcasting Read more
Source§

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<()>

Validate plugin configuration Read more
Source§

fn cleanup(&mut self) -> Result<()>

Cleanup resources when plugin is unloaded Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V