From e44f74352c53dc2158f14e8f42acd7f4237cd455 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Mon, 30 Sep 2024 18:51:22 -0400 Subject: [PATCH] test_locate_tools: Make test_FindInf2CatToolInWinSdk() results consistent 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 --- tests.unit/test_locate_tools.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests.unit/test_locate_tools.py b/tests.unit/test_locate_tools.py index b68bfc86..81298c38 100644 --- a/tests.unit/test_locate_tools.py +++ b/tests.unit/test_locate_tools.py @@ -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): @@ -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):