Skip to content

Commit

Permalink
test_locate_tools: Make test_FindInf2CatToolInWinSdk() results consis…
Browse files Browse the repository at this point in the history
…tent (#647)

Currently, this function depends on finding the actual inf2cat.exe
tool which is dependent on the user's system. Instead mock the
dependencies so the function logic is excercised but with consistent
dependency values.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki authored Oct 1, 2024
1 parent 44bb090 commit 2b0527b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tests.unit/test_locate_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import os
import edk2toollib.windows.locate_tools as locate_tools
from unittest.mock import patch


class LocateToolsTest(unittest.TestCase):
Expand Down Expand Up @@ -70,10 +71,16 @@ def test_QueryVcVariables(self):
self.assertIsNotNone(results["WindowsSDKVersion"])

@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_FindInf2CatToolInWinSdk(self):
@patch("edk2toollib.windows.locate_tools.QueryVcVariables")
@patch("glob.iglob")
def test_FindInf2CatToolInWinSdk(self, mock_iglob, mock_QueryVcVariables):
# Mock dependencies to otherwise exercise the `FindToolInWinSdk`
# function
mock_QueryVcVariables.return_value = {"WindowsSdkDir": "C:/mock/sdk/dir", "WindowsSDKVersion": "10.0.12345.0"}
mock_iglob.return_value = ["C:/mock/sdk/dir/10.0.12345.0/bin/x64/inf2cat.exe"]

results = locate_tools.FindToolInWinSdk("inf2cat.exe")
self.assertIsNotNone(results)
self.assertTrue(os.path.isfile(results))

@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_FindToolInWinSdk(self):
Expand Down

0 comments on commit 2b0527b

Please sign in to comment.