Merge pull request #43123 from twangboy/win_fix_test_which

Fix `unit.utils.test_which` for Windows
This commit is contained in:
Mike Place 2017-08-23 10:01:38 -06:00 committed by GitHub
commit 03f652159f

View File

@ -44,18 +44,21 @@ class TestWhich(TestCase):
# The second, iterating through $PATH, should also return False, # The second, iterating through $PATH, should also return False,
# still checking for Linux # still checking for Linux
False, False,
# We will now also return False once so we get a .EXE back from
# the function, see PATHEXT below.
False,
# Lastly return True, this is the windows check. # Lastly return True, this is the windows check.
True True
] ]
# Let's patch os.environ to provide a custom PATH variable # Let's patch os.environ to provide a custom PATH variable
with patch.dict(os.environ, {'PATH': '/bin'}): with patch.dict(os.environ, {'PATH': '/bin',
'PATHEXT': '.COM;.EXE;.BAT;.CMD'}):
# Let's also patch is_windows to return True # Let's also patch is_windows to return True
with patch('salt.utils.is_windows', lambda: True): with patch('salt.utils.is_windows', lambda: True):
with patch('os.path.isfile', lambda x: True): with patch('os.path.isfile', lambda x: True):
self.assertEqual( self.assertEqual(
salt.utils.which('this-binary-exists-under-windows'), salt.utils.which('this-binary-exists-under-windows'),
# The returned path should return the .exe suffix os.path.join('/bin', 'this-binary-exists-under-windows.EXE')
'/bin/this-binary-exists-under-windows.EXE'
) )
def test_missing_binary_in_windows(self): def test_missing_binary_in_windows(self):
@ -106,6 +109,5 @@ class TestWhich(TestCase):
with patch('os.path.isfile', lambda x: True): with patch('os.path.isfile', lambda x: True):
self.assertEqual( self.assertEqual(
salt.utils.which('this-binary-exists-under-windows'), salt.utils.which('this-binary-exists-under-windows'),
# The returned path should return the .exe suffix os.path.join('/bin', 'this-binary-exists-under-windows.CMD')
'/bin/this-binary-exists-under-windows.CMD'
) )