add testing file with mock tests

This commit is contained in:
anetla 2023-11-28 18:46:35 +01:00
parent 086c2379cd
commit 9d8f1c331d
1 changed files with 32 additions and 0 deletions

32
testy_jednostkowe.py Normal file
View File

@ -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()