Operator matchers

Comparisons

These matchers use Python’s relational operators: <, >=, etc.

class callee.operators.Less(*args, **kwargs)[source]

Matches values that are smaller (as per < operator) than given object.

Accepts a single argument: the reference object to compare against.

It can be passed either as a single positional parameter, or as a single keyword argument – preferably with a readable name, for example:

some_mock.assert_called_with(Number() & LessOrEqual(to=42))
callee.operators.LessThan

alias of callee.operators.Less

callee.operators.Lt

alias of callee.operators.Less

class callee.operators.LessOrEqual(*args, **kwargs)[source]

Matches values that are smaller than, or equal to (as per <= operator), given object.

Accepts a single argument: the reference object to compare against.

It can be passed either as a single positional parameter, or as a single keyword argument – preferably with a readable name, for example:

some_mock.assert_called_with(Number() & LessOrEqual(to=42))
callee.operators.LessOrEqualTo

alias of callee.operators.LessOrEqual

callee.operators.Le

alias of callee.operators.LessOrEqual

class callee.operators.Greater(*args, **kwargs)[source]

Matches values that are greater (as per > operator) than given object.

Accepts a single argument: the reference object to compare against.

It can be passed either as a single positional parameter, or as a single keyword argument – preferably with a readable name, for example:

some_mock.assert_called_with(Number() & LessOrEqual(to=42))
callee.operators.GreaterThan

alias of callee.operators.Greater

callee.operators.Gt

alias of callee.operators.Greater

class callee.operators.GreaterOrEqual(*args, **kwargs)[source]

Matches values that are greater than, or equal to (as per >= operator), given object.

Accepts a single argument: the reference object to compare against.

It can be passed either as a single positional parameter, or as a single keyword argument – preferably with a readable name, for example:

some_mock.assert_called_with(Number() & LessOrEqual(to=42))
callee.operators.GreaterOrEqualTo

alias of callee.operators.GreaterOrEqual

callee.operators.Ge

alias of callee.operators.GreaterOrEqual

By length

In addition to simple comparison matchers described, callee offers a set of dedicated matchers for asserting on object’s length. You can use them in conjunction with any Python Sequence: a string, list, collections.deque, and so on.

class callee.operators.Shorter(*args, **kwargs)[source]

Matches values that are shorter (as per < comparison on len) than given value.

callee.operators.ShorterThan

alias of callee.operators.Shorter

class callee.operators.ShorterOrEqual(*args, **kwargs)[source]

Matches values that are shorter than, or equal in length to (as per <= operator), given object.

callee.operators.ShorterOrEqualTo

alias of callee.operators.ShorterOrEqual

class callee.operators.Longer(*args, **kwargs)[source]

Matches values that are longer (as per > comparison on len) than given value.

callee.operators.LongerThan

alias of callee.operators.Longer

class callee.operators.LongerOrEqual(*args, **kwargs)[source]

Matches values that are longer than, or equal in length to (as per >= operator), given object.

callee.operators.LongerOrEqualTo

alias of callee.operators.LongerOrEqual

Memberships

class callee.operators.Contains(value)[source]

Matches values that contain (as per the in operator) given reference object.

class callee.operators.In(container)[source]

Matches values that are within the reference object (as per the in operator).

Identity

class callee.operators.Is(value)[source]

Matches a value using the identity (is) operator.

class callee.operators.IsNot(value)[source]

Matches a value using the negated identity (is not) operator.

Equality

Note

You will most likely never use the following matcher, but it’s included for completeness.

class callee.operators.Eq(value)[source]

Matches a value exactly using the equality (==) operator.

This is already the default mode of operation for assert_called_with methods on mocks, making this matcher redundant in most situations:

mock_foo.assert_called_with(bar)
mock_foo.assert_called_with(Eq(bar))  # equivalent

In very rare and specialized cases, however, if the tested code treats callee matcher objects in some special way, using Eq may be necessary.

Those situations shouldn’t generally arise outside of writing tests for code that is itself a test library or helper.

Parameters:value – Value to match against