Validate.assert_passing

Validate.assert_passing()

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.

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). After interrogation, the assert_passing() method is used to assert that all validation steps passed perfectly.

import pointblank as pb
import polars as pl

tbl = 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"])
    .interrogate()
)

validation.assert_passing()
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[1], line 20
      4 tbl = pl.DataFrame(
      5     {
      6     "a": [1, 2, 9, 5],
   (...)
      9     }
     10 )
     12 validation = (
     13     pb.Validate(data=tbl)
     14     .col_vals_gt(columns="a", value=0)
   (...)
     17     .interrogate()
     18 )
---> 20 validation.assert_passing()

File /opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/pointblank/validate.py:5448, in Validate.assert_passing(self)
   5440 failed_steps = [
   5441     (i, str(step.autobrief))
   5442     for i, step in enumerate(self.validation_info)
   5443     if step.n_failed > 0
   5444 ]
   5445 msg = "The following assertions failed:\n" + "\n".join(
   5446     [f"- Step {i + 1}: {autobrief}" for i, autobrief in failed_steps]
   5447 )
-> 5448 raise AssertionError(msg)

AssertionError: The following assertions failed:
- Step 2: Expect that values in `b` should be < `9`.