Ejemplo n.º 1
0
 def test_two_args__integer_ranges__closed(self):
     self._assertIntegerFunctionsEqual(
         And_.BETWEEN(5, 10),
         __unit__.and_(And_.GREATER_THAN(5), And_.LESS_THAN(10)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE, __unit__.and_(And_.GREATER_THAN(10),
                                   And_.LESS_THAN(5)))
Ejemplo n.º 2
0
 def test_two_args__integer_ranges__closed(self):
     self._assertIntegerFunctionsEqual(
         And_.BETWEEN(5, 10),
         __unit__.and_(And_.GREATER_THAN(5), And_.LESS_THAN(10)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE,
         __unit__.and_(And_.GREATER_THAN(10), And_.LESS_THAN(5)))
Ejemplo n.º 3
0
 def test_two_args__integer_ranges__half_open(self):
     self._assertIntegerFunctionsEqual(
         And_.GREATER_THAN(10),  # higher minimum "wins"
         __unit__.and_(And_.GREATER_THAN(5), And_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         And_.LESS_THAN(5),  # lower maximum "wins"
         __unit__.and_(And_.LESS_THAN(5), And_.LESS_THAN(10)))
Ejemplo n.º 4
0
 def test_two_args__integer_ranges__half_open(self):
     self._assertIntegerFunctionsEqual(
         And_.GREATER_THAN(10),  # higher minimum "wins"
         __unit__.and_(And_.GREATER_THAN(5), And_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         And_.LESS_THAN(5),  # lower maximum "wins"
         __unit__.and_(And_.LESS_THAN(5), And_.LESS_THAN(10)))
Ejemplo n.º 5
0
 def test_two_args__boolean_functions(self):
     self._assertBooleanFunctionsEqual(And_.TRUE,
                                       __unit__.and_(And_.TRUE, And_.TRUE))
     self._assertBooleanFunctionsEqual(And_.FALSE,
                                       __unit__.and_(And_.TRUE, And_.FALSE))
     self._assertBooleanFunctionsEqual(And_.FALSE,
                                       __unit__.and_(And_.FALSE, And_.TRUE))
     self._assertBooleanFunctionsEqual(
         And_.FALSE, __unit__.and_(And_.FALSE, And_.FALSE))
Ejemplo n.º 6
0
 def test_two_args__boolean_functions(self):
     self._assertBooleanFunctionsEqual(
         And_.TRUE, __unit__.and_(And_.TRUE, And_.TRUE))
     self._assertBooleanFunctionsEqual(
         And_.FALSE, __unit__.and_(And_.TRUE, And_.FALSE))
     self._assertBooleanFunctionsEqual(
         And_.FALSE, __unit__.and_(And_.FALSE, And_.TRUE))
     self._assertBooleanFunctionsEqual(
         And_.FALSE, __unit__.and_(And_.FALSE, And_.FALSE))
Ejemplo n.º 7
0
 def test_three_args__even_integer_intervals(self):
     self._assertIntegerFunctionsEqual(
         And_.EVEN_BETWEEN(5, 10),
         __unit__.and_(And_.GREATER_THAN(5), And_.LESS_THAN(10),
                       And_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE,  # because there are no even numbers in range
         __unit__.and_(And_.GREATER_THAN(6), And_.LESS_THAN(7),
                       And_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE,  # because there are no numbers in range
         __unit__.and_(And_.GREATER_THAN(10), And_.LESS_THAN(5),
                       And_.DIVISIBLE_BY(2)))
Ejemplo n.º 8
0
 def test_three_args__even_integer_intervals(self):
     self._assertIntegerFunctionsEqual(
         And_.EVEN_BETWEEN(5, 10),
         __unit__.and_(And_.GREATER_THAN(5), And_.LESS_THAN(10),
                       And_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE,  # because there are no even numbers in range
         __unit__.and_(And_.GREATER_THAN(6), And_.LESS_THAN(7),
                       And_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         And_.FALSE,  # because there are no numbers in range
         __unit__.and_(And_.GREATER_THAN(10), And_.LESS_THAN(5),
                       And_.DIVISIBLE_BY(2)))
Ejemplo n.º 9
0
 def test_one_arg__false(self):
     self._assertBooleanFunctionsEqual(And_.FALSE,
                                       __unit__.and_(And_.FALSE))
Ejemplo n.º 10
0
 def test_one_arg__true(self):
     self._assertBooleanFunctionsEqual(And_.TRUE, __unit__.and_(And_.TRUE))
Ejemplo n.º 11
0
 def test_one_arg__none(self):
     with self.assertRaises(TypeError):
         __unit__.and_(None)
Ejemplo n.º 12
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         __unit__.and_()
Ejemplo n.º 13
0
 def test_one_arg__false(self):
     self._assertBooleanFunctionsEqual(And_.FALSE, __unit__.and_(And_.FALSE))
Ejemplo n.º 14
0
 def test_one_arg__true(self):
     self._assertBooleanFunctionsEqual(And_.TRUE, __unit__.and_(And_.TRUE))
Ejemplo n.º 15
0
 def test_one_arg__none(self):
     with self.assertRaises(TypeError):
         __unit__.and_(None)
Ejemplo n.º 16
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         __unit__.and_()
Ejemplo n.º 17
0
    result = breadth_first(class_, ascend)
    next(result)  # omit ``class_`` itself
    return result


# Metaclass utilities


def is_metaclass(obj):
    """Checks whether given object is a metaclass.
    :return: ``True`` if object is a metaclass, ``False`` otherwise
    """
    return issubclass(obj, type)


def ensure_metaclass(arg):
    """Check whether argument is a metaclass.
    :return: Argument, if it's a metaclass
    :raise TypeError: When argument is not a metaclass
    """
    if not is_metaclass(arg):
        raise TypeError("expected a metaclass, got %s instead" %
                        type(arg).__name__)
    return arg


# Expose the :class:`metaclass` decorator after augmenting it with type checks.
metaclass = _wrap_decorator(metaclass, "non-meta classes",
                            and_(inspect.isclass, not_(is_metaclass)))
metaclass.__name__ = 'metaclass'
Ejemplo n.º 18
0
    result = breadth_first(class_, ascend)
    next(result)  # omit ``class_`` itself
    return result


# Metaclass utilities

def is_metaclass(obj):
    """Checks whether given object is a metaclass.
    :return: ``True`` if object is a metaclass, ``False`` otherwise
    """
    return issubclass(obj, type)


def ensure_metaclass(arg):
    """Check whether argument is a metaclass.
    :return: Argument, if it's a metaclass
    :raise TypeError: When argument is not a metaclass
    """
    if not is_metaclass(arg):
        raise TypeError(
            "expected a metaclass, got %s instead" % type(arg).__name__)
    return arg


# Expose the :class:`metaclass` decorator after augmenting it with type checks.
metaclass = _wrap_decorator(metaclass, "non-meta classes",
                            and_(inspect.isclass, not_(is_metaclass)))
metaclass.__name__ = 'metaclass'