From 9d8f1c331da5807ec90c441a67effb07458e422a Mon Sep 17 00:00:00 2001 From: anetla Date: Tue, 28 Nov 2023 18:46:35 +0100 Subject: [PATCH] add testing file with mock tests --- testy_jednostkowe.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 testy_jednostkowe.py diff --git a/testy_jednostkowe.py b/testy_jednostkowe.py new file mode 100644 index 0000000..3870b38 --- /dev/null +++ b/testy_jednostkowe.py @@ -0,0 +1,32 @@ +import unittest +from unittest.mock import patch +from detect_module import TomatoDetector + +class TestTomatoDetection(unittest.TestCase): + @patch('detect_module.TomatoDetector.image_contains_tomato') + def test_no_tomato_mock(self, mock_image_contains_tomato): + # Test the app's ability to correctly identify images without tomatoes using a mock + + # Configure the mock to return False, simulating the absence of a tomato + mock_image_contains_tomato.return_value = False + + # Create an instance of TomatoDetector + tomato_detector = TomatoDetector() + + # Call the detect_tomato method, which internally calls the mocked image_contains_tomato + result = tomato_detector.detect_tomato('path_to_no_tomato_image.jpg') + + # Ensure the app correctly identifies that there is no tomato using the mocked method + self.assertFalse(result, "No tomato should be detected in the image") + + def test_invalid_photo_file(self): + + # Test the model ability to identify if a file is a photo or not + + # Provide an file that is not a photo + image_path = 'path_to_no_tomato_image.txt' + + self.assertFalse(show_image(image_path), "It should be returned that this file is not an image") + +if __name__ == '__main__': + unittest.main() \ No newline at end of file