Skip to content

Commit

Permalink
Use scalacheck effect in CE3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Mar 13, 2022
1 parent faf6d87 commit 8a1bfc4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
10 changes: 6 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
)
)

Expand Down
2 changes: 1 addition & 1 deletion cats/src/main/scala/frameless/cats/FramelessSyntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
34 changes: 18 additions & 16 deletions cats/src/test/scala/frameless/cats/FramelessSyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]])(
Expand All @@ -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
}
}
2 changes: 2 additions & 0 deletions docs/Cats.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
```

Expand Down

0 comments on commit 8a1bfc4

Please sign in to comment.