onecondition.test

Contains methods to test various conditions about 1 or more values.

Module Contents

Functions

true(→ bool)

Test if a value is pythonically True.

false(→ bool)

Test if a value is pythonically False.

none(→ bool)

Test if a value is None.

specific_type(→ bool)

Test if a value is a specific type (do not consider inheritance).

instance(→ bool)

Test if a value is an instance (the same as or a subclass) of a specific type.

zero(→ bool)

Test if a value is exactly equal to 0.

positive(→ bool)

Test if a value is positive (non-zero).

negative(→ bool)

Test if a value is negative (non-zero).

range_inclusive(→ bool)

Test if a value is within a specified range (inclusive).

range_non_inclusive(→ bool)

Test if a value is within a specified range (non-inclusive).

eq(→ bool)

Test if a value is exactly equal to a second value.

gt(→ bool)

Test if a value is greater than a second value.

lt(→ bool)

Test if a value is less than a second value.

gte(→ bool)

Test if a value is greater than or equal to a second value.

lte(→ bool)

Test if a value is less than or equal to a second value.

onecondition.test.true(value: Any) bool

Test if a value is pythonically True.

Parameters:

value (Any) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> true(True)
True
>>> true(False)
False
>>> true(None)
False
>>> true(0)
False
>>> true(1)
True
>>> true("")
False
>>> true("foobar")
True
onecondition.test.false(value: Any) bool

Test if a value is pythonically False.

Parameters:

value (Any) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> false(True)
False
>>> false(False)
True
>>> false(0)
True
>>> false(1)
False
>>> false("")
True
>>> false("foobar")
False
onecondition.test.none(value: Any) bool

Test if a value is None.

Parameters:

value (Any) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> none(None)
True
>>> none("")
False
>>> none(42)
False
onecondition.test.specific_type(value: Any, value_type: type | types.UnionType | tuple[type | types.UnionType | tuple[Any, Ellipsis], Ellipsis]) bool

Test if a value is a specific type (do not consider inheritance).

Parameters:
  • value (Any) – The value to test.

  • value_type (type) – The type to test the value against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> class TestError(ValueError):
...     def __init__(self, message):
...         super().__init__(message)
>>> test_error = TestError("Test")
>>> specific_type(test_error, TestError)
True
>>> specific_type(test_error, ValueError)
False
>>> specific_type(test_error, (int, float))
False
onecondition.test.instance(value: Any, value_type: type | types.UnionType | tuple[type | types.UnionType | tuple[Any, Ellipsis], Ellipsis]) bool

Test if a value is an instance (the same as or a subclass) of a specific type.

Parameters:
  • value (Any) – The value to test.

  • value_type (type) – The type to test the value against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> class TestError(ValueError):
...     def __init__(self, message):
...         super().__init__(message)
>>> test_error = TestError("Test")
>>> instance(test_error, TestError)
True
>>> instance(test_error, ValueError)
True
>>> instance(test_error, (int, float))
False
onecondition.test.zero(value: int | float) bool

Test if a value is exactly equal to 0.

Parameters:

value (int | float) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> zero(42)
False
>>> zero(0)
True
>>> zero(-123.45)
False
onecondition.test.positive(value: int | float) bool

Test if a value is positive (non-zero).

Parameters:

value (int | float) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> positive(42)
True
>>> positive(0)
False
>>> positive(-123.45)
False
onecondition.test.negative(value: int | float) bool

Test if a value is negative (non-zero).

Parameters:

value (int | float) – The value to test.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> negative(42)
False
>>> negative(0)
False
>>> negative(-123.45)
True
onecondition.test.range_inclusive(value: int | float, minimum: int | float, maximum: int | float) bool

Test if a value is within a specified range (inclusive).

Parameters:
  • value (int | float) – The value to test.

  • minimum (int | float) – The minimum value to test against.

  • maximum (int | float) – The maximum value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> range_inclusive(-123.45, 0, 1)
False
>>> range_inclusive(0, 0, 1)
True
>>> range_inclusive(0.5, 0, 1)
True
>>> range_inclusive(1, 0, 1)
True
>>> range_inclusive(42, 0, 1)
False
onecondition.test.range_non_inclusive(value: int | float, minimum: int | float, maximum: int | float) bool

Test if a value is within a specified range (non-inclusive).

Parameters:
  • value (int | float) – The value to test.

  • minimum (int | float) – The minimum value to test against.

  • maximum (int | float) – The maximum value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> range_non_inclusive(-123.45, 0, 1)
False
>>> range_non_inclusive(0, 0, 1)
False
>>> range_non_inclusive(0.5, 0, 1)
True
>>> range_non_inclusive(1, 0, 1)
False
>>> range_non_inclusive(42, 0, 1)
False
onecondition.test.eq(first: Any, second: Any) bool

Test if a value is exactly equal to a second value.

Parameters:
  • first (Any) – The value to test.

  • second (Any) – The value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> eq(-123.45, 0)
False
>>> eq(0, 0)
True
>>> eq(42, 0)
False
>>> eq("foo", "bar")
False
>>> eq("foo", "foo")
True
onecondition.test.gt(first: int | float, second: int | float) bool

Test if a value is greater than a second value.

Parameters:
  • first (int | float) – The value to test.

  • second (int | float) – The value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> gt(-123.45, 0)
False
>>> gt(0, 0)
False
>>> gt(42, 0)
True
onecondition.test.lt(first: int | float, second: int | float) bool

Test if a value is less than a second value.

Parameters:
  • first (int | float) – The value to test.

  • second (int | float) – The value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> lt(-123.45, 0)
True
>>> lt(0, 0)
False
>>> lt(42, 0)
False
onecondition.test.gte(first: int | float, second: int | float) bool

Test if a value is greater than or equal to a second value.

Parameters:
  • first (int | float) – The value to test.

  • second (int | float) – The value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> gte(-123.45, 0)
False
>>> gte(0, 0)
True
>>> gte(42, 0)
True
onecondition.test.lte(first: int | float, second: int | float) bool

Test if a value is less than or equal to a second value.

Parameters:
  • first (int | float) – The value to test.

  • second (int | float) – The value to test against.

Returns:

The result of the evaluation.

Return type:

bool

Example:
>>> lte(-123.45, 0)
True
>>> lte(0, 0)
True
>>> lte(42, 0)
False