Skip to content

Commit

Permalink
Mocked print and log functions for tests (Infra) (#827)
Browse files Browse the repository at this point in the history
Mocked print and log functions for tests

Replaced print and log functions for mocks for the tests in the
base provider
  • Loading branch information
fernando79513 authored Nov 16, 2023
1 parent a4f3f2a commit 1c854ed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion providers/base/tests/test_camera_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pathlib import Path
import time
import unittest
from unittest.mock import patch
from unittest.mock import patch, MagicMock

import cv2

Expand All @@ -38,6 +38,7 @@

@patch("bin.camera_quality_test.TIMEOUT", new=0.05)
@patch("bin.camera_quality_test.MIN_INTERVAL", new=0.01)
@patch("builtins.print", new=MagicMock())
class CameraQualityTests(unittest.TestCase):
"""This class provides test cases for the camera_quality_test module."""

Expand Down Expand Up @@ -78,6 +79,7 @@ def test_get_score_from_device(self, mock_score):
self.assertEqual(result, 0)
mock_score.assert_called_with("video0", True)

@patch("logging.Logger.error", new=MagicMock())
def test_quality_evaluation(self):
"""
The test should pass if the image is good and fails if it has bad
Expand Down
7 changes: 2 additions & 5 deletions providers/base/tests/test_camera_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,15 @@
import unittest
import io
import sys
from unittest.mock import patch
from unittest.mock import patch, MagicMock

from camera_test import CameraTest, v4l2_capability


@patch("builtins.print", new=MagicMock())
class CameraTestTests(unittest.TestCase):
"""This class provides test cases for the CameraTest class."""
def setUp(self):
# supress stdout to hide print message
suppress_text = io.StringIO()
sys.stdout = suppress_text

self.camera_instance = CameraTest(None)

@patch('camera_test.CameraTest._supported_resolutions_to_string')
Expand Down
3 changes: 3 additions & 0 deletions providers/base/tests/test_dkms_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import io
import unittest
from unittest import mock
from unittest.mock import patch, MagicMock

import dkms_info


@patch("logging.Logger.info", new=MagicMock())
class SystemInfoTests(unittest.TestCase):

"""Tests for System Information Parsing and Collection."""
Expand Down Expand Up @@ -118,6 +120,7 @@ def test_match_patterns(self, mock_get_system_modaliases):
matched_modalieses)


@patch("logging.Logger.info", new=MagicMock())
class DebianPackageHandlerTest(unittest.TestCase):

"""Test of DebianPackageHandler."""
Expand Down
3 changes: 2 additions & 1 deletion providers/base/tests/test_recovery_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import unittest
from unittest import mock
from unittest.mock import patch
from unittest.mock import patch, MagicMock
import sys

import recovery_info
Expand Down Expand Up @@ -96,6 +96,7 @@ def test_with_of_MountedPartition(self, mock_subprocess_check_output):
universal_newlines=True)])


@patch("builtins.print", new=MagicMock())
class RecoveryInfoTests(unittest.TestCase):

"""Tests for RecoveryInfo."""
Expand Down

0 comments on commit 1c854ed

Please sign in to comment.