add tests

This commit is contained in:
Joe Eacott 2020-05-06 15:33:13 -06:00 committed by Daniel Wozniak
parent 6b9c3faf11
commit d2688ae80e
2 changed files with 44 additions and 7 deletions

View file

@ -148,10 +148,9 @@ def _check_bundled():
"""
Gather run-time information to indicate if we are running from source or bundled.
"""
frozen = False
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
frozen = True
return frozen
return True
return False
def _get_pip_bin(bin_env):

View file

@ -38,10 +38,48 @@ class PipTestCase(TestCase, LoaderModuleMockMixin):
ret = pip._pip_bin_env(None, None)
self.assertIsNone(ret)
def test__pip_bin_bundled_app(self):
sys_info = hasattr(sys, "sys._MEIPASS")
ret = pip._check_bundled()
self.assertEqual(ret, sys_info)
def test_install_frozen_app(self):
pkg = "pep8"
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch("sys.frozen", True, create=True):
with patch("sys._MEIPASS", True, create=True):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg)
expected = [
sys.executable,
"pip",
"install",
pkg,
]
mock.assert_called_with(
expected,
python_shell=False,
saltenv="base",
use_vt=False,
runas=None,
)
def test_install_source_app(self):
pkg = "pep8"
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
with patch("sys.frozen", False, create=True):
with patch("sys._MEIPASS", False, create=True):
with patch.dict(pip.__salt__, {"cmd.run_all": mock}):
pip.install(pkg)
expected = [
sys.executable,
"-m",
"pip",
"install",
pkg,
]
mock.assert_called_with(
expected,
python_shell=False,
saltenv="base",
use_vt=False,
runas=None,
)
def test_fix4361(self):
mock = MagicMock(return_value={"retcode": 0, "stdout": ""})