Skip to content

Selene Exceptions#

This is the latest development version

Some features documented on this page may not yet be available in the published stable version.

ConditionMismatch #

Bases: AssertionError

An error to through during assertion if the asserting condition is not matched.

Contains a bunch of factory methods to transform regular predicates (functions that returns True/False) into condition functions that raise this error (ConditionMismatch) where predicate would return false.

Is handy for building custom expected conditions for explicit waits and assertions. See a practical examples of application in Expected Conditions guide.

Examples of usage of factory methods:

# GIVEN
class predicate:
    @staticmethod
    def is_positive(x) -> bool:
        return x > 0

def is_positive(x) -> bool:
    return x > 0

def decremented(x) -> int:
    return x - 1

# THEN (all will pass without error)
ConditionMismatch.to_raise_if_not(predicate.is_positive)(1)
ConditionMismatch.to_raise_if_not(is_positive)(1)
ConditionMismatch.to_raise_if(predicate.is_positive)(0)
ConditionMismatch.to_raise_if(is_positive)(0)

ConditionMismatch.to_raise_if_not(Query('is positive', lambda x: x > 0))(1)
ConditionMismatch.to_raise_if(Query('is positive', lambda x: x > 0))(0)

ConditionMismatch.to_raise_if_not(
    Query('is positive', lambda x: x > 0),
    Query('decremented', lambda x: x - 1),
)(2)
ConditionMismatch.to_raise_if_not(
    Query('is positive', lambda x: x > 0),
    decremented,
)(2)
ConditionMismatch.to_raise_if_not(is_positive, decremented)(2)
ConditionMismatch.to_raise_if(is_positive, decremented)(1)
ConditionMismatch.to_raise_if_not(actual=decremented, by=is_positive)(2)
ConditionMismatch.to_raise_if(actual=decremented, by=is_positive)(1)

ConditionMismatch.to_raise_if_not_actual(decremented, predicate.is_positive)(2)
ConditionMismatch.to_raise_if_actual(decremented, predicate.is_positive)(1)
ConditionMismatch.to_raise_if_not_actual(decremented, predicate.is_positive)(2)
ConditionMismatch.to_raise_if_actual(decremented, is_positive)(1)

ConditionMismatch.to_raise_if_not_actual(
    Query('decremented', lambda x: x - 1),
    Query('is positive', lambda x: x > 0)
)(2)
# ...

ConditionNotMatchedError #

TimeoutException #

Bases: AssertionError

msg = msg instance-attribute #