Skip to content

Commit

Permalink
Try to fix the unit test issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-yujinwu committed Jan 21, 2025
1 parent c6728c8 commit 95d33ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 8 additions & 4 deletions providers/base/tests/test_wol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import unittest
from unittest.mock import patch, MagicMock, mock_open
import subprocess
import netifaces
import requests
from wol_client import (
request,
Expand Down Expand Up @@ -129,9 +128,12 @@ class TestGetIpMacFunction(unittest.TestCase):
@patch("wol_client.netifaces.ifaddresses")
def test_get_ip_mac_success(self, mock_ifaddresses):
# Mock the return value of netifaces.ifaddresses
AF_LINK = 17 # netifaces.AF_LINK
AF_INET = 2 # netifaces.AF_INET

mock_ifaddresses.return_value = {
netifaces.AF_LINK: [{"addr": "00:11:22:33:44:55"}],
netifaces.AF_INET: [{"addr": "192.168.1.10"}],
AF_LINK: [{"addr": "00:11:22:33:44:55"}],
AF_INET: [{"addr": "192.168.1.10"}],
}

ip, mac = get_ip_mac("eth0")
Expand All @@ -142,9 +144,11 @@ def test_get_ip_mac_success(self, mock_ifaddresses):
@patch("wol_client.netifaces.ifaddresses")
def test_get_ip_mac_no_ip(self, mock_ifaddresses):
# Mock the return value of netifaces.ifaddresses (no AF_INET)
AF_LINK = 17

mock_ifaddresses.return_value = {
netifaces.AF_LINK: [{"addr": "00:11:22:33:44:55"}],
# No AF_INET key to simulate no IP address
AF_LINK: [{"addr": "00:11:22:33:44:55"}],
}

ip, mac = get_ip_mac("eth0")
Expand Down
4 changes: 4 additions & 0 deletions providers/base/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ deps =
pyparsing == 2.0.3
PyYAML == 3.11
XlsxWriter == 0.7.3
fastapi == 0.65.2
setenv=
# we do not care about the package version in tox
# but it breaks some old python3.5 builds
Expand All @@ -56,6 +57,7 @@ deps =
pyparsing == 2.2.0
PyYAML == 3.12
XlsxWriter == 0.9.6
fastapi == 0.65.2

[testenv:py38]
deps =
Expand All @@ -73,6 +75,7 @@ deps =
pyparsing == 2.4.6
PyYAML == 5.3.1
XlsxWriter == 1.1.2
fastapi == 0.74.1

[testenv:py310]
deps =
Expand All @@ -91,3 +94,4 @@ deps =
pyparsing == 2.4.7
PyYAML == 6.0.1
XlsxWriter == 3.0.2
fastapi == 0.85.0

0 comments on commit 95d33ee

Please sign in to comment.