Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_process_optimizes_image #152

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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