Skip to content

Commit

Permalink
Remove maxPercentDifference
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodbx committed Jul 12, 2024
1 parent f3ac474 commit 1781060
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 39 deletions.
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 @@ -86,10 +86,7 @@ class RenderExtensionTest {
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = File("src/test/resources/${snapshot.name}").apply {
mkdirs()
}
failureDir = File("src/test/resources/${snapshot.name}").apply { mkdirs() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class AccessibilityRenderExtensionTest {
relativePath = expected.path,
image = image,
goldenImage = ImageIO.read(expected),
maxPercentDifferent = 0.1,
failureDir = tempDir.newFolder()
)
}
Expand Down
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 Down Expand Up @@ -94,7 +92,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 3,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand Down Expand Up @@ -128,7 +125,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 3,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand Down Expand Up @@ -166,7 +162,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 3,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(thirdFrame)
Expand Down Expand Up @@ -200,7 +195,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 5,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand Down Expand Up @@ -237,7 +231,6 @@ class ApngVerifierTest {
deltaFilePath = deltaFile.toOkioPath(),
fps = 1,
frameCount = 2,
maxPercentDifference = 0.0,
withErrorText = false
).use {
it.verifyFrame(firstFrame)
Expand Down
Binary file modified paparazzi/src/test/resources/accessibility-new-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified paparazzi/src/test/resources/accessibility.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified paparazzi/src/test/resources/without-layout-params.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 1781060

Please sign in to comment.