Exemple #1
0
 def test_two_args__integer_ranges__half_open(self):
     self._assertIntegerFunctionsEqual(
         Or_.GREATER_THAN(5),  # lower minimum "wins"
         __unit__.or_(Or_.GREATER_THAN(5), Or_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         Or_.LESS_THAN(10),  # higher maximum "wins"
         __unit__.or_(Or_.LESS_THAN(5), Or_.LESS_THAN(10)))
Exemple #2
0
 def test_two_args__integer_ranges__half_open(self):
     self._assertIntegerFunctionsEqual(
         Or_.GREATER_THAN(5),  # lower minimum "wins"
         __unit__.or_(Or_.GREATER_THAN(5), Or_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         Or_.LESS_THAN(10),  # higher maximum "wins"
         __unit__.or_(Or_.LESS_THAN(5), Or_.LESS_THAN(10)))
Exemple #3
0
 def test_two_args__integer_ranges__open(self):
     self._assertIntegerFunctionsEqual(
         Or_.OUTSIDE(5, 10),
         __unit__.or_(Or_.LESS_THAN(5), Or_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE,
         __unit__.or_(Or_.GREATER_THAN(5), Or_.LESS_THAN(10)))
Exemple #4
0
 def test_two_args__boolean_functions(self):
     self._assertBooleanFunctionsEqual(Or_.TRUE,
                                       __unit__.or_(Or_.TRUE, Or_.TRUE))
     self._assertBooleanFunctionsEqual(Or_.TRUE,
                                       __unit__.or_(Or_.TRUE, Or_.FALSE))
     self._assertBooleanFunctionsEqual(Or_.TRUE,
                                       __unit__.or_(Or_.FALSE, Or_.TRUE))
     self._assertBooleanFunctionsEqual(Or_.FALSE,
                                       __unit__.or_(Or_.FALSE, Or_.FALSE))
Exemple #5
0
 def test_two_args__boolean_functions(self):
     self._assertBooleanFunctionsEqual(
         Or_.TRUE, __unit__.or_(Or_.TRUE, Or_.TRUE))
     self._assertBooleanFunctionsEqual(
         Or_.TRUE, __unit__.or_(Or_.TRUE, Or_.FALSE))
     self._assertBooleanFunctionsEqual(
         Or_.TRUE, __unit__.or_(Or_.FALSE, Or_.TRUE))
     self._assertBooleanFunctionsEqual(
         Or_.FALSE, __unit__.or_(Or_.FALSE, Or_.FALSE))
Exemple #6
0
 def test_three_args__even_integer_intervals(self):
     self._assertIntegerFunctionsEqual(
         Or_.EVEN_OR_OUTSIDE(5, 10),
         __unit__.or_(Or_.LESS_THAN(5), Or_.GREATER_THAN(10),
                       Or_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE,  # because the ranges overlap
         __unit__.or_(Or_.GREATER_THAN(6), Or_.LESS_THAN(7),
                       Or_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE,  # because an even number closes the gap between ranges
         __unit__.or_(Or_.GREATER_THAN(10), Or_.LESS_THAN(10),
                       Or_.DIVISIBLE_BY(2)))
Exemple #7
0
 def test_three_args__even_integer_intervals(self):
     self._assertIntegerFunctionsEqual(
         Or_.EVEN_OR_OUTSIDE(5, 10),
         __unit__.or_(Or_.LESS_THAN(5), Or_.GREATER_THAN(10),
                      Or_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE,  # because the ranges overlap
         __unit__.or_(Or_.GREATER_THAN(6), Or_.LESS_THAN(7),
                      Or_.DIVISIBLE_BY(2)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE,  # because an even number closes the gap between ranges
         __unit__.or_(Or_.GREATER_THAN(10), Or_.LESS_THAN(10),
                      Or_.DIVISIBLE_BY(2)))
Exemple #8
0
def decorator(decor):
    """Decorator for decorators (sic), written either as classes or functions.

    In either case, the decorator ``decor`` must be "doubly-callable":

        * for classes, this means implementing ``__call__`` method
          in addition to possible ``__init__``
        * for functions, this means returning a function that acts
          as an actual decorator, i.e. taking a function and returning
          its decorated version

    Although it works for any decorator, it's useful mainly for those
    that should take optional arguments. If the decorator is adorned
    with ``@decorator``, it's possible to use it without the pair of
    empty parentheses::

        @enhanced  # rather than @enhanced()
        def foo():
            pass

    when we don't want to pass any arguments to it.

    .. note::

        :func:`decorator` makes decorator appicable for both
        functions and classes. If you want to restrict the type of
        decorator targets, use :func:`function_decorator`,
        :func:`method_decorator` or :func:`class_decorator`.
    """
    ensure_callable(decor)
    return _wrap_decorator(decor, "functions or classes",
                           or_(inspect.isfunction, inspect.isclass))
Exemple #9
0
 def test_two_args__integer_ranges__open(self):
     self._assertIntegerFunctionsEqual(
         Or_.OUTSIDE(5, 10),
         __unit__.or_(Or_.LESS_THAN(5), Or_.GREATER_THAN(10)))
     self._assertIntegerFunctionsEqual(
         Or_.TRUE, __unit__.or_(Or_.GREATER_THAN(5), Or_.LESS_THAN(10)))
Exemple #10
0
 def test_one_arg__false(self):
     self._assertBooleanFunctionsEqual(Or_.FALSE, __unit__.or_(Or_.FALSE))
Exemple #11
0
 def test_one_arg__true(self):
     self._assertBooleanFunctionsEqual(Or_.TRUE, __unit__.or_(Or_.TRUE))
Exemple #12
0
 def test_one_arg__none(self):
     with self.assertRaises(TypeError):
         __unit__.or_(None)
Exemple #13
0
 def test_one_arg__none(self):
     with self.assertRaises(TypeError):
         __unit__.or_(None)
Exemple #14
0
 def test_one_arg__false(self):
     self._assertBooleanFunctionsEqual(Or_.FALSE, __unit__.or_(Or_.FALSE))
Exemple #15
0
 def test_one_arg__true(self):
     self._assertBooleanFunctionsEqual(Or_.TRUE, __unit__.or_(Or_.TRUE))
Exemple #16
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         __unit__.or_()
Exemple #17
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         __unit__.or_()