Esempio n. 1
0
from gutter.client.arguments.variables import Base as VariableBase
from gutter.client.operators import Base
from gutter.client.registry import operators


class EqualsStripIgnoreCase(Base):

    name = 'strip_ignorecase_equals'
    group = 'string'
    preposition = 'strip ignore case equal to'
    arguments = ('value', )

    def applies_to(self, argument):
        if isinstance(argument, VariableBase):
            argument = str(argument.value)
        else:
            argument = str(argument)

        return argument.lower().strip() == self.value.lower().strip()

    def __str__(self):
        return '%s "%s"' % (self.preposition, self.value.lower())


operators.register(EqualsStripIgnoreCase)
Esempio n. 2
0
    group = 'comparable'
    preposition = 'more than'
    arguments = ('lower_limit',)

    def applies_to(self, argument):
        return argument > self.lower_limit

    def __str__(self):
        return 'more than "%s"' % self.lower_limit


class MoreThanOrEqualTo(MoreThan):

    name = 'more_than_or_equal_to'
    group = 'comparable'
    preposition = 'more than or equal to'

    def applies_to(self, argument):
        return argument >= self.lower_limit

    def __str__(self):
        return 'more than or equal to "%s"' % self.lower_limit


operators.register(Equals)
operators.register(Between)
operators.register(LessThan)
operators.register(LessThanOrEqualTo)
operators.register(MoreThan)
operators.register(MoreThanOrEqualTo)
Esempio n. 3
0
        except DecimalException:
            decimal_argument = Decimal(hash(argument))

        return self.lower_limit <= self._modulo(decimal_argument) < self.upper_limit

    def __str__(self):
        return 'in %0.1f - %0.1f%% of values' % (self.lower_limit, self.upper_limit)


class Percent(PercentRange):

    name = 'percent'
    group = 'misc'
    preposition = 'within the percentage of'
    arguments = ('percentage',)

    def __init__(self, percentage):
        self.upper_limit = float(percentage)
        self.lower_limit = 0.0

    @property
    def variables(self):
        return dict(percentage=self.upper_limit)

    def __str__(self):
        return 'in %s%% of values' % self.upper_limit


operators.register(PercentRange)
operators.register(Percent)
Esempio n. 4
0
from gutter.client.arguments.variables import Base as VariableBase
from gutter.client.operators import Base
from gutter.client.registry import operators


class EqualsStripIgnoreCase(Base):

    name = 'strip_ignorecase_equals'
    group = 'string'
    preposition = 'strip ignore case equal to'
    arguments = ('value',)

    def applies_to(self, argument):
        if isinstance(argument, VariableBase):
            argument = str(argument.value)
        else:
            argument = str(argument)

        return argument.lower().strip() == self.value.lower().strip()

    def __str__(self):
        return '%s "%s"' % (self.preposition, self.value.lower())


operators.register(EqualsStripIgnoreCase)
Esempio n. 5
0
        return self.lower_limit <= self._modulo(
            decimal_argument) < self.upper_limit

    def __str__(self):
        return 'in %0.1f - %0.1f%% of values' % (self.lower_limit,
                                                 self.upper_limit)


class Percent(PercentRange):

    name = 'percent'
    group = 'misc'
    preposition = 'within the percentage of'
    arguments = ('percentage', )

    def __init__(self, percentage):
        self.upper_limit = float(percentage)
        self.lower_limit = 0.0

    @property
    def variables(self):
        return dict(percentage=self.upper_limit)

    def __str__(self):
        return 'in %s%% of values' % self.upper_limit


operators.register(PercentRange)
operators.register(Percent)
Esempio n. 6
0
from gutter.client.operators import Base
from gutter.client.registry import operators


class Truthy(Base):

    name = 'true'
    group = 'identity'
    preposition = 'true'

    def applies_to(self, argument):
        return bool(argument)

    def __str__(self):
        return 'true'


operators.register(Truthy)