Raise an AssertionError if all tests are not passing.
The assert_passing() method will raise an AssertionError if a test does not pass. This method simply wraps all_passed for more ready use in test suites. The step number and assertion made is printed in the AssertionError message if a failure occurs, ensuring some details are preserved.
If the validation has not yet been interrogated, this method will automatically call interrogate() with default parameters before checking for passing tests.
Raises
:AssertionError
If any validation step has failing test units.
Examples
In the example below, we’ll use a simple Polars DataFrame with three columns (a, b, and c). There will be three validation steps, and the second step will have a failing test unit (the value 10 isn’t less than 9). The assert_passing() method is used to assert that all validation steps passed perfectly, automatically performing the interrogation if needed.
import pointblank as pbimport polars as pltbl = pl.DataFrame( {"a": [1, 2, 9, 5],"b": [5, 6, 10, 3],"c": ["a", "b", "a", "a"], })validation = ( pb.Validate(data=tbl) .col_vals_gt(columns="a", value=0) .col_vals_lt(columns="b", value=9) # this assertion is false .col_vals_in_set(columns="c", set=["a", "b"]))# No need to call [`interrogate()`](`pointblank.Validate.interrogate`) explicitlyvalidation.assert_passing()
---------------------------------------------------------------------------AssertionError Traceback (most recent call last)
/tmp/ipykernel_3104/2424908189.py in ?() 16.col_vals_in_set(columns="c", set=["a","b"]) 17 )
18 19# No need to call [`interrogate()`](`pointblank.Validate.interrogate`) explicitly---> 20validation.assert_passing()/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/pointblank/validate.py in ?(self) 8827 ]
8828 msg = "The following assertions failed:\n" + "\n".join(
8829[f"- Step {i + 1}: {autobrief}"for i, autobrief in failed_steps] 8830 )
-> 8831raise AssertionError(msg)AssertionError: The following assertions failed:
- Step 2: Expect that values in `b` should be < `9`.