@@ -1101,7 +1101,6 @@ def test_install_extra_args_arguments_recursion_error():
11011101 pkg = "pep8"
11021102 mock = MagicMock (return_value = {"retcode" : 0 , "stdout" : "" })
11031103 with patch .dict (pip .__salt__ , {"cmd.run_all" : mock }):
1104-
11051104 pytest .raises (
11061105 TypeError ,
11071106 lambda : pip .install (
@@ -1522,7 +1521,7 @@ def test_list_upgrades_gt9(python_binary):
15221521 {"latest_filetype": "wheel", "version": "1.4.1", "name": "appdirs", "latest_version": "1.4.3"},
15231522 {"latest_filetype": "sdist", "version": "1.11.63", "name": "awscli", "latest_version": "1.12.1"}
15241523 ]"""
1525- mock = MagicMock (return_value = {"retcode" : 0 , "stdout" : "{}" . format ( eggs ) })
1524+ mock = MagicMock (return_value = {"retcode" : 0 , "stdout" : f" { eggs } " })
15261525 with patch .dict (pip .__salt__ , {"cmd.run_all" : mock }):
15271526 with patch ("salt.modules.pip.version" , MagicMock (return_value = "9.1.1" )):
15281527 ret = pip .list_upgrades ()
@@ -1738,28 +1737,44 @@ def test_when_version_is_called_with_a_user_it_should_be_passed_to_undelying_run
17381737 )
17391738
17401739
1741- def test_install_target_from_VENV_PIP_TARGET_in_resulting_command (python_binary ):
1740+ @pytest .mark .parametrize (
1741+ "bin_env,target,target_env,expected_target" ,
1742+ [
1743+ (None , None , None , None ),
1744+ (None , "/tmp/foo" , None , "/tmp/foo" ),
1745+ (None , None , "/tmp/bar" , "/tmp/bar" ),
1746+ (None , "/tmp/foo" , "/tmp/bar" , "/tmp/foo" ),
1747+ ("/tmp/venv" , "/tmp/foo" , None , "/tmp/foo" ),
1748+ ("/tmp/venv" , None , "/tmp/bar" , None ),
1749+ ("/tmp/venv" , "/tmp/foo" , "/tmp/bar" , "/tmp/foo" ),
1750+ ],
1751+ )
1752+ def test_install_target_from_VENV_PIP_TARGET_in_resulting_command (
1753+ python_binary , bin_env , target , target_env , expected_target
1754+ ):
17421755 pkg = "pep8"
1743- target = "/tmp/foo"
1744- target_env = "/tmp/bar"
17451756 mock = MagicMock (return_value = {"retcode" : 0 , "stdout" : "" })
17461757 environment = os .environ .copy ()
1747- environment ["VENV_PIP_TARGET" ] = target_env
1758+ real_get_pip_bin = pip ._get_pip_bin
1759+
1760+ def mock_get_pip_bin (bin_env ):
1761+ if not bin_env :
1762+ return real_get_pip_bin (bin_env )
1763+ return [f"{ bin_env } /bin/pip" ]
1764+
1765+ if target_env is not None :
1766+ environment ["VENV_PIP_TARGET" ] = target_env
17481767 with patch .dict (pip .__salt__ , {"cmd.run_all" : mock }), patch .object (
17491768 os , "environ" , environment
1750- ):
1751- pip .install (pkg )
1752- expected = [* python_binary , "install" , "--target" , target_env , pkg ]
1753- mock .assert_called_with (
1754- expected ,
1755- saltenv = "base" ,
1756- runas = None ,
1757- use_vt = False ,
1758- python_shell = False ,
1759- )
1760- mock .reset_mock ()
1761- pip .install (pkg , target = target )
1762- expected = [* python_binary , "install" , "--target" , target , pkg ]
1769+ ), patch .object (pip , "_get_pip_bin" , mock_get_pip_bin ):
1770+ pip .install (pkg , bin_env = bin_env , target = target )
1771+ expected_binary = python_binary
1772+ if bin_env is not None :
1773+ expected_binary = [f"{ bin_env } /bin/pip" ]
1774+ if expected_target is not None :
1775+ expected = [* expected_binary , "install" , "--target" , expected_target , pkg ]
1776+ else :
1777+ expected = [* expected_binary , "install" , pkg ]
17631778 mock .assert_called_with (
17641779 expected ,
17651780 saltenv = "base" ,
0 commit comments