Any.object.of_type(User).with_attrs({"username": "name", "id": 4})
Any.object(User, {"username": "name", "id": 4})
You can make basic comparisons to collections as follows:
Any.iterable()
Any.list()
Any.set()
You can specify a custom class with:
Any.iterable.of_type(MyCustomList)
You can also chain on to add requirements for the size.
Any.iterable.of_size(4)
Any.list.of_size(at_least=3)
Any.set.of_size(at_most=5)
Any.set.of_size(at_least=3, at_most=5)
You can require an iterable to have a minimum number of items, with repetitions , optionally in order:
Any.iterable.containing([1])
Any.list.containing([1, 2, 2])
Any.list.containing([1, 2, 2]).in_order()
This will match if the sequence is found any where in the iterable.
You can also say that there cannot be any extra items in the iterable:
Any.set.containing({2, 3, 4}).only()
Any.list.containing([1, 2, 2, 3]).only().in_order()
All of this should work with non-hashable items too as long as the items test as equal:
Any.set.containing([{'a': 1}, {'b': 2}])
You can specify that every item in the collection must match a certain item. You can also pass matchers to this:
Any.list.comprised_of(Any.string).of_size(6)
Any.iterable.comprised_of(True)
Basic comparisons are available:
Any.iterable()
Any.mapping()
Any.dict()
Any.dict.of_size(at_most=4)
Any.dict.containing(['key_1', 'key_2']).only()
Any.dict.containing({'a': 5, 'b': 6})
Any.dict.containing({'a': 5, 'b': 6}).only()
This is useful for dict-like objects which may have different behavior and semantics to regular dicts. For example: objects which support multiple values for the same key.
Any.mapping.containing(MultiDict(['a', 1], ['a', 2]))