Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_register(self):
class TestClass():
intValue = 0
def getIntValue(self):
return self.intValue
from sciunit.validators import register_quantity, register_type
from cerberus import TypeDefinition, Validator
register_type(TestClass, "TestType1")
q = pq.Quantity([1, 2, 3], 'J')
register_quantity(q, "TestType2")
self.assertIsInstance(Validator.types_mapping['TestType1'], TypeDefinition)
self.assertIsInstance(Validator.types_mapping['TestType2'], TypeDefinition)
def test_register(self):
class TestClass():
intValue = 0
def getIntValue(self):
return self.intValue
from sciunit.validators import register_quantity, register_type
from cerberus import TypeDefinition, Validator
register_type(TestClass, "TestType1")
q = pq.Quantity([1, 2, 3], 'J')
register_quantity(q, "TestType2")
self.assertIsInstance(Validator.types_mapping['TestType1'], TypeDefinition)
self.assertIsInstance(Validator.types_mapping['TestType2'], TypeDefinition)
def register_type(cls, name):
"""Register `name` as a type to validate as an instance of class `cls`."""
x = TypeDefinition(name, (cls,), ())
Validator.types_mapping[name] = x
# -*- coding: utf-8 -*-
from openelevationservice.server.api import api_exceptions
from openelevationservice.server.utils import logger
from cerberus import Validator, TypeDefinition
log = logger.get_logger(__name__)
object_type = TypeDefinition("object", (object,), ())
Validator.types_mapping['object'] = object_type
v = Validator()
schema_post = {'geometry': {'anyof_type': ['object', 'list', 'string'], 'required': True},
'format_in': {'type': 'string', 'allowed': ['geojson', 'point', 'encodedpolyline', 'encodedpolyline5', 'encodedpolyline6', 'polyline'], 'required': True},
'format_out': {'type': 'string', 'allowed': ['geojson', 'point', 'encodedpolyline', 'encodedpolyline5', 'encodedpolyline6', 'polyline'], 'default': 'geojson'},
'dataset': {'type': 'string', 'allowed': ['srtm'], 'default': 'srtm'}
}
schema_get = {'geometry': {'type': 'string', 'required': True},
'format_out': {'type': 'string', 'allowed': ['geojson', 'point'], 'default': 'geojson'},
'dataset': {'type': 'string', 'allowed': ['srtm'], 'default': 'srtm'}
}
def validate_request(request):
"""
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Validates the used parameter with Cerberus."""
from cerberus import Validator, TypeDefinition
from openrouteservice import exceptions
# Add the tuple type
tuple_type = TypeDefinition("tuple", (tuple), ())
Validator.types_mapping['tuple'] = tuple_type
v = Validator()
def validator(args, function):
"""
Validates arguments against function specific schemas
:param args: Arguments to validate
:type args: dict
:param function: calling function
:type function: string
:raises: ValidationError
"""
def register_quantity(quantity, name):
"""Register `name` as a type to validate as an instance of class `cls`."""
x = TypeDefinition(name, (quantity.__class__,), ())
Validator.types_mapping[name] = x