How to use cast_value method in localstack

Best Python code snippet using localstack_python

types.py

Source:types.py Github

copy

Full Screen

1from .parameter import Parameter2from ..errors import ParameterError3# ------------ float types ------------4class Float(Parameter):5 """6 Floating point7 """8 _doc_type = ':class:`float`'9 def type(self, value):10 try:11 cast_value = float(value)12 except ValueError:13 raise ParameterError("value cannot be cast to a float: %r" % value)14 return cast_value15class PositiveFloat(Float):16 """17 Floating point >= 018 """19 def type(self, value):20 cast_value = super(PositiveFloat, self).type(value)21 if cast_value < 0:22 raise ParameterError("value is not positive: %g" % cast_value)23 return cast_value24class FloatRange(Float):25 """26 Floating point in the given range (inclusive)27 """28 def __init__(self, min, max, default, doc="[no description]"):29 """30 {``min`` <= value <= ``max``}31 :param min: minimum value32 :type min: float33 :param max: maximum value34 :type max: float35 """36 self.min = min37 self.max = max38 super(FloatRange, self).__init__(default, doc=doc)39 def type(self, value):40 cast_value = super(FloatRange, self).type(value)41 # Check range (min/max value of None is equivalent to -inf/inf)42 inside_range = True43 if (self.min is not None) and (cast_value < self.min):44 inside_range = False45 if (self.max is not None) and (cast_value > self.max):46 inside_range = False47 if not inside_range:48 raise ParameterError("value of %g outside the range {%s, %s}" % (49 cast_value, self.min, self.max50 ))51 return cast_value52# ------------ int types ---------------53class Int(Parameter):54 """55 Integer value56 """57 _doc_type = ":class:`int`"58 def type(self, value):59 try:60 cast_value = int(value)61 except ValueError:62 raise ParameterError("value cannot be cast to an integer: %r" % value)63 return cast_value64class PositiveInt(Int):65 """66 Integer >= 067 """68 def type(self, value):69 cast_value = super(PositiveInt, self).type(value)70 if cast_value < 0:71 raise ParameterError("value is not positive: %g" % cast_value)72 return cast_value73class IntRange(Int):74 """75 Integer in the given range (inclusive)76 """77 def __init__(self, min, max, default, doc="[no description]"):78 """79 {``min`` <= value <= ``max``}80 :param min: minimum value81 :type min: int82 :param max: maximum value83 :type max: int84 """85 self.min = min86 self.max = max87 super(IntRange, self).__init__(default, doc=doc)88 def type(self, value):89 cast_value = super(IntRange, self).type(value)90 # Check range (min/max value of None is equivalent to -inf/inf)91 inside_range = True92 if (self.min is not None) and (cast_value < self.min):93 inside_range = False94 if (self.max is not None) and (cast_value > self.max):95 inside_range = False96 if not inside_range:97 raise ParameterError("value of %g outside the range {%s, %s}" % (98 cast_value, self.min, self.max99 ))100 return cast_value101# ------------ boolean types ------------102class Boolean(Parameter):103 """104 Boolean value105 """106 _doc_type = ':class:`bool`'107 def type(self, value):108 try:109 cast_value = bool(value)110 except ValueError:111 raise ParameterError("value cannot be cast to bool: %r" % value)112 return cast_value113# ------------ string types ------------114class String(Parameter):115 """116 String value117 """118 _doc_type = ":class:`str`"119 def type(self, value):120 try:121 cast_value = str(value)122 except ValueError:123 raise ParameterError("value cannot be cast to string: %r" % value)124 return cast_value125class LowerCaseString(String):126 """127 Lower case string128 """129 def type(self, value):130 cast_value = super(LowerCaseString, self).type(value)131 return cast_value.lower()132class UpperCaseString(String):133 """134 Upper case string135 """136 def type(self, value):137 cast_value = super(UpperCaseString, self).type(value)138 return cast_value.upper()139# ------------ others ---------------140class NonNullParameter(Parameter):141 """142 Non-nullable parameter143 """144 def cast(self, value):145 if value is None:146 raise ParameterError("value cannot be None")147 return self.type(value)148class PartsList(Parameter):149 _doc_type = ":class:`list` of :class:`Part <cqparts.Part>` instances"150 def type(self, value):151 # Verify, raise exception for any problems152 if isinstance(value, (list, tuple)):153 from .. import Part # avoid circular dependency154 for part in value:155 if not isinstance(part, Part):156 raise ParameterError("value must be a list of Part instances")157 else:158 raise ParameterError("value must be a list")159 return value160class ComponentRef(Parameter):161 """162 Reference to a Component163 Initially introduced as a means to reference a sub-component's parent164 .. doctest::165 import cadquery166 from cqparts import Part, Component167 from cqparts.params import *168 class Eighth(Part):169 parent = ComponentRef(doc="part's parent")170 def make(self):171 size = self.parent.size / 2.172 return cadquery.Workplane('XY').box(size, size, size)173 class Cube(Assembly):174 size = PositiveFloat(10, doc="cube size")175 def make_components(self):176 # create a single cube 1/8 the volume of the whole cube177 return {178 'a': Eighth(parent=self),179 }180 def make_constraints(self):181 return [182 Fixed(self.components['a'].mate_origin),183 ]184 """185 def type(self, value):186 # Verify, raise exception for any problems187 from .. import Component # avoid circular dependency188 if not isinstance(value, Component):189 raise ParameterError("value must be a Component")...

Full Screen

Full Screen

credit_card.py

Source:credit_card.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2import re3from yandex_checkout.domain.common.base_object import BaseObject4class CreditCard(BaseObject):5 __number = None6 __expiry_year = None7 __expiry_month = None8 __csc = None9 __cardholder = None10 @property11 def number(self):12 return self.__number13 @number.setter14 def number(self, value):15 cast_value = str(value)16 if re.match('^[0-9]{12,19}$', cast_value):17 self.__number = cast_value18 else:19 raise ValueError('Invalid card number value')20 @property21 def expiry_year(self):22 return self.__expiry_year23 @expiry_year.setter24 def expiry_year(self, value):25 cast_value = str(value)26 if re.match('^\d\d\d\d$', cast_value) and 2000 < int(cast_value) < 2200:27 self.__expiry_year = cast_value28 else:29 raise ValueError('Invalid card expiry year value')30 @property31 def expiry_month(self):32 return self.__expiry_month33 @expiry_month.setter34 def expiry_month(self, value):35 cast_value = str(value)36 if re.match('^\d\d$', cast_value) and 0 < int(cast_value) <= 12:37 self.__expiry_month = cast_value38 else:39 raise ValueError('Invalid card expiry month value')40 @property41 def csc(self):42 return self.__csc43 @csc.setter44 def csc(self, value):45 cast_value = str(value)46 if re.match('^\d{3,4}$', cast_value):47 self.__csc = cast_value48 else:49 raise ValueError('Invalid card CSC code value')50 @property51 def cardholder(self):52 return self.__cardholder53 @cardholder.setter54 def cardholder(self, value):55 cast_value = str(value)56 if re.match('^[a-zA-Z\s]{1,26}$', cast_value):57 self.__cardholder = cast_value58 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful