Skip to content

Commit

Permalink
formatting and use math.isclose for sonar happiness #1
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-mccarthy committed Sep 8, 2024
1 parent ef3cf7d commit 5227153
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions tests/capture/test_average_brightness.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest
import math
from unittest.mock import patch, MagicMock
from PIL import Image
from src.app.capture.exposure import calculate_average_brightness
Expand All @@ -15,7 +15,7 @@ def test_completely_dark_image(mock_open):
average_brightness = calculate_average_brightness("dummy_path")

# Assert
assert average_brightness == 0
math.isclose(average_brightness, 0.0)


@patch("src.app.capture.exposure.Image.open")
Expand All @@ -29,7 +29,7 @@ def test_completely_bright_image(mock_open):
average_brightness = calculate_average_brightness("dummy_path")

# Assert
assert average_brightness == 1.0
assert math.isclose(average_brightness, 1.0)


@patch("src.app.capture.exposure.Image.open")
Expand All @@ -45,4 +45,4 @@ def test_mid_tone_image(mock_open):
average_brightness = calculate_average_brightness("dummy_path")

# Assert
assert average_brightness == 0.5
assert math.isclose(average_brightness, 0.5)
22 changes: 11 additions & 11 deletions tests/capture/test_exposure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unittest
import math
from unittest.mock import patch, MagicMock
from src.app.capture.exposure import calculate_next_exposure_value
from src.app.configuration.nsp_configuration import Capture
Expand All @@ -22,8 +22,8 @@ def test_brightness_below_lower_threshold(mock_calculate_average_brightness):
calculate_next_exposure_value("dummy_path", capture)

# Assert
assert capture.shutter.current == 200.03
assert capture.gain.current == 1.0
assert math.isclose(capture.shutter.current, 200, rel_tol=0.5)
assert math.isclose(capture.gain.current, 1.0)


@patch("src.app.capture.exposure.calculate_average_brightness")
Expand All @@ -44,8 +44,8 @@ def test_brightness_above_upper_threshold(mock_calculate_average_brightness):
calculate_next_exposure_value("dummy_path", capture)

# Assert
assert capture.shutter.current == 95.0
assert capture.gain.current == 1.0
assert math.isclose(capture.shutter.current, 95, rel_tol=0.5)
assert math.isclose(capture.gain.current, 1.0)


@patch("src.app.capture.exposure.calculate_average_brightness")
Expand All @@ -66,8 +66,8 @@ def test_brightness_above_upper_threshold_gain(mock_calculate_average_brightness
calculate_next_exposure_value("dummy_path", capture)

# Assert
assert capture.shutter.current == 100
assert capture.gain.current == 6.65
assert math.isclose(capture.shutter.current, 100)
assert math.isclose(capture.gain.current, 6.6, rel_tol=0.5)


@patch("src.app.capture.exposure.calculate_average_brightness")
Expand All @@ -88,8 +88,8 @@ def test_brightness_below_lower_threshold_gain(mock_calculate_average_brightness
calculate_next_exposure_value("dummy_path", capture)

# Assert
assert capture.shutter.current == 10000
assert capture.gain.current == 1.15
assert math.isclose(capture.shutter.current, 10000)
assert math.isclose(capture.gain.current, 1.1, rel_tol=0.5)


@patch("src.app.capture.exposure.calculate_average_brightness")
Expand All @@ -109,5 +109,5 @@ def test_brightness_within_tolerance(mock_calculate_average_brightness):
# Act
calculate_next_exposure_value("dummy_path", capture)

assert capture.shutter.current == 550
assert capture.gain.current == 3.0
assert math.isclose(capture.shutter.current, 550)
assert math.isclose(capture.gain.current, 3.0, rel_tol=0.5)

0 comments on commit 5227153

Please sign in to comment.