Skip to content
Open
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
52 changes: 50 additions & 2 deletions tests/test_diff_motion_detector/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,62 @@
from deepgaze.deepgaze.motion_detection import DiffMotionDetector
import cv2


import pytest

class TestDiffMotionDetector:

# Tests that the background image is set successfully
def test_set_background_successfully(self):
detector = DiffMotionDetector()
background_image = cv2.imread('background.jpg')
detector.setBackground(background_image)
assert detector.getBackground() is not None

# Tests that a binary image is returned successfully after the detection process
def test_return_binary_image_successfully(self):
detector = DiffMotionDetector()
@pytest.fixture(scope="module")
def loaded_images():
background_image = cv2.imread('background.jpg')
foreground_image = cv2.imread('foreground.jpg')
return background_image, foreground_image

def test_return_binary_image_successfully(self, loaded_images):
detector = DiffMotionDetector()
background_image, foreground_image = loaded_images
detector.setBackground(background_image)
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None
detector.setBackground(background_image)
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To further ensure robustness, you might add assertions to check specific properties of the binary_image such as its type or shape, ensuring it meets expected criteria after processing. [medium]

Comment on lines +31 to +32

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: To ensure the test is robust, explicitly check the contents of the binary image rather than just its existence. This helps verify that the function returnMask is processing the images correctly and not just returning a non-None default value. [enhancement]

Suggested change
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None and binary_image.any(), "Binary image should contain true values"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To further ensure the robustness of the tests, consider adding assertions to check the type and content of the binary image in test_return_binary_image_successfully. This will help confirm that the function not only returns a non-None value but also returns a valid binary image. [medium]

Comment on lines +31 to +32

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: To ensure that the tests are robust, include assertions to check the content of the binary image, not just its existence. This helps in verifying that the function returnMask is not only returning a non-null value but is also performing the expected operations correctly. [enhancement]

Suggested change
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None
binary_image = detector.returnMask(foreground_image)
assert binary_image is not None
assert np.any(binary_image), "Binary image should contain non-zero values"


# Tests that a background image is set and a binary image is returned successfully after the detection process
def test_set_background_and_return_binary_image_successfully(self):
detector = DiffMotionDetector()
background_image = cv2.imread('background.jpg')
foreground_image = cv2.imread('foreground.jpg')
detector.setBackground(background_image)
binary_image = detector.returnMask(foreground_image)
assert detector.getBackground() is not None, "Background should be set"
assert binary_image is not None, "Binary image should be generated"
assert binary_image.shape == foreground_image.shape, "Binary image should match the shape of the foreground image"

# Tests that setting a None background image returns None
def test_set_none_background_image_and_return_none(self):
detector = DiffMotionDetector()
detector.setBackground(None)
assert detector.getBackground() is None

# Tests that setting a None foreground image returns None
def test_set_none_foreground_image_and_return_none(self):
detector = DiffMotionDetector()
background_image = cv2.imread('background.jpg')
detector.setBackground(background_image)
binary_image = detector.returnMask(None)
assert binary_image is None

# Tests that setting a None background image returns None after the detection process
def test_set_none_background_image_and_return_none_after_detection_process(self):
detector = DiffMotionDetector()
detector.setBackground(None)
assert detector.getBackground() is None