mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add bdist_wheel test
This commit is contained in:
parent
fceff0287c
commit
ddfb065bfb
2 changed files with 136 additions and 0 deletions
59
tests/integration/test_setup.py
Normal file
59
tests/integration/test_setup.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
tests.integration.test_setup
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import re
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import skipIf
|
||||
from tests.support.helpers import skip_if_not_root
|
||||
from tests.support.virtualenv import VirtualEnvHelper
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
||||
|
||||
|
||||
@skip_if_not_root
|
||||
@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
|
||||
class SetupTest(VirtualEnvHelper):
|
||||
'''
|
||||
Tests for building and installing packages using setup.py
|
||||
'''
|
||||
def test_wheel_build(self):
|
||||
'''
|
||||
test building a bdist_wheel package and ensure
|
||||
'''
|
||||
# Let's create the testing virtualenv
|
||||
self._create_virtualenv(self.venv_dir)
|
||||
|
||||
# Let's remove the pip binary
|
||||
pip_bin = os.path.join(self.venv_dir, 'bin', 'pip')
|
||||
site_dir = self.run_function('virtualenv.get_distribution_path', [self.venv_dir, 'pip'])
|
||||
if salt.utils.platform.is_windows():
|
||||
pip_bin = os.path.join(self.venv_dir, 'Scripts', 'pip.exe')
|
||||
site_dir = os.path.join(self.venv_dir, 'lib', 'site-packages')
|
||||
if not os.path.isfile(pip_bin):
|
||||
self.skipTest(
|
||||
'Failed to find the pip binary to the test virtualenv'
|
||||
)
|
||||
ret = self.run_function('cmd.run', ['python setup.py bdist_wheel --dist-dir={0}'.format(self.venv_dir)], cwd=RUNTIME_VARS.CODE_DIR)
|
||||
|
||||
for _file in os.listdir(self.venv_dir):
|
||||
if _file.endswith('whl'):
|
||||
whl = os.path.join(self.venv_dir, _file)
|
||||
break
|
||||
|
||||
ret = self.run_function('pip.install', pkgs=whl, bin_env=self.venv_dir)
|
||||
|
||||
# Let's ensure the version is correct
|
||||
pip_ver = self.run_function('pip.list', bin_env=self.venv_dir).get('salt')
|
||||
whl_ver = [x for x in whl.split('/')[-1:][0].split('-') if re.search(r'^\d.\d*', x)][0]
|
||||
assert pip_ver == whl_ver
|
77
tests/support/virtualenv.py
Normal file
77
tests/support/virtualenv.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
helper for creating virtualenv's in tests
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.case import ModuleCase
|
||||
from tests.support.helpers import patched_environ
|
||||
|
||||
|
||||
class VirtualEnvHelper(ModuleCase):
|
||||
|
||||
def setUp(self):
|
||||
self.venv_test_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
|
||||
# Remove the venv test directory
|
||||
self.addCleanup(shutil.rmtree, self.venv_test_dir, ignore_errors=True)
|
||||
self.venv_dir = os.path.join(self.venv_test_dir, 'venv')
|
||||
self.pip_temp = os.path.join(self.venv_test_dir, '.pip-temp')
|
||||
if not os.path.isdir(self.pip_temp):
|
||||
os.makedirs(self.pip_temp)
|
||||
self.patched_environ = patched_environ(
|
||||
PIP_SOURCE_DIR='',
|
||||
PIP_BUILD_DIR='',
|
||||
__cleanup__=[k for k in os.environ if k.startswith('PIP_')]
|
||||
)
|
||||
self.patched_environ.__enter__()
|
||||
self.addCleanup(self.patched_environ.__exit__)
|
||||
|
||||
def _create_virtualenv(self, path):
|
||||
'''
|
||||
The reason why the virtualenv creation is proxied by this function is mostly
|
||||
because under windows, we can't seem to properly create a virtualenv off of
|
||||
another virtualenv(we can on linux) and also because, we really don't want to
|
||||
test virtualenv creation off of another virtualenv, we want a virtualenv created
|
||||
from the original python.
|
||||
Also, one windows, we must also point to the virtualenv binary outside the existing
|
||||
virtualenv because it will fail otherwise
|
||||
'''
|
||||
try:
|
||||
if salt.utils.platform.is_windows():
|
||||
python = os.path.join(sys.real_prefix, os.path.basename(sys.executable))
|
||||
else:
|
||||
python_binary_names = [
|
||||
'python{}.{}'.format(*sys.version_info),
|
||||
'python{}'.format(*sys.version_info),
|
||||
'python'
|
||||
]
|
||||
for binary_name in python_binary_names:
|
||||
python = os.path.join(sys.real_prefix, 'bin', binary_name)
|
||||
if os.path.exists(python):
|
||||
break
|
||||
else:
|
||||
self.fail(
|
||||
'Couldn\'t find a python binary name under \'{}\' matching: {}'.format(
|
||||
os.path.join(sys.real_prefix, 'bin'),
|
||||
python_binary_names
|
||||
)
|
||||
)
|
||||
# We're running off a virtualenv, and we don't want to create a virtualenv off of
|
||||
# a virtualenv
|
||||
kwargs = {'python': python}
|
||||
except AttributeError:
|
||||
# We're running off of the system python
|
||||
kwargs = {}
|
||||
self.run_function('virtualenv.create', [path], **kwargs)
|
Loading…
Add table
Reference in a new issue