@@ -431,10 +431,12 @@ def isGreaterThan(self, columnA, columnB, assertion=None, hint=None):
431431 df = VerificationResult .checkResultsAsDataFrame (self .spark , result )
432432 return df .select ("constraint_status" ).collect ()
433433
434- def isContainedIn (self , column , allowed_values ):
434+ def isContainedIn (self , column , allowed_values , assertion = None , hint = None ):
435435 check = Check (self .spark , CheckLevel .Warning , "test isContainedIn" )
436436 result = (
437- VerificationSuite (self .spark ).onData (self .df ).addCheck (check .isContainedIn (column , allowed_values )).run ()
437+ VerificationSuite (self .spark ).onData (self .df ).addCheck (
438+ check .isContainedIn (column , allowed_values , assertion = assertion , hint = hint )
439+ ).run ()
438440 )
439441
440442 df = VerificationResult .checkResultsAsDataFrame (self .spark , result )
@@ -1134,6 +1136,11 @@ def test_fail_satisfies(self):
11341136
11351137 def test_hasPattern (self ):
11361138 self .assertEqual (self .hasPattern ("ssn" , "\d{3}\-\d{2}\-\d{4}" , lambda x : x == 2 / 3 ), [Row (constraint_status = "Success" )])
1139+ # Default assertion is 1, thus failure
1140+ self .assertEqual (self .hasPattern ("ssn" , "\d{3}\-\d{2}\-\d{4}" ), [Row (constraint_status = "Failure" )])
1141+ self .assertEqual (
1142+ self .hasPattern ("ssn" , "\d{3}\-\d{2}\-\d{4}" , lambda x : x == 2 / 3 , hint = "it be should be above 0.66" ),
1143+ [Row (constraint_status = "Success" )])
11371144
11381145 @pytest .mark .xfail (reason = "@unittest.expectedFailure" )
11391146 def test_fail_hasPattern (self ):
@@ -1206,6 +1213,12 @@ def test_fail_isGreaterThan(self):
12061213 self .assertEqual (self .isGreaterThan ("h" , "f" , lambda x : x == 1 ), [Row (constraint_status = "Success" )])
12071214
12081215 def test_isContainedIn (self ):
1216+ # test all variants for assertion and hint
1217+ self .assertEqual (
1218+ self .isContainedIn ("a" , ["foo" , "bar" , "baz" ], lambda x : x == 1 ), [Row (constraint_status = "Success" )])
1219+ self .assertEqual (
1220+ self .isContainedIn ("a" , ["foo" , "bar" , "baz" ], lambda x : x == 1 , hint = "it should be 1" ),
1221+ [Row (constraint_status = "Success" )])
12091222 self .assertEqual (self .isContainedIn ("a" , ["foo" , "bar" , "baz" ]), [Row (constraint_status = "Success" )])
12101223 # A none value makes the test still pass
12111224 self .assertEqual (self .isContainedIn ("c" , ["5" , "6" ]), [Row (constraint_status = "Success" )])
0 commit comments