expyct.collection module

class expyct.collection.AllOrAny(all: Optional[Any] = None, any: Optional[Any] = None)

Bases: expyct.base.BaseMatcher

Mixin for matching a collection object by checking that all or at least one of its members are equal to the given.

Like all other expyct objects, these can be nested. For example, assert l == exp.AllOrAny(all=exp.Int(min=3)).

Parameters
  • all – all members of collection must equal

  • any – any member of collection must equal

class expyct.collection.Collection(all: Optional[Any] = None, any: Optional[Any] = None, map_before: Optional[Callable] = None, optional: Optional[bool] = None, equals: Optional[Any] = None, type: Optional[Type] = None, instance_of: Optional[Type] = None, length: Optional[int] = None, min_length: Optional[int] = None, max_length: Optional[int] = None, non_empty: bool = False, superset_of: Optional[Collection] = None, subset_of: Optional[Collection] = None, satisfies: Optional[Callable[[Any], bool]] = None)

Bases: expyct.base.Satisfies, expyct.collection.Contains, expyct.collection.Length, expyct.base.Instance, expyct.base.Equals[Collection], expyct.base.Optional, expyct.base.MapBefore, expyct.collection.AllOrAny, expyct.base.BaseMatcher

Match any object that is an instance of typing.Collection.

Parameters
  • all – all members of collection must equal

  • any – any member of collection must equal

  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • type – type of object must equal to given type

  • instance_of – object must be an instance of given type

  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

  • satisfies – object must satisfy predicate

class expyct.collection.Contains(superset_of: Optional[Collection] = None, subset_of: Optional[Collection] = None)

Bases: expyct.base.BaseMatcher

Mixin matching a collection object by the containment of specified members.

Parameters
  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

class expyct.collection.Dict(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.collection.Contains, expyct.collection.Length, expyct.base.Equals[dict], expyct.base.Optional, expyct.base.MapBefore, expyct.base.BaseMatcher, dict

Match any object that is an instance of dict.

Parameters
  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

  • satisfies – object must satisfy predicate

  • keys – dict keys must equal

  • values – dict values must equal

  • keys_all – all dict keys must equal

  • keys_any – any dict key must equal

  • values_all – all dict values must equal

  • values_any – any dict value must equal

class expyct.collection.Length(length: Optional[int] = None, min_length: Optional[int] = None, max_length: Optional[int] = None, non_empty: bool = False)

Bases: expyct.base.BaseMatcher

Mixin for matching a collection object by its length as the result of len().

Parameters
  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

class expyct.collection.List(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.collection.Contains, expyct.collection.Length, expyct.base.Equals[list], expyct.base.Optional, expyct.base.MapBefore, expyct.collection.AllOrAny, expyct.base.BaseMatcher, list

Match any object that is an instance of list.

Parameters
  • all – all members of collection must equal

  • any – any member of collection must equal

  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

  • satisfies – object must satisfy predicate

  • ignore_order – whether to ignore order for equals

class expyct.collection.Set(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.collection.Contains, expyct.collection.Length, expyct.base.Equals[set], expyct.base.Optional, expyct.base.MapBefore, expyct.collection.AllOrAny, expyct.base.BaseMatcher, set

Match any object that is an instance of set.

Parameters
  • all – all members of collection must equal

  • any – any member of collection must equal

  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • type – type of object must equal to given type

  • instance_of – object must be an instance of given type

  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

  • satisfies – object must satisfy predicate

class expyct.collection.Tuple(*args, **kwargs)

Bases: expyct.base.Satisfies, expyct.collection.Contains, expyct.collection.Length, expyct.base.Equals[tuple], expyct.base.Optional, expyct.base.MapBefore, expyct.collection.AllOrAny, expyct.base.BaseMatcher, tuple

Match any object that is an instance of tuple.

Parameters
  • all – all members of collection must equal

  • any – any member of collection must equal

  • map_before – apply function before checking equality

  • optional – whether None is allowed

  • equals – object must equal exactly. This is useful together with map_before to check a value after applying a function

  • type – type of object must equal to given type

  • instance_of – object must be an instance of given type

  • length – object length must be exactly

  • min_length – object length must be at least

  • max_length – object length must be at most

  • non_empty – object must have at least one member [default: False]

  • superset_of – collection of which the object must be a superset

  • subset_of – collection of which the object must be a subset

  • satisfies – object must satisfy predicate

expyct.collection.ANY_COLLECTION = expyct.Instance(non_empty=False)

Any collection

expyct.collection.ANY_DICT = {}

Any instance of dict

expyct.collection.ANY_LIST = expyct.List(non_empty=False, ignore_order=False)

Any instance of list

expyct.collection.ANY_NONEMPTY_COLLECTION = expyct.Instance(non_empty=True)

Any non-empty collection

expyct.collection.ANY_NONEMPTY_DICT = {}

Any non-empty instance of dict

expyct.collection.ANY_NONEMPTY_LIST = expyct.List(non_empty=True, ignore_order=False)

Any non-empty instance of list

expyct.collection.ANY_NONEMPTY_SET = {}

Any non-empty instance of set

expyct.collection.ANY_NONEMPTY_TUPLE = expyct.Tuple(non_empty=True)

Any non-empty instance of tuple

expyct.collection.ANY_SET = {}

Any instance of set

expyct.collection.ANY_TUPLE = expyct.Tuple(non_empty=False)

Any instance of tuple