Skip to content

Commit

Permalink
Fix test_process_optimizes_image
Browse files Browse the repository at this point in the history
On my machine, one optimized version is 56kb smaller which surpasses the
allowed tolerance but not in a negative way.

use `assertAlmostEqual` instead because it's delta parameter is clearer
than a factor.
  • Loading branch information
Stormheg committed Sep 5, 2024
1 parent 9640d33 commit c6a7d70
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions tests/test_optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ def setUpClass(cls) -> None:
cls.optimized_size = os.fstat(f.fileno()).st_size
cls.optimized_image = f.read()

def _fairly_equal(self, a, b, tolerance=0.001):
"""
Checks that two number are within a certain tolerance of each other.
We want to account for slight variations in how the libraries optimize the images under different OSes.
"""
return abs(a - b) <= tolerance * a

def test_process_optimizes_image(self):
try:
with NamedTemporaryFile(delete=False) as named_temporary_file:
Expand All @@ -90,10 +83,8 @@ def test_process_optimizes_image(self):
self.optimizer.process(image_file)

with open(image_file, "rb") as f:
self.assertTrue(
self._fairly_equal(
self.optimized_size, os.fstat(f.fileno()).st_size
)
self.assertAlmostEqual(
self.optimized_size, os.fstat(f.fileno()).st_size, delta=60
)
finally:
os.unlink(image_file)
Expand Down

0 comments on commit c6a7d70

Please sign in to comment.