From 229fa2ae293e54802d4f0024477df823a115ba67 Mon Sep 17 00:00:00 2001 From: Muhammad Umair Shahid <58398786+Umair0343@users.noreply.github.com> Date: Fri, 10 May 2024 09:31:03 +0500 Subject: [PATCH 1/3] Update test.py Added test cases --- tests/test_diff_motion_detector/test.py | 40 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/tests/test_diff_motion_detector/test.py b/tests/test_diff_motion_detector/test.py index e468af8..063bfb0 100644 --- a/tests/test_diff_motion_detector/test.py +++ b/tests/test_diff_motion_detector/test.py @@ -2,14 +2,50 @@ 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() + background_image = cv2.imread('background.jpg') + foreground_image = cv2.imread('foreground.jpg') + detector.setBackground(background_image) + binary_image = detector.returnMask(foreground_image) + assert binary_image is not None + + # 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 and binary_image is not None + + # 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 From 34401c7e4892532a522497f3c8854b9e48c769ed Mon Sep 17 00:00:00 2001 From: Muhammad Umair Shahid <58398786+Umair0343@users.noreply.github.com> Date: Fri, 10 May 2024 09:44:07 +0500 Subject: [PATCH 2/3] Update tests/test_diff_motion_detector/test.py Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com> --- tests/test_diff_motion_detector/test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_diff_motion_detector/test.py b/tests/test_diff_motion_detector/test.py index 063bfb0..8ac8793 100644 --- a/tests/test_diff_motion_detector/test.py +++ b/tests/test_diff_motion_detector/test.py @@ -28,7 +28,9 @@ def test_set_background_and_return_binary_image_successfully(self): foreground_image = cv2.imread('foreground.jpg') detector.setBackground(background_image) binary_image = detector.returnMask(foreground_image) - assert detector.getBackground() is not None and binary_image is not None + 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): From 7af0b721ecaca44c3e334bba8e60c89e3debfd82 Mon Sep 17 00:00:00 2001 From: Muhammad Umair Shahid <58398786+Umair0343@users.noreply.github.com> Date: Fri, 10 May 2024 10:51:19 +0500 Subject: [PATCH 3/3] Update tests/test_diff_motion_detector/test.py Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com> --- tests/test_diff_motion_detector/test.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_diff_motion_detector/test.py b/tests/test_diff_motion_detector/test.py index 8ac8793..00a5448 100644 --- a/tests/test_diff_motion_detector/test.py +++ b/tests/test_diff_motion_detector/test.py @@ -15,8 +15,18 @@ def test_set_background_successfully(self): # Tests that a binary image is returned successfully after the detection process def test_return_binary_image_successfully(self): detector = DiffMotionDetector() - background_image = cv2.imread('background.jpg') - foreground_image = cv2.imread('foreground.jpg') + @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