brails.utils.inventory_validator module
This module provides a utility class for validating AssetInventory objects.
A utility class for validating AssetInventory objects. |
- class brails.utils.inventory_validator.InventoryValidator
Bases:
object
A utility class for validating AssetInventory objects.
This class provides static methods for checking whether a given object is a valid instance of AssetInventory, and for enforcing that validation with clear error reporting.
The
InventoryValidator
class can be imported using:from brails.utils import InventoryValidator
- static is_inventory(inventory)
Check if the given object is an instance of AssetInventory.
- Parameters:
inventory (Any) – The object to check.
- Returns:
True
if the object is an instance ofAssetInventory
,False
otherwise.- Return type:
bool
Examples
>>> from brails.types.asset_inventory import AssetInventory >>> from brails.utils import InventoryValidator >>> inv = AssetInventory() >>> InventoryValidator.is_inventory(inv) True
>>> InventoryValidator.is_inventory("not an inventory") False
- static validate_inventory(inventory)
Validate that the input is an instance of AssetInventory.
- Parameters:
inventory (Any) – The object to validate.
- Raises:
TypeError – If the input is not an instance of
AssetInventory
.
Examples
>>> from brails.types.asset_inventory import AssetInventory >>> from brails.utils import InventoryValidator >>> inv = AssetInventory() >>> InventoryValidator.validate_inventory(inv)
Invalid input raises an error:
>>> InventoryValidator.validate_inventory("wrong type") TypeError: Expected an instance of AssetInventory for inventory input.