From a8a22a404032613120559cd16a610d60ee041239 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Thu, 19 Mar 2020 17:23:42 -0400 Subject: [PATCH 1/2] Ensure version.py included before we install --- setup.py | 6 +++ tests/integration/setup/test_egg.py | 58 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/integration/setup/test_egg.py diff --git a/setup.py b/setup.py index 48b779997dff..45484e5d7703 100755 --- a/setup.py +++ b/setup.py @@ -745,6 +745,12 @@ def run(self): self.distribution.salt_download_windows_dlls = True self.run_command('download-windows-dlls') self.distribution.salt_download_windows_dlls = None + # need to ensure _version.py is created in build dir before install + if not os.path.exists(os.path.join(self.build_lib)): + if not self.skip_build: + self.run_command('build') + else: + self.run_command('write_salt_version') # Run install.run install.run(self) diff --git a/tests/integration/setup/test_egg.py b/tests/integration/setup/test_egg.py new file mode 100644 index 000000000000..fd538ebd61d0 --- /dev/null +++ b/tests/integration/setup/test_egg.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +''' +tests.integration.setup.test_egg +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +''' + +# Import python libs +from __future__ import absolute_import, print_function, unicode_literals +import os +import re +import shutil + +# Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS +from tests.support.unit import skipIf +from tests.support.helpers import VirtualEnv, destructiveTest +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 + + +@destructiveTest +@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed') +class EggSetupTest(ModuleCase): + ''' + Tests for building and installing egg packages + ''' + def test_egg_install(self): + ''' + test installing an egg package + ''' + # Let's create the testing virtualenv + with VirtualEnv() as venv: + ret = self.run_function('cmd.run', ['{0} setup.py install --prefix={1}'.format(venv.venv_python, + venv.venv_dir)], + cwd=RUNTIME_VARS.CODE_DIR) + lib_dir = os.path.join(venv.venv_dir, 'lib') + for _dir in os.listdir(lib_dir): + site_pkg = os.path.join(lib_dir, _dir, 'site-packages') + for _file in os.listdir(site_pkg): + if _file.startswith('salt-'): + egg = os.path.join(venv.venv_dir, _file) + assert os.path.exists(os.path.join(site_pkg, _file, 'salt', '_version.py')) + break + + # Let's ensure the version is correct + pip_ver = self.run_function('pip.list', bin_env=venv.venv_dir).get('salt') + egg_ver = [x for x in egg.split('/')[-1:][0].split('-') if re.search(r'^\d.\d*', x)][0] + assert pip_ver == egg_ver.replace('_', '-') + assert self.run_function('cmd.run', ['salt --version']).split()[1] == pip_ver + + def tearDown(self): + build_dir = os.path.join(RUNTIME_VARS.CODE_DIR, 'build') + if os.path.exists(build_dir): + shutil.rmtree(build_dir) From 85d7c784ef0a1ad799db6cc7651844d445cb1e83 Mon Sep 17 00:00:00 2001 From: ch3ll Date: Fri, 20 Mar 2020 11:27:40 -0400 Subject: [PATCH 2/2] Fix integration setup egg test --- tests/integration/setup/test_egg.py | 23 +++++++++++++++++------ tests/unit/test_module_names.py | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/integration/setup/test_egg.py b/tests/integration/setup/test_egg.py index fd538ebd61d0..2939f189207a 100644 --- a/tests/integration/setup/test_egg.py +++ b/tests/integration/setup/test_egg.py @@ -28,6 +28,22 @@ class EggSetupTest(ModuleCase): ''' Tests for building and installing egg packages ''' + + def setUp(self): + # ensure we have a clean build dir + self._clean_build() + + def _clean_build(self): + ''' + helper method to clean the build dir + ''' + dirs = [os.path.join(RUNTIME_VARS.CODE_DIR, 'build'), + os.path.join(RUNTIME_VARS.CODE_DIR, 'salt.egg-info'), + os.path.join(RUNTIME_VARS.CODE_DIR, 'dist')] + for _dir in dirs: + if os.path.exists(_dir): + shutil.rmtree(_dir) + def test_egg_install(self): ''' test installing an egg package @@ -37,6 +53,7 @@ def test_egg_install(self): ret = self.run_function('cmd.run', ['{0} setup.py install --prefix={1}'.format(venv.venv_python, venv.venv_dir)], cwd=RUNTIME_VARS.CODE_DIR) + self._clean_build() lib_dir = os.path.join(venv.venv_dir, 'lib') for _dir in os.listdir(lib_dir): site_pkg = os.path.join(lib_dir, _dir, 'site-packages') @@ -50,9 +67,3 @@ def test_egg_install(self): pip_ver = self.run_function('pip.list', bin_env=venv.venv_dir).get('salt') egg_ver = [x for x in egg.split('/')[-1:][0].split('-') if re.search(r'^\d.\d*', x)][0] assert pip_ver == egg_ver.replace('_', '-') - assert self.run_function('cmd.run', ['salt --version']).split()[1] == pip_ver - - def tearDown(self): - build_dir = os.path.join(RUNTIME_VARS.CODE_DIR, 'build') - if os.path.exists(build_dir): - shutil.rmtree(build_dir) diff --git a/tests/unit/test_module_names.py b/tests/unit/test_module_names.py index 5d91dfd383b5..ded8d34a0d3f 100644 --- a/tests/unit/test_module_names.py +++ b/tests/unit/test_module_names.py @@ -160,6 +160,7 @@ def test_module_name_source_match(self): 'integration.scheduler.test_helpers', 'integration.scheduler.test_run_job', 'integration.setup.test_bdist', + 'integration.setup.test_egg', 'integration.shell.test_spm', 'integration.shell.test_cp', 'integration.shell.test_syndic',