Best Python code snippet using sure_python
comparison.py
Source:comparison.py  
1# 2# Copyright (C) 2007-2008  Camptocamp3#  4# This file is part of MapFish Server5#  6# MapFish Server is free software: you can redistribute it and/or modify7# it under the terms of the GNU Lesser General Public License as published by8# the Free Software Foundation, either version 3 of the License, or9# (at your option) any later version.10#  11# MapFish Server is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the14# GNU Lesser General Public License for more details.15#  16# You should have received a copy of the GNU Lesser General Public License17# along with MapFish Server.  If not, see <http://www.gnu.org/licenses/>.18#19from mapfish.lib.filters import Filter20from sqlalchemy.sql import and_21class Comparison(Filter):22    EQUAL_TO = '=='23    NOT_EQUAL_TO = '!='24    LOWER_THAN = '<'25    LOWER_THAN_OR_EQUAL_TO = '<='26    GREATER_THAN = '>'27    GREATER_THAN_OR_EQUAL_TO = '>='28    BETWEEN = '..'29    LIKE = '~'30    ILIKE = '~~'31    def __init__(self, type, column, **kwargs):32        """Create a comparison filter.33          type34              the type of filter to create. Possible values are:35                Comparison.EQUAL_TO36                Comparison.NOT_EQUAL_TO37                Comparison.LOWER_THAN38                Comparison.LOWER_THAN_OR_EQUAL_TO39                Comparison.GREATER_THAN40                Comparison.GREATER_THAN_OR_EQUAL_TO41                Comparison.BETWEEN42                Comparison.LIKE43                Comparison.ILIKE44          column45              the column to use for the comparison. 46          \**kwargs47              lower_bound48                the lower bound value, to be used with the BETWEEN type.49              upper_bound50                the upper bound value, to be used with the BETWEEN type.51              value52                the value to use.53        """54        self.type = type55        self.column = column56        self.values = kwargs57    def to_sql_expr(self):58        """Return the SQLAlchemy SQL expression corresponding to that filter.59        """60        if self.type == Comparison.EQUAL_TO:61            return self.column == self.values['value']62        if self.type == Comparison.NOT_EQUAL_TO:63            return self.column != self.values['value']64        if self.type == Comparison.LOWER_THAN:65            return self.column < self.values['value']66        if self.type == Comparison.LOWER_THAN_OR_EQUAL_TO:67            return self.column <= self.values['value']68        if self.type == Comparison.GREATER_THAN:69            return self.column > self.values['value']70        if self.type == Comparison.GREATER_THAN_OR_EQUAL_TO:71            return self.column >= self.values['value']72        if self.type == Comparison.BETWEEN:73            return and_(74                self.column <= self.values['upper_bound'],75                self.column >= self.values['lower_bound']76            )77        if self.type == Comparison.LIKE:78            return self.column.like('%' + self.values['value'] + '%')79        if self.type == Comparison.ILIKE:...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!!
