Beispiel #1
0
    def test_get_virtualenv_version_from_shell(self):
        with ForceImportErrorOn('virtualenv'):

            # ----- virtualenv binary not available ------------------------->
            mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    '/tmp/foo',
                )
            # <---- virtualenv binary not available --------------------------

            # ----- virtualenv binary present but > 0 exit code ------------->
            mock = MagicMock(side_effect=[{
                'retcode': 1,
                'stdout': '',
                'stderr': 'This is an error'
            }, {
                'retcode': 0,
                'stdout': ''
            }])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    '/tmp/foo',
                    venv_bin='virtualenv',
                )
            # <---- virtualenv binary present but > 0 exit code --------------

            # ----- virtualenv binary returns 1.9.1 as its version --------->
            mock = MagicMock(side_effect=[{
                'retcode': 0,
                'stdout': '1.9.1'
            }, {
                'retcode': 0,
                'stdout': ''
            }])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                virtualenv_mod.create('/tmp/foo', never_download=True)
                mock.assert_called_with(
                    ['virtualenv', '--never-download', '/tmp/foo'],
                    runas=None,
                    python_shell=False)
            # <---- virtualenv binary returns 1.9.1 as its version ----------

            # ----- virtualenv binary returns 1.10rc1 as its version ------->
            mock = MagicMock(side_effect=[{
                'retcode': 0,
                'stdout': '1.10rc1'
            }, {
                'retcode': 0,
                'stdout': ''
            }])
            with patch.dict(virtualenv_mod.__salt__, {'cmd.run_all': mock}):
                virtualenv_mod.create('/tmp/foo', never_download=True)
                mock.assert_called_with(['virtualenv', '/tmp/foo'],
                                        runas=None,
                                        python_shell=False)
 def test_virtualenv_importerror_ver_output(self):
     """
     test virtualenv_ver when there is an ImportError
     and virtualenv --version returns the various
     --versions outputs
     """
     stdout = (
         ("1.9.2", (1, 9, 2)),
         ("1.9rc2", (1, 9)),
         (
             "virtualenv 20.0.0 from /home/ch3ll/.pyenv/versions/3.6.4/envs/virtualenv/lib/python3.6/site-packages/virtualenv/__init__.py",
             (20, 0, 0),
         ),
         ("16.7.10", (16, 7, 10)),
     )
     for stdout, expt in stdout:
         with ForceImportErrorOn("virtualenv"):
             mock_ver = MagicMock(return_value={
                 "retcode": 0,
                 "stdout": stdout
             })
             with patch.dict(virtualenv_mod.__salt__,
                             {"cmd.run_all": mock_ver}):
                 ret = virtualenv_mod.virtualenv_ver(venv_bin="pyenv")
                 assert ret == expt
Beispiel #3
0
 def test_virtualenv_ver_importerror_cmd_error(self):
     """
     test virtualenv_ver when there is an ImportError
     and virtualenv --version does not return anything
     """
     with ForceImportErrorOn("virtualenv"):
         mock_ver = MagicMock(return_value={"retcode": 0, "stdout": ""})
         with patch.dict(virtualenv_mod.__salt__,
                         {"cmd.run_all": mock_ver}):
             with self.assertRaises(CommandExecutionError):
                 virtualenv_mod.virtualenv_ver(venv_bin="pyenv")
Beispiel #4
0
 def test_virtualenv_ver_importerror_cmd_error(self):
     '''
     test virtualenv_ver when there is an ImportError
     and virtualenv --version does not return anything
     '''
     with ForceImportErrorOn('virtualenv'):
         mock_ver = MagicMock(return_value={'retcode': 0, 'stdout': ''})
         with patch.dict(virtualenv_mod.__salt__,
                         {'cmd.run_all': mock_ver}):
             with self.assertRaises(CommandExecutionError):
                 virtualenv_mod.virtualenv_ver(venv_bin='pyenv')
Beispiel #5
0
 def test_virtualenv_ver_importerror(self):
     """
     test virtualenv_ver when there is an ImportError
     """
     with ForceImportErrorOn("virtualenv"):
         mock_ver = MagicMock(return_value={
             "retcode": 0,
             "stdout": "1.9.1"
         })
         with patch.dict(virtualenv_mod.__salt__,
                         {"cmd.run_all": mock_ver}):
             ret = virtualenv_mod.virtualenv_ver(venv_bin="pyenv")
     assert ret == (1, 9, 1)
Beispiel #6
0
 def test_virtualenv_ver_importerror(self):
     '''
     test virtualenv_ver when there is an ImportError
     '''
     with ForceImportErrorOn('virtualenv'):
         mock_ver = MagicMock(return_value={
             'retcode': 0,
             'stdout': '1.9.1'
         })
         with patch.dict(virtualenv_mod.__salt__,
                         {'cmd.run_all': mock_ver}):
             ret = virtualenv_mod.virtualenv_ver(venv_bin='pyenv')
     assert ret == (1, 9, 1)
 def test_issue_57734_debian_package_importerror(self):
     with ForceImportErrorOn("virtualenv"):
         mock_ver = MagicMock(
             return_value={
                 "retcode":
                 0,
                 "stdout":
                 ("virtualenv 20.0.23+ds from "
                  "/usr/lib/python3/dist-packages/virtualenv/__init__.py"),
             })
         with patch.dict(virtualenv_mod.__salt__,
                         {"cmd.run_all": mock_ver}):
             ret = virtualenv_mod.virtualenv_ver(venv_bin="pyenv")
     self.assertEqual(ret, (20, 0, 23))
Beispiel #8
0
    def test_get_virtualenv_version_from_shell(self):
        with ForceImportErrorOn("virtualenv"):

            # ----- virtualenv binary not available ------------------------->
            mock = MagicMock(return_value={"retcode": 0, "stdout": ""})
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    "/tmp/foo",
                )
            # <---- virtualenv binary not available --------------------------

            # ----- virtualenv binary present but > 0 exit code ------------->
            mock = MagicMock(side_effect=[
                {
                    "retcode": 1,
                    "stdout": "",
                    "stderr": "This is an error"
                },
                {
                    "retcode": 0,
                    "stdout": ""
                },
            ])
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                self.assertRaises(
                    CommandExecutionError,
                    virtualenv_mod.create,
                    "/tmp/foo",
                    venv_bin="virtualenv",
                )
            # <---- virtualenv binary present but > 0 exit code --------------

            # ----- virtualenv binary returns 1.9.1 as its version --------->
            mock = MagicMock(side_effect=[
                {
                    "retcode": 0,
                    "stdout": "1.9.1"
                },
                {
                    "retcode": 0,
                    "stdout": ""
                },
            ])
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                virtualenv_mod.create("/tmp/foo", never_download=True)
                mock.assert_called_with(
                    ["virtualenv", "--never-download", "/tmp/foo"],
                    runas=None,
                    python_shell=False,
                )
            # <---- virtualenv binary returns 1.9.1 as its version ----------

            # ----- virtualenv binary returns 1.10rc1 as its version ------->
            mock = MagicMock(side_effect=[
                {
                    "retcode": 0,
                    "stdout": "1.10rc1"
                },
                {
                    "retcode": 0,
                    "stdout": ""
                },
            ])
            with patch.dict(virtualenv_mod.__salt__, {"cmd.run_all": mock}):
                virtualenv_mod.create("/tmp/foo", never_download=True)
                mock.assert_called_with(["virtualenv", "/tmp/foo"],
                                        runas=None,
                                        python_shell=False)