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)))
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)))
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))
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))
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)))
def test_one_arg__false(self): self._assertBooleanFunctionsEqual(And_.FALSE, __unit__.and_(And_.FALSE))
def test_one_arg__true(self): self._assertBooleanFunctionsEqual(And_.TRUE, __unit__.and_(And_.TRUE))
def test_one_arg__none(self): with self.assertRaises(TypeError): __unit__.and_(None)
def test_no_args(self): with self.assertRaises(TypeError): __unit__.and_()
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'
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'