Schema
KoshSchema
Bases: object
Source code in kosh/schema.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
__init__(required={}, optional={})
Schema for Kosh objects
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required
|
dict
|
Dictionary of required keys and their validation function(s). |
{}
|
optional
|
dict
Validation functions must be pickable.
If multiple validation functions are provided (in a list),
then the attribute is valid if ANY function return True.
Validation function must return True, False | raise an Exception.
|
Dictionary of optional keys and their validation function(s) |
{}
|
Source code in kosh/schema.py
__str__()
validate(obj, level=None)
validate an object through a schema Checks that the obj has all the required attribute and that both required and present optional attributes pass validation functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
str
|
object to validate |
required |
level
|
str
|
Dataset or Ensemble level, used for |
None
|
Returns:
| Type | Description |
|---|---|
|
True if validates "rtype: bool |
Raises:
| Type | Description |
|---|---|
ValueError
|
obj does not validate through the schema |
Source code in kosh/schema.py
validate_attribute(attribute, value)
validate_attribute validates a value for a specific attribute
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attribute
|
str
|
attribute to validate |
required |
value
|
any
|
value to validate |
required |
Returns:
| Type | Description |
|---|---|
|
True or False "rtype: bool |
Source code in kosh/schema.py
auto_valid(validation)
auto_valid converts class type to their 'isinstance' function in the future other keyword maybe added to the list
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validation
|
type
|
class def or type |
required |
Returns:
| Type | Description |
|---|---|
function
|
isinstance lambda function or validation function |
Source code in kosh/schema.py
validate_value(value, validation)
validate_value Validates a value for a given validation function (or list of)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
any
|
value to validate |
required |
validation
|
callable
|
validation function (or list of) |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if validates |
Raises:
| Type | Description |
|---|---|
ValueError
|
value does not vaidate |