Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix base provider's unit tests (BugFix) #1216

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 3 additions & 7 deletions providers/base/bin/prime_offload_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,13 @@ def get_clients(self, card_id: str) -> str:
)

def check_offload(
self, cmd: list, card_id: str, card_name: str, timeout: str
self, cmd: list, card_id: str, card_name: str, timeout: int
):
"""
Use to check provided command is executed on specific GPU.

:param cmd: command that running under prime offload

Check provided command is executed on specific GPU.
:param cmd: command to check if it's running on specific GPU
:param card_id: card id of dri device

:param card_name: card name of dri device

:param timeout: timeout for offloaded command
"""
delay = timeout / 10
Expand Down
2 changes: 1 addition & 1 deletion providers/base/tests/test_cpuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class CpuidTests(unittest.TestCase):
def test_hygon_dhyana_plus(self):
self.assertEquals(
self.assertEqual(
cpuid_to_human_friendly("0x900f22"), "Hygon Dhyana Plus"
)

Expand Down
2 changes: 0 additions & 2 deletions providers/base/tests/test_get_firmware_info_fwupd.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ def test_get_firmware_data_by_fwupd_deb_on_checkbox_deb(
mock_snapd.return_value = False
mock_fwupd_ver.return_value = (1, 7, 9)

# SNAP env is empty
self.assertIsNone(os.environ.get("SNAP"))
get_firmware_info_fwupd.get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
Expand Down
11 changes: 10 additions & 1 deletion providers/base/tests/test_led_control_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import unittest
from datetime import datetime
from unittest.mock import patch, Mock
from pathlib import PosixPath, Path
from led_control_test import SysFsLEDController
Expand Down Expand Up @@ -132,9 +133,17 @@ def test_get_initial_state(self, mock_read):
self.led_controller._get_initial_state()
self.assertEqual(expected_data, self.led_controller.initial_state)

@patch("time.sleep", return_value=0)
@patch("led_control_test.datetime")
@patch("led_control_test.SysFsLEDController.off")
@patch("led_control_test.SysFsLEDController.on")
def test_blinking_test(self, mock_on, mock_off):
def test_blinking_test(self, mock_on, mock_off, mock_datetime, mock_sleep):
mock_datetime.now = Mock()
mock_datetime.now.side_effect = [
datetime(2020, 1, 1, 0, 0, 0),
datetime(2020, 1, 1, 0, 0, 1),
datetime(2020, 1, 1, 0, 0, 2),
]

self.led_controller.blinking(1, 0.5)
mock_on.assert_called_with()
Expand Down
3 changes: 2 additions & 1 deletion providers/base/tests/test_prime_offload_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ def test_offload_succ_check(self, mock_client, mock_sleep):
)
self.assertEqual(po.check_result, False)

@patch("time.time", side_effect=[1, 2, 3, 4])
@patch("time.sleep", return_value=None)
@patch("prime_offload_tester.PrimeOffloader.get_clients")
def test_offload_fail_check(self, mock_client, mock_sleep):
def test_offload_fail_check(self, mock_client, mock_sleep, mock_time):
cmd = ["echo"]
# get_clients return string that doesn't include cmd
mock_client.return_value = ""
Expand Down
Loading