Skip to content

Commit

Permalink
Test that exceptions within a check's constraints do not affect other…
Browse files Browse the repository at this point in the history
… checks in a verification suite. (#516)

Co-authored-by: Tyler Mcdaniel <[email protected]>
  • Loading branch information
tylermcdaniel0 and Tyler Mcdaniel authored Oct 27, 2023
1 parent cedcf07 commit 32e1155
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<stdout>F</stdout>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
Expand Down
54 changes: 51 additions & 3 deletions src/test/scala/com/amazon/deequ/VerificationSuiteTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import com.amazon.deequ.anomalydetection.AbsoluteChangeStrategy
import com.amazon.deequ.checks.Check
import com.amazon.deequ.checks.CheckLevel
import com.amazon.deequ.checks.CheckStatus
import com.amazon.deequ.constraints.Constraint
import com.amazon.deequ.constraints.{Constraint, ConstraintResult}
import com.amazon.deequ.io.DfsUtils
import com.amazon.deequ.metrics.DoubleMetric
import com.amazon.deequ.metrics.Entity
import com.amazon.deequ.metrics.{DoubleMetric, Entity, Metric}
import com.amazon.deequ.repository.MetricsRepository
import com.amazon.deequ.repository.ResultKey
import com.amazon.deequ.repository.memory.InMemoryMetricsRepository
Expand Down Expand Up @@ -849,6 +848,55 @@ class VerificationSuiteTest extends WordSpec with Matchers with SparkContextSpec
assert(checkFailedCompletenessResult.status == CheckStatus.Error)
}

"Well-defined checks should produce correct result even if another check throws an exception" in withSparkSession {
sparkSession =>
val df = getDfWithNameAndAge(sparkSession)


val checkThatShouldSucceed =
Check(CheckLevel.Error, "shouldSucceedForValue").isComplete("name")


val checkThatWillThrow = Check(CheckLevel.Error, "shouldThrow")
.hasSize(_ => {
throw new IllegalArgumentException("borked")
})

val complianceCheckThatShouldSucceed =
Check(CheckLevel.Error, "shouldSucceedForAge").isContainedIn("age", 1, 100)


val isCompleteCheckThatShouldFailCompleteness = Check(CheckLevel.Error, "shouldErrorStringType")
.isComplete("fake")

val verificationResult = VerificationSuite()
.onData(df)
.addCheck(checkThatShouldSucceed)
.addCheck(checkThatWillThrow)
.addCheck(isCompleteCheckThatShouldFailCompleteness)
.addCheck(complianceCheckThatShouldSucceed)
.run()

val checkSuccessResult = verificationResult.checkResults(checkThatShouldSucceed)
checkSuccessResult.constraintResults.map(_.message) shouldBe List(None)
assert(checkSuccessResult.status == CheckStatus.Success)

val checkExceptionResult = verificationResult.checkResults(checkThatWillThrow)
checkExceptionResult.constraintResults.map(_.message) shouldBe
List(Some("Can't execute the assertion: borked!"))
assert(checkExceptionResult.status == CheckStatus.Error)

val checkIsCompleteFailedResult = verificationResult.checkResults(isCompleteCheckThatShouldFailCompleteness)
checkIsCompleteFailedResult.constraintResults.map(_.message) shouldBe
List(Some("Input data does not include column fake!"))
assert(checkIsCompleteFailedResult.status == CheckStatus.Error)

val checkAgeSuccessResult = verificationResult.checkResults(complianceCheckThatShouldSucceed)
checkAgeSuccessResult.constraintResults.map(_.message) shouldBe List(None)
assert(checkAgeSuccessResult.status == CheckStatus.Success)

}

"A well-defined completeness check should pass even with a single column" in withSparkSession {
sparkSession =>
val df = getDfWithVariableStringLengthValues(sparkSession)
Expand Down

0 comments on commit 32e1155

Please sign in to comment.