A small assertion library
Project description
Fluent Assertions
A DSL like assertion library that enables concise high quality assertions in your tests
Assertions
Assertions follow a simple pattern
assert_that(subject).matches(comparison) # object or criteria
assert_that(subject).does_not_match(comparison) # object or criteria
# Same as above
assert_that(subject) == comparison # object or criteria
assert_that(subject) != comparison # object or criteria
Using matchers without criteria, just use classic asserts
assert 2 == is_greater_than(1)
Critera Objects
Critera helps define complex assertions in a concise manner
Some examples of criteria
assert_that(5).matches(is_greater_than(4))
assert_that(5).matches(is_greater_than_or_equal(5))
assert_that(5).matches(is_odd())
Logical criteria operations
assert_that(5).matches(is_odd() & is_greater_than(4)) # And
assert_that(5).matches(is_odd() | is_greater_than(10)) # Or
assert_that(5).matches(~is_even()) # Inverted
Matching
Basic
is_equal_to
assert_that(5).matches(5)
assert_that(5).matches(is_equal_to(5))
assert_that("hello").matches("hello")
assert_that("hello").matches(is_equal_to("hello"))
is_greater_than
assert_that(5).matches(is_greater_than(3))
assert_that(5) == is_greater_than(3)
is_greater_than_or_equal
assert_that(5).matches(is_greater_than_or_equal(5))
is_less_than
assert_that(5).matches(is_less_than(10))
is_less_than_or_equal
assert_that(5).matches(is_less_than_or_equal(10))
assert_that(5).matches(is_less_than_or_equal(5))
is_between
assert_that(5).matches(is_between(5, 10)) # passes
assert_that(5).matches(is_between(5, 10).exclusive) # fails
assert_that(5).matches(is_between(5, 10).inclusive) # passes
is_same_instance_as
x = "hello"
y = x
assert_that(x).matches(is_same_instance_as(y)) # passes
as_string_matches
When the subject called with the str the subject matches the criteria
assert_that(5).matches(as_string_matches("5")) # passes
assert_that(12345).matches(as_string_matches(ends_with("45"))) # passes
Exceptions
Exceptions can be tested in two different ways.
- As a callable
assert_that(lambda: my_exception_raising_method(123)).matches(raises_exception(Exception))
- As a context manager
with raises_exception(Exception):
my_exception_raising_method(123)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
assertive-0.0.3.tar.gz
(10.5 kB
view hashes)
Built Distribution
assertive-0.0.3-py3-none-any.whl
(14.1 kB
view hashes)
Close
Hashes for assertive-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59411fffeb0121aa1876447c54661f8212916fc2ad3486d71b1cc0c0a679d977 |
|
MD5 | aeeedebc1343501cd882c41d867ba888 |
|
BLAKE2b-256 | dde883b064e7604e3cedf1362de87a6c3225c9b505ec4796d2f3cf3d4a9e1ddd |