Ejemplo n.º 1
0
    def test_destroy_venv(self):
        builder = envbuilder._FadesEnvBuilder()
        # make sure the virtualenv exists on disk
        options = {"virtualenv_options": [],
                   "pyvenv_options": ['--system-site-packages'],
                   "pip-options": [],
                   }

        def fake_create(*_):
            """Fake venv create.

            This is for the test to avoid network usage on venv creation, but also create
            and set the fake dir.
            """
            os.mkdir(fake_venv_path)
            builder.env_path = fake_venv_path

        fake_venv_path = tempfile.TemporaryDirectory().name
        builder.create_with_virtualenv = fake_create
        builder.create_env('python', False, options=options)
        assert os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 2
0
    def test_destroy_venv(self):
        builder = envbuilder._FadesEnvBuilder()
        # make sure the virtualenv exists on disk
        options = {
            "virtualenv_options": [],
            "pyvenv_options": ['--system-site-packages'],
            "pip-options": [],
        }

        def fake_create(*_):
            """Fake venv create.

            This is for the test to avoid network usage on venv creation, but also create
            and set the fake dir.
            """
            os.mkdir(fake_venv_path)
            builder.env_path = fake_venv_path

        fake_venv_path = tempfile.TemporaryDirectory().name
        builder.create_with_virtualenv = fake_create
        builder.create_env('python', False, options=options)
        assert os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 3
0
    def test_destroy_venv_if_env_path_not_found(self):
        builder = envbuilder._FadesEnvBuilder()
        assert not os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 4
0
    def test_destroy_venv_if_env_path_not_found(self):
        builder = envbuilder._FadesEnvBuilder()
        assert not os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 5
0
 def test_create_virtualenv(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'pythonX.Y'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": [],
                }
     with patch.object(envbuilder._FadesEnvBuilder, 'create_with_virtualenv') as mock_create:
             env_builder.create_env(interpreter, is_current, options)
             mock_create.assert_called_with(interpreter, options['virtualenv_options'])
Ejemplo n.º 6
0
 def test_create_virtualenv(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'pythonX.Y'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": [],
                }
     with patch.object(envbuilder._FadesEnvBuilder, 'create_with_virtualenv') as mock_create:
             env_builder.create_env(interpreter, is_current, options)
             mock_create.assert_called_with(interpreter, options['virtualenv_options'])
Ejemplo n.º 7
0
 def test_create_pyvenv(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = True
     options = {"virtualenv_options": [],
                "pyvenv_options": [],
                }
     with patch.object(EnvBuilder, 'create') as mock_create:
             env_builder.create_env(interpreter, is_current, options)
             self.assertFalse(env_builder.system_site_packages)
             self.assertTrue(mock_create.called)
Ejemplo n.º 8
0
 def test_create_pyvenv(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = True
     options = {"virtualenv_options": [],
                "pyvenv_options": [],
                }
     with patch.object(EnvBuilder, 'create') as mock_create:
             env_builder.create_env(interpreter, is_current, options)
             self.assertFalse(env_builder.system_site_packages)
             self.assertTrue(mock_create.called)
Ejemplo n.º 9
0
 def test_executionerror_exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": ['--system-site-packages'],
                }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
             mock_lexec.side_effect = envbuilder.helpers.ExecutionError(1, 'cmd', ['stdout'])
             with self.assertRaises(FadesError) as cm:
                 env_builder.create_env(interpreter, is_current, options)
             self.assertEqual(str(cm.exception), 'virtualenv could not be run')
Ejemplo n.º 10
0
 def test_exit_3_on_any_Exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": ['--system-site-packages'],
                }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
             mock_lexec.side_effect = Exception()
             with self.assertRaises(SystemExit) as cm:
                 env_builder.create_env(interpreter, is_current, options)
             self.assertEqual(cm.exception.code, 3)
Ejemplo n.º 11
0
 def test_general_error_exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": ['--system-site-packages'],
                }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
             mock_lexec.side_effect = Exception()
             with self.assertRaises(FadesError) as cm:
                 env_builder.create_env(interpreter, is_current, options)
             self.assertEqual(str(cm.exception), 'General error while running virtualenv')
Ejemplo n.º 12
0
 def test_filenotfound_exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": ['--system-site-packages'],
                }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
             # mock_lexec.side_effect = envbuilder.helpers.ExecutionError('matanga!')
             mock_lexec.side_effect = FileNotFoundError('matanga!')
             with self.assertRaises(FadesError) as cm:
                 env_builder.create_env(interpreter, is_current, options)
             self.assertEqual(str(cm.exception), 'virtualenv not found')
Ejemplo n.º 13
0
 def test_exit_1_on_FileNotFound(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {"virtualenv_options": [],
                "pyvenv_options": ['--system-site-packages'],
                }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
             # mock_lexec.side_effect = envbuilder.helpers.ExecutionError('matanga!')
             mock_lexec.side_effect = FileNotFoundError('matanga!')
             with self.assertRaises(SystemExit) as cm:
                 env_builder.create_env(interpreter, is_current, options)
             self.assertEqual(cm.exception.code, 1)
Ejemplo n.º 14
0
 def test_general_error_exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {
         "virtualenv_options": [],
         "pyvenv_options": ['--system-site-packages'],
     }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
         mock_lexec.side_effect = Exception()
         with self.assertRaises(FadesError) as cm:
             env_builder.create_env(interpreter, is_current, options)
         self.assertEqual(str(cm.exception),
                          'General error while running virtualenv')
Ejemplo n.º 15
0
    def test_destroy_venv(self):
        builder = envbuilder._FadesEnvBuilder()
        # make sure the virtualenv exists on disk
        options = {"virtualenv_options": [],
                   "pyvenv_options": ['--system-site-packages'],
                   "pip-options": [],
                   }
        builder.create_env('python', False, options=options)
        assert os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 16
0
 def test_executionerror_exception(self):
     env_builder = envbuilder._FadesEnvBuilder()
     interpreter = 'python3'
     is_current = False
     options = {
         "virtualenv_options": [],
         "pyvenv_options": ['--system-site-packages'],
     }
     with patch('fades.envbuilder.helpers.logged_exec') as mock_lexec:
         mock_lexec.side_effect = envbuilder.helpers.ExecutionError(
             1, 'cmd', ['stdout'])
         with self.assertRaises(FadesError) as cm:
             env_builder.create_env(interpreter, is_current, options)
         self.assertEqual(str(cm.exception), 'virtualenv could not be run')
Ejemplo n.º 17
0
    def test_destroy_venv(self):
        builder = envbuilder._FadesEnvBuilder()
        # make sure the virtualenv exists on disk
        options = {
            "virtualenv_options": [],
            "pyvenv_options": ['--system-site-packages'],
            "pip-options": [],
        }
        builder.create_env('python', False, options=options)
        assert os.path.exists(builder.env_path)

        cache_mock = Mock()
        envbuilder.destroy_venv(builder.env_path, cache_mock)
        self.assertFalse(os.path.exists(builder.env_path))
        cache_mock.remove.assert_called_with(builder.env_path)
Ejemplo n.º 18
0
 def test_custom_env_path(self):
     builder = envbuilder._FadesEnvBuilder('some-path')
     self.assertEqual(builder.env_path, 'some-path')
Ejemplo n.º 19
0
 def test_custom_env_path(self):
     builder = envbuilder._FadesEnvBuilder('some-path')
     self.assertEqual(builder.env_path, 'some-path')