changeset 921:6b38f55114c4

helper method to compare zip sizes including a tolerance
author Alain Mazy <am@orthanc.team>
date Wed, 03 Jun 2026 15:56:00 +0200
parents a2051215a485
children f8511b19e114
files Tests/Tests.py
diffstat 1 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Tests/Tests.py	Tue Jun 02 22:21:24 2026 +0200
+++ b/Tests/Tests.py	Wed Jun 03 15:56:00 2026 +0200
@@ -7081,6 +7081,11 @@
             else:
                 self.assertEqual(a, b)
 
+    # Helper method to use when comparing zip because the zip size may depend on timestamp and other stuffs.
+    # We have seen differences of 4 bytes but let's take a 0.1% margin
+    def assertZipSizesAlmostEqual(self, sizeA, sizeB):
+        tolerance = max(4, sizeA/1000)
+        self.assertLess(abs(sizeA - sizeB), tolerance)
 
     def test_transcode_lossy_compression_ratio(self):
         i = UploadInstance(_REMOTE, 'ColorTestImageJ.dcm')['ID']
@@ -7102,7 +7107,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
 
                 # Contrary to DCMTK, GDCM doesn't automatically set "LossyImageCompressionRatio" (0028,2112)
                 self.assertEqual(ratio40, '')
@@ -7140,7 +7145,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7179,7 +7184,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7209,7 +7214,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7248,7 +7253,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7307,7 +7312,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7327,7 +7332,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7348,7 +7353,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)
 
@@ -7359,7 +7364,7 @@
 
             if HasGdcmPlugin(_REMOTE):
                 # The plugin SDK doesn't currently allow to pass lossyQuality to plugins
-                self.assertEqual(size40, size80)
+                self.assertZipSizesAlmostEqual(size40, size80)
             else:
                 self.assertLess(size40, size80)