Skip to content

Commit

Permalink
Remove maxPercentDifference
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodbx committed Jul 13, 2024
1 parent 43c4550 commit b888b78
Show file tree
Hide file tree
Showing 34 changed files with 26 additions and 116 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 10 additions & 11 deletions paparazzi/api/paparazzi.api
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,13 @@ public final class app/cash/paparazzi/Paparazzi : org/junit/rules/TestRule {
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;Z)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZD)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;Z)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZ)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZ)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZZ)V
public synthetic fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZDLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;Z)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZ)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZ)V
public fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZZ)V
public synthetic fun <init> (Lapp/cash/paparazzi/Environment;Lapp/cash/paparazzi/DeviceConfig;Ljava/lang/String;Lcom/android/ide/common/rendering/api/SessionParams$RenderingMode;ZLapp/cash/paparazzi/SnapshotHandler;Ljava/util/Set;ZZZZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun apply (Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;)Lorg/junit/runners/model/Statement;
public final fun close ()V
public final fun getContext ()Landroid/content/Context;
Expand Down Expand Up @@ -209,9 +208,9 @@ public abstract interface class app/cash/paparazzi/SnapshotHandler$FrameHandler

public final class app/cash/paparazzi/SnapshotVerifier : app/cash/paparazzi/SnapshotHandler {
public static final field $stable I
public fun <init> (D)V
public fun <init> (DLjava/io/File;)V
public synthetic fun <init> (DLjava/io/File;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> ()V
public fun <init> (Ljava/io/File;)V
public synthetic fun <init> (Ljava/io/File;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public fun newFrameHandler (Lapp/cash/paparazzi/Snapshot;II)Lapp/cash/paparazzi/SnapshotHandler$FrameHandler;
}
Expand Down
7 changes: 3 additions & 4 deletions paparazzi/src/main/java/app/cash/paparazzi/Paparazzi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class Paparazzi @JvmOverloads constructor(
private val theme: String = "android:Theme.Material.NoActionBar.Fullscreen",
private val renderingMode: RenderingMode = RenderingMode.NORMAL,
private val appCompatEnabled: Boolean = true,
private val maxPercentDifference: Double = 0.1,
private val snapshotHandler: SnapshotHandler = determineHandler(maxPercentDifference),
private val snapshotHandler: SnapshotHandler = determineHandler(),
private val renderExtensions: Set<RenderExtension> = setOf(),
private val supportsRtl: Boolean = false,
private val showSystemUi: Boolean = false,
Expand Down Expand Up @@ -153,9 +152,9 @@ public class Paparazzi @JvmOverloads constructor(
private val isVerifying: Boolean =
System.getProperty("paparazzi.test.verify")?.toBoolean() == true

private fun determineHandler(maxPercentDifference: Double): SnapshotHandler =
private fun determineHandler(): SnapshotHandler =
if (isVerifying) {
SnapshotVerifier(maxPercentDifference)
SnapshotVerifier()
} else {
HtmlReportWriter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import java.io.File
import javax.imageio.ImageIO

public class SnapshotVerifier @JvmOverloads constructor(
private val maxPercentDifference: Double,
rootDirectory: File = File(System.getProperty("paparazzi.snapshot.dir"))
) : SnapshotHandler {
private val imagesDirectory: File = File(rootDirectory, "images")
Expand All @@ -45,7 +44,7 @@ public class SnapshotVerifier @JvmOverloads constructor(
val expected = File(snapshotDir, snapshot.toFileName(extension = "png"))
val failurePath = File(failureDir, "delta-${expected.name}").toOkioPath()
val pngVerifier: ApngVerifier? = if (fps != -1) {
ApngVerifier(expected.toOkioPath(), failurePath, fps, frameCount, maxPercentDifference)
ApngVerifier(expected.toOkioPath(), failurePath, fps, frameCount)
} else {
null
}
Expand Down Expand Up @@ -74,7 +73,6 @@ public class SnapshotVerifier @JvmOverloads constructor(
relativePath = expected.path,
image = image,
goldenImage = goldenImage,
maxPercentDifferent = maxPercentDifference,
failureDir = failureDir
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ internal object ImageUtils {
relativePath: String,
goldenImage: BufferedImage,
image: BufferedImage,
maxPercentDifferent: Double,
failureDir: File
) {
val (deltaImage, percentDifference) = compareImages(goldenImage, image)
Expand All @@ -62,7 +61,7 @@ internal object ImageUtils {

val imageName = getName(relativePath)
var error = when {
percentDifference > maxPercentDifferent -> "Images differ (by %f%%)".format(percentDifference)
percentDifference > 0f -> "Images differ (by %f%%)".format(percentDifference)
abs(goldenImageWidth - imageWidth) >= 2 ->
"Widths differ too much for $imageName: ${goldenImageWidth}x$goldenImageHeight vs ${imageWidth}x$imageHeight"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal class ApngVerifier(
private val deltaFilePath: Path,
private val fps: Int,
private val frameCount: Int,
private val maxPercentDifference: Double,
private val fileSystem: FileSystem = FileSystem.SYSTEM,
private val withErrorText: Boolean = true
) : Closeable {
Expand All @@ -56,7 +55,7 @@ internal class ApngVerifier(
fun verifyFrame(image: BufferedImage) {
val (expectedFrame, actualFrame) = resizeMaxBounds(currentGoldenFrame ?: blankFrame, image)
val (deltaImage, percentDifferent) = ImageUtils.compareImages(expectedFrame, actualFrame)
if (percentDifferent > maxPercentDifference) {
if (percentDifferent > 0f) {
if (deltaWriter == null) {
deltaWriter = pngReader.initializeWriter()
}
Expand Down Expand Up @@ -106,9 +105,7 @@ internal class ApngVerifier(

val error = buildString {
if (invalidFrames >= 1) {
appendLine(
"$invalidFrames frames differed by more than %.1f%%".format(maxPercentDifference)
)
appendLine("$invalidFrames frames differ")
}
if (pngReader.getFps() != fps) {
appendLine("Mismatched video fps expected: ${pngReader.getFps()} actual: $fps")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@ import android.widget.Button
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import app.cash.paparazzi.internal.ImageUtils
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

class RenderExtensionTest {
@get:Rule
val tempDir = TemporaryFolder()

private val snapshotHandler = TestSnapshotVerifier()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5,
snapshotHandler = snapshotHandler,
snapshotHandler = SnapshotVerifier(),
renderExtensions = setOf(
WrappedRenderExtension(Color.DKGRAY),
WrappedRenderExtension(Color.RED),
Expand Down Expand Up @@ -72,33 +62,6 @@ class RenderExtensionTest {
}
)
}

private inner class TestSnapshotVerifier : SnapshotHandler {
override fun newFrameHandler(
snapshot: Snapshot,
frameCount: Int,
fps: Int
): SnapshotHandler.FrameHandler {
return object : SnapshotHandler.FrameHandler {
override fun handle(image: BufferedImage) {
val expected = File("src/test/resources/${snapshot.name}.png")
ImageUtils.assertImageSimilar(
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = File("src/test/resources/${snapshot.name}").apply {
mkdirs()
}
)
}

override fun close() = Unit
}
}

override fun close() = Unit
}
}

class WrappedRenderExtension(val color: Int) : RenderExtension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,15 @@ import android.widget.LinearLayout
import android.widget.TextView
import app.cash.paparazzi.DeviceConfig
import app.cash.paparazzi.Paparazzi
import app.cash.paparazzi.Snapshot
import app.cash.paparazzi.SnapshotHandler
import app.cash.paparazzi.internal.ImageUtils
import app.cash.paparazzi.SnapshotVerifier
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO

class AccessibilityRenderExtensionTest {
@get:Rule
val tempDir = TemporaryFolder()

private val snapshotHandler = TestSnapshotVerifier()

@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.NEXUS_5,
snapshotHandler = snapshotHandler,
snapshotHandler = SnapshotVerifier(),
renderExtensions = setOf(AccessibilityRenderExtension())
)

Expand Down Expand Up @@ -117,29 +106,4 @@ class AccessibilityRenderExtensionTest {
}
)
}

private inner class TestSnapshotVerifier : SnapshotHandler {
override fun newFrameHandler(
snapshot: Snapshot,
frameCount: Int,
fps: Int
): SnapshotHandler.FrameHandler {
return object : SnapshotHandler.FrameHandler {
override fun handle(image: BufferedImage) {
val expected = File("src/test/resources/${snapshot.name}.png")
ImageUtils.assertImageSimilar(
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = tempDir.newFolder()
)
}

override fun close() = Unit
}
}

override fun close() = Unit
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ApngReaderTest {
relativePath = expectedFile!!.path,
goldenImage = expectedImage,
image = actualImage,
maxPercentDifferent = 0.0,
failureDir = tempDir.newFolder()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -59,7 +58,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 3,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -71,7 +69,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"4 frames differed by more than 0.0%\n" +
"4 frames differ\n" +
"Mismatched video fps expected: 1 actual: 3\n" +
" - see details in file://${deltaFile.path}\n\n"
)
Expand All @@ -94,7 +92,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 3,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -105,7 +102,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"4 frames differed by more than 0.0%\n" +
"4 frames differ\n" +
"Mismatched video fps expected: 1 actual: 3\n" +
" - see details in file://${deltaFile.path}\n\n"
)
Expand All @@ -128,7 +125,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 3,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -143,7 +139,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"1 frames differed by more than 0.0%\n" +
"1 frames differ\n" +
"Mismatched video fps expected: 1 actual: 3\n" +
" - see details in file://${deltaFile.path}\n\n"
)
Expand All @@ -166,7 +162,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(thirdFrame)
Expand All @@ -178,7 +173,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"2 frames differed by more than 0.0%\n" +
"2 frames differ\n" +
" - see details in file://${deltaFile.path}\n\n"
)
}
Expand All @@ -200,7 +195,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 5,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -214,7 +208,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"2 frames differed by more than 0.0%\n" +
"2 frames differ\n" +
"Mismatched frame count expected: 3 actual: 5\n" +
" - see details in file://${deltaFile.path}\n\n"
)
Expand All @@ -237,7 +231,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 2,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand All @@ -248,7 +241,7 @@ class ApngVerifierTest {
fail("Should have already failed")
} catch (e: AssertionError) {
assertThat(e.message).isEqualTo(
"1 frames differed by more than 0.0%\n" +
"1 frames differ\n" +
"Mismatched frame count expected: 3 actual: 2\n" +
" - see details in file://${deltaFile.path}\n\n"
)
Expand Down
Binary file not shown.
Binary file removed paparazzi/src/test/resources/accessibility.png
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.junit.Test
class ComposeDialogShrinkTest {
@get:Rule
val paparazzi = Paparazzi(
maxPercentDifference = 1.0,
deviceConfig = DeviceConfig.PIXEL_5.copy(softButtons = false),
renderingMode = RenderingMode.SHRINK
)
Expand Down

0 comments on commit b888b78

Please sign in to comment.