Best Python code snippet using lisa_python
validate.py
Source:validate.py  
2import pandas as pd3from pycargo.exceptions import ValidationException4class Validator:5    def __repr__(self) -> str:6        args = self._repr_args()7        args = "{},".format(args) if args else ""8        return f"<{self.__class__.__name__}({args})>"9    def _repr_args(self) -> str:10        return ""11class Required(Validator):12    default_message = "Required field"13    def __init__(self, error: str = None):14        self.error = error or self.default_message15    def _format_error(self, value) -> str:16        return self.error17    def __call__(self, value) -> None:18        if pd.isnull(value):19            raise ValidationException(self.error)20class Range(Validator):21    message_min = "Must be {min_op} {{min}}."22    message_max = "Must be {max_op} {{max}}."23    message_all = "Must be {min_op} {{min}} and {max_op} {{max}}."24    message_gte = "greater than or equal to"25    message_gt = "greater than"26    message_lte = "less than or equal to"27    message_lt = "less than"28    def __init__(29        self,30        min: int = None,31        max: int = None,32        min_inclusive: bool = True,33        max_inclusive: bool = True,34        error: typing.Optional[str] = None,35    ):36        self.min = min37        self.max = max38        self.min_inclusive = min_inclusive39        self.max_inclusive = max_inclusive40        self.error = error41        self.message_min = self.message_min.format(42            min_op=self.message_gte if self.min_inclusive else self.message_gt43        )44        self.message_max = self.message_max.format(45            max_op=self.message_lte if self.max_inclusive else self.message_lt46        )47        self.message_all = self.message_all.format(48            min_op=self.message_gte if self.min_inclusive else self.message_gt,49            max_op=self.message_lte if self.max_inclusive else self.message_lt,50        )51    def _repr_args(self) -> str:52        return (53            f"min={self.min!r}, "54            f"max={self.max!r}, "55            f"min_inclusive={self.min_inclusive!r}, "56            f"max_inclusive={self.max_inclusive!r}"57        )58    def _format_error(self, value: typing.Any, message: str) -> str:59        return (self.error or message).format(60            input=value, min=self.min, max=self.max61        )62    def __call__(self, value: typing.Any):63        if self.min is not None and (64            value < self.min if self.min_inclusive else value <= self.min65        ):66            message = (67                self.message_min if self.max is None else self.message_all68            )69            raise ValidationException(self._format_error(value, message))70        if self.max is not None and (71            value > self.max if self.max_inclusive else value >= self.max72        ):73            message = (74                self.message_max if self.min is None else self.message_all75            )76            raise ValidationException(self._format_error(value, message))77class Equal(Validator):78    default_message = "Must be equal to {other}"79    def __init__(80        self,81        comparable,82        error: typing.Optional[str] = None,83    ):84        self.comparable = comparable85        self.error = error or self.default_message86    def _repr_args(self) -> str:87        return f"comparable={self.comparable!r}"88    def _format_error(self, value):89        return self.error.format(value=value, other=self.comparable)90    def __call__(self, value):91        if value != self.comparable:92            raise ValidationException(self._format_error(value))93class OneOf(Validator):94    default_message = "Must be one of {choices}"95    def __init__(96        self, choices: typing.Iterable, error: typing.Optional[str] = None97    ):98        self.choices = choices99        self.error = error or self.default_message100    def _repr_args(self) -> str:101        return f"choices={self.choices!r}"102    def _format_error(self, value) -> str:103        return self.error.format(choices=self.choices, value=value)104    def __call__(self, value):105        try:106            if value not in self.choices:107                raise ValidationException(self._format_error(value))108        except TypeError as err:109            raise ValidationException(self._format_error(value)) from err110class NoneOf(Validator):111    default_message = "Must be none of {iterable}"112    def __init__(113        self, iterable: typing.Iterable, error: typing.Optional[str] = None114    ):115        self.iterable = iterable116        self.error = error or self.default_message117    def _repr_args(self) -> str:118        return f"iterable={self.iterable!r}"119    def _format_error(self, value: typing.Any) -> str:120        return self.error.format(iterable=self.iterable, value=value)121    def __call__(self, value):122        try:123            if value in self.iterable:124                raise ValidationException(self._format_error(value))125        except TypeError as err:...rcommands.py
Source:rcommands.py  
...14    def get_messages(self):15        return DELIMITER,16    def __repr__(self):17        class_name = self.__class__.__name__18        return '{}[{}]'.format(class_name, self._repr_args())19    def _repr_args(self):20        return ''21    def __len__(self):22        return sum((len(msg) for msg in self.get_messages()))23         24class JoinedCommand(RobotCommand):25    def __init__(self, commands):26        messages = tuple()27        for cmd in commands:28            messages += cmd.get_messages()29        self._messages = messages30        self._commands_str = ','.join((str(cmd) for cmd in commands))31    def get_messages(self):32        return self._messages33    def _repr_args(self):34        return self._commands_str35class DirectCommand(RobotCommand):36    def __init__(self, cmd):37        self._cmd = cmd38    def get_messages(self):39        return self._cmd.encode() + DELIMITER,40    def _repr_args(self):41        return '"{}"'.format(self._cmd)42class SetSpeed(RobotCommand):43    def __init__(self, speed_factor):44        self._speed_factor = speed_factor45    def get_messages(self):46        return 'set_speed:{:d}'.format(self._speed_factor).encode() + DELIMITER,47    def _repr_args(self):48        return '{:d}'.format(self._speed_factor)49class MotionCommand(RobotCommand):50    def __init__(self, template, vec, break_move=True):51        assert len(vec) == 652        self._template = template53        self._vec = vec54        self._break = break_move55    def get_messages(self):56        return create_motion_command(self._template, self._vec, self._break)57    def _repr_args(self):58        vs = vec_to_str(self._vec)59        return '{}, break={}'.format(vs, self._break)60class MoveToPose(MotionCommand):61    def __init__(self, pose, break_move=True):62        template = 'move_to:{:s}'63        super(MoveToPose, self).__init__(template, pose, break_move)64class MoveRelWorld(MotionCommand):65    def __init__(self, pose, break_move=True):66        template = 'move_rel_world:{:s}'67        super(MoveRelWorld, self).__init__(template, pose, break_move)68class MoveJoints(MotionCommand):69    def __init__(self, jconf, break_move=True):70        template = 'move_joints:{:s}'71        super(MoveJoints, self).__init__(template, jconf, break_move)72class MoveRelJoints(MotionCommand):73    def __init__(self, jconf, break_move=True):74        template = 'move_rel_joints:{:s}'75        super(MoveRelJoints, self).__init__(template, jconf, break_move)76class MoveRelTool(MotionCommand):77    def __init__(self, pose, break_move=True):78        template = 'move_rel_tool:{:s}'79        super(MoveRelTool, self).__init__(template, pose, break_move)80class MoveToolZ(MoveRelTool):81    def __init__(self, z, break_move=True):82        self._z = z83        pose = np.array([0, 0, z, 0, 0, 0])84        super(MoveToolZ, self).__init__(pose, break_move)85    def _repr_args(self):...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
