From 8a1bfc4a340a9ec5ad28d8f11372b2d122b6d713 Mon Sep 17 00:00:00 2001 From: Grigory Pomadchin Date: Sat, 12 Mar 2022 22:39:13 -0500 Subject: [PATCH] Use scalacheck effect in CE3 tests --- build.sbt | 10 +++--- .../frameless/cats/FramelessSyntax.scala | 2 +- .../frameless/cats/FramelessSyntaxTests.scala | 34 ++++++++++--------- docs/Cats.md | 2 ++ 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/build.sbt b/build.sbt index 72b23e327..1a17fd917 100644 --- a/build.sbt +++ b/build.sbt @@ -8,6 +8,7 @@ val scalatest = "3.2.11" val scalatestplus = "3.1.0.0-RC2" val shapeless = "2.3.7" val scalacheck = "1.15.4" +val scalacheckEffect = "1.0.3" val refinedVersion = "0.9.28" val Scala212 = "2.12.15" @@ -160,10 +161,11 @@ def sparkMlDependencies(sparkVersion: String, scope: Configuration = Provided) = lazy val catsSettings = framelessSettings ++ Seq( addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full), libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % catsCoreVersion, - "org.typelevel" %% "cats-effect" % catsEffectVersion, - "org.typelevel" %% "cats-mtl" % catsMtlVersion, - "org.typelevel" %% "alleycats-core" % catsCoreVersion + "org.typelevel" %% "cats-core" % catsCoreVersion, + "org.typelevel" %% "cats-effect" % catsEffectVersion, + "org.typelevel" %% "cats-mtl" % catsMtlVersion, + "org.typelevel" %% "alleycats-core" % catsCoreVersion, + "org.typelevel" %% "scalacheck-effect" % scalacheckEffect % Test ) ) diff --git a/cats/src/main/scala/frameless/cats/FramelessSyntax.scala b/cats/src/main/scala/frameless/cats/FramelessSyntax.scala index 97c988aca..663ae5958 100644 --- a/cats/src/main/scala/frameless/cats/FramelessSyntax.scala +++ b/cats/src/main/scala/frameless/cats/FramelessSyntax.scala @@ -19,6 +19,6 @@ trait FramelessSyntax extends frameless.FramelessSyntax { def withGroupId(groupId: String): F[A] = withLocalProperty("spark.jobGroup.id", groupId) - def withDescription(description: String) = withLocalProperty("spark.job.description", description) + def withDescription(description: String): F[A] = withLocalProperty("spark.job.description", description) } } diff --git a/cats/src/test/scala/frameless/cats/FramelessSyntaxTests.scala b/cats/src/test/scala/frameless/cats/FramelessSyntaxTests.scala index 247172573..6b9f54ce4 100644 --- a/cats/src/test/scala/frameless/cats/FramelessSyntaxTests.scala +++ b/cats/src/test/scala/frameless/cats/FramelessSyntaxTests.scala @@ -4,12 +4,13 @@ package cats import _root_.cats.data.ReaderT import _root_.cats.effect.IO import _root_.cats.effect.unsafe.implicits.global -import frameless.{ TypedDataset, TypedDatasetSuite, TypedEncoder, X2 } import org.apache.spark.sql.SparkSession +import org.scalatest.matchers.should.Matchers +import org.scalacheck.{Test => PTest} import org.scalacheck.Prop, Prop._ +import org.scalacheck.effect.PropF, PropF._ - -class FramelessSyntaxTests extends TypedDatasetSuite { +class FramelessSyntaxTests extends TypedDatasetSuite with Matchers { override val sparkDelay = null def prop[A, B](data: Vector[X2[A, B]])( @@ -34,18 +35,19 @@ class FramelessSyntaxTests extends TypedDatasetSuite { import implicits._ import _root_.cats.syntax.all._ - check { - forAll { (k:String, v: String) => - val scopedKey = "frameless.tests." + k - 1.pure[ReaderT[IO, SparkSession, *]].withLocalProperty(scopedKey,v).run(session).unsafeRunSync() - sc.getLocalProperty(scopedKey) ?= v - - 1.pure[ReaderT[IO, SparkSession, *]].withGroupId(v).run(session).unsafeRunSync() - sc.getLocalProperty("spark.jobGroup.id") ?= v - - 1.pure[ReaderT[IO, SparkSession, *]].withDescription(v).run(session).unsafeRunSync() - sc.getLocalProperty("spark.job.description") ?= v - } - } + forAllF { (k: String, v: String) => + val scopedKey = "frameless.tests." + k + 1 + .pure[ReaderT[IO, SparkSession, *]] + .withLocalProperty(scopedKey, v) + .withGroupId(v) + .withDescription(v) + .run(session) + .map { _ => + sc.getLocalProperty(scopedKey) shouldBe v + sc.getLocalProperty("spark.jobGroup.id") shouldBe v + sc.getLocalProperty("spark.job.description") shouldBe v + }.void + }.check().unsafeRunSync() shouldBe PTest.Passed } } diff --git a/docs/Cats.md b/docs/Cats.md index c2a24a6df..3976e3d0a 100644 --- a/docs/Cats.md +++ b/docs/Cats.md @@ -70,6 +70,8 @@ As with `Job`, note that nothing has been run yet. The effect has been properly run our program, we must first supply the `SparkSession` to the `ReaderT` layer and then run the `IO` effect: ```scala mdoc +import cats.effect.unsafe.implicits.global + result.run(spark).unsafeRunSync() ```