Skip to content

Commit 5dc3638

Browse files
tylermcdaniel0Tyler Mcdaniel
authored andcommitted
Test that exceptions within a check's constraints do not affect other checks in a verification suite. (#516)
Co-authored-by: Tyler Mcdaniel <[email protected]>
1 parent a2741df commit 5dc3638

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<artifactId>scalatest-maven-plugin</artifactId>
199199
<version>1.0</version>
200200
<configuration>
201+
<stdout>F</stdout>
201202
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
202203
<junitxml>.</junitxml>
203204
<filereports>WDF TestSuite.txt</filereports>

src/test/scala/com/amazon/deequ/VerificationSuiteTest.scala

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import com.amazon.deequ.anomalydetection.AbsoluteChangeStrategy
2222
import com.amazon.deequ.checks.Check
2323
import com.amazon.deequ.checks.CheckLevel
2424
import com.amazon.deequ.checks.CheckStatus
25-
import com.amazon.deequ.constraints.Constraint
25+
import com.amazon.deequ.constraints.{Constraint, ConstraintResult}
2626
import com.amazon.deequ.io.DfsUtils
27-
import com.amazon.deequ.metrics.DoubleMetric
28-
import com.amazon.deequ.metrics.Entity
27+
import com.amazon.deequ.metrics.{DoubleMetric, Entity, Metric}
2928
import com.amazon.deequ.repository.MetricsRepository
3029
import com.amazon.deequ.repository.ResultKey
3130
import com.amazon.deequ.repository.memory.InMemoryMetricsRepository
@@ -849,6 +848,55 @@ class VerificationSuiteTest extends WordSpec with Matchers with SparkContextSpec
849848
assert(checkFailedCompletenessResult.status == CheckStatus.Error)
850849
}
851850

851+
"Well-defined checks should produce correct result even if another check throws an exception" in withSparkSession {
852+
sparkSession =>
853+
val df = getDfWithNameAndAge(sparkSession)
854+
855+
856+
val checkThatShouldSucceed =
857+
Check(CheckLevel.Error, "shouldSucceedForValue").isComplete("name")
858+
859+
860+
val checkThatWillThrow = Check(CheckLevel.Error, "shouldThrow")
861+
.hasSize(_ => {
862+
throw new IllegalArgumentException("borked")
863+
})
864+
865+
val complianceCheckThatShouldSucceed =
866+
Check(CheckLevel.Error, "shouldSucceedForAge").isContainedIn("age", 1, 100)
867+
868+
869+
val isCompleteCheckThatShouldFailCompleteness = Check(CheckLevel.Error, "shouldErrorStringType")
870+
.isComplete("fake")
871+
872+
val verificationResult = VerificationSuite()
873+
.onData(df)
874+
.addCheck(checkThatShouldSucceed)
875+
.addCheck(checkThatWillThrow)
876+
.addCheck(isCompleteCheckThatShouldFailCompleteness)
877+
.addCheck(complianceCheckThatShouldSucceed)
878+
.run()
879+
880+
val checkSuccessResult = verificationResult.checkResults(checkThatShouldSucceed)
881+
checkSuccessResult.constraintResults.map(_.message) shouldBe List(None)
882+
assert(checkSuccessResult.status == CheckStatus.Success)
883+
884+
val checkExceptionResult = verificationResult.checkResults(checkThatWillThrow)
885+
checkExceptionResult.constraintResults.map(_.message) shouldBe
886+
List(Some("Can't execute the assertion: borked!"))
887+
assert(checkExceptionResult.status == CheckStatus.Error)
888+
889+
val checkIsCompleteFailedResult = verificationResult.checkResults(isCompleteCheckThatShouldFailCompleteness)
890+
checkIsCompleteFailedResult.constraintResults.map(_.message) shouldBe
891+
List(Some("Input data does not include column fake!"))
892+
assert(checkIsCompleteFailedResult.status == CheckStatus.Error)
893+
894+
val checkAgeSuccessResult = verificationResult.checkResults(complianceCheckThatShouldSucceed)
895+
checkAgeSuccessResult.constraintResults.map(_.message) shouldBe List(None)
896+
assert(checkAgeSuccessResult.status == CheckStatus.Success)
897+
898+
}
899+
852900
"A well-defined completeness check should pass even with a single column" in withSparkSession {
853901
sparkSession =>
854902
val df = getDfWithVariableStringLengthValues(sparkSession)

0 commit comments

Comments
 (0)