mirror of
https://github.com/saltstack/salt.git
synced 2025-04-15 09:10:20 +00:00
Use virtualenv test helper that already exists and fix setup.py
This commit is contained in:
parent
293b1fddf2
commit
22cccd2107
7 changed files with 75 additions and 128 deletions
18
setup.py
18
setup.py
|
@ -38,6 +38,11 @@ from setuptools.command.develop import develop
|
|||
from setuptools.command.install import install
|
||||
from setuptools.command.sdist import sdist
|
||||
from setuptools.command.egg_info import egg_info
|
||||
try:
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
HAS_BDIST_WHEEL = True
|
||||
except ImportError:
|
||||
HAS_BDIST_WHEEL = False
|
||||
# pylint: enable=E0611
|
||||
|
||||
try:
|
||||
|
@ -642,6 +647,14 @@ class Clean(clean):
|
|||
os.remove(to_remove_filename)
|
||||
|
||||
|
||||
if HAS_BDIST_WHEEL:
|
||||
class BDistWheel(bdist_wheel):
|
||||
|
||||
def finalize_options(self):
|
||||
bdist_wheel.finalize_options(self)
|
||||
self.distribution.build_wheel = True
|
||||
|
||||
|
||||
INSTALL_VERSION_TEMPLATE = '''\
|
||||
# This file was auto-generated by salt's setup
|
||||
|
||||
|
@ -913,6 +926,8 @@ class SaltDistribution(distutils.dist.Distribution):
|
|||
'install_lib': InstallLib})
|
||||
if IS_WINDOWS_PLATFORM:
|
||||
self.cmdclass.update({'download-windows-dlls': DownloadWindowsDlls})
|
||||
if HAS_BDIST_WHEEL:
|
||||
self.cmdclass["bdist_wheel"] = BDistWheel
|
||||
|
||||
self.license = 'Apache Software License 2.0'
|
||||
self.packages = self.discover_packages()
|
||||
|
@ -1229,9 +1244,6 @@ class SaltDistribution(distutils.dist.Distribution):
|
|||
if not self.ssh_packaging and PACKAGED_FOR_SALT_SSH:
|
||||
self.ssh_packaging = 1
|
||||
|
||||
if 'bdist_wheel' in sys.argv:
|
||||
self.build_wheel = True
|
||||
|
||||
if self.ssh_packaging:
|
||||
self.metadata.name = 'salt-ssh'
|
||||
self.salt_transport = 'ssh'
|
||||
|
|
1
tests/integration/setup/__init__.py
Normal file
1
tests/integration/setup/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
48
tests/integration/setup/test_bdist.py
Normal file
48
tests/integration/setup/test_bdist.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
tests.integration.setup.test_bdist
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# 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, VirtualEnv
|
||||
from tests.support.case import ModuleCase
|
||||
|
||||
# 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 BdistSetupTest(ModuleCase):
|
||||
'''
|
||||
Tests for building and installing bdist_wheel packages
|
||||
'''
|
||||
def test_wheel_build(self):
|
||||
'''
|
||||
test building a bdist_wheel package
|
||||
'''
|
||||
# Let's create the testing virtualenv
|
||||
with VirtualEnv() as venv:
|
||||
ret = self.run_function('cmd.run', ['{0} setup.py bdist_wheel --dist-dir={1}'.format(venv.venv_python, venv.venv_dir)], cwd=RUNTIME_VARS.CODE_DIR)
|
||||
|
||||
for _file in os.listdir(venv.venv_dir):
|
||||
if _file.endswith('whl'):
|
||||
whl = os.path.join(venv.venv_dir, _file)
|
||||
break
|
||||
|
||||
ret = self.run_function('pip.install', pkgs=whl, bin_env=venv.venv_dir)
|
||||
|
||||
# Let's ensure the version is correct
|
||||
pip_ver = self.run_function('pip.list', bin_env=venv.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.replace('_', '-')
|
|
@ -1,48 +0,0 @@
|
|||
# -*- 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)
|
||||
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
|
|
@ -143,6 +143,9 @@ TEST_SUITES_UNORDERED = {
|
|||
'returners':
|
||||
{'display_name': 'Returners',
|
||||
'path': 'integration/returners'},
|
||||
'setup':
|
||||
{'display_name': 'Setup',
|
||||
'path': 'integration/setup'},
|
||||
'ssh-int':
|
||||
{'display_name': 'SSH Integration',
|
||||
'path': 'integration/ssh'},
|
||||
|
@ -399,6 +402,13 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
action='store_true',
|
||||
help='Run spm integration tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'--setup',
|
||||
dest='setup',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Run setup integration tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'-l',
|
||||
'--loader',
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
# -*- 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)
|
|
@ -159,6 +159,7 @@ class BadTestModuleNamesTestCase(TestCase):
|
|||
'integration.scheduler.test_maxrunning',
|
||||
'integration.scheduler.test_helpers',
|
||||
'integration.scheduler.test_run_job',
|
||||
'integration.setup.test_bdist',
|
||||
'integration.shell.test_spm',
|
||||
'integration.shell.test_cp',
|
||||
'integration.shell.test_syndic',
|
||||
|
|
Loading…
Add table
Reference in a new issue