1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
22 from pbr.tests import base
23 from pbr.tests import test_packaging
25 PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', ''))
26 PIPVERSION = os.environ.get('PIPVERSION', 'pip')
27 PBRVERSION = os.environ.get('PBRVERSION', 'pbr')
28 REPODIR = os.environ.get('REPODIR', '')
29 WHEELHOUSE = os.environ.get('WHEELHOUSE', '')
30 PIP_CMD = ['-m', 'pip'] + PIPFLAGS + ['install', '-f', WHEELHOUSE]
31 PROJECTS = shlex.split(os.environ.get('PROJECTS', ''))
32 PBR_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
38 # Future: make this path parameterisable.
39 excludes = set(['tempest', 'requirements'])
42 short_name = name.split('/')[-1]
44 with open(os.path.join(
45 REPODIR, short_name, 'setup.py'), 'rt') as f:
46 if 'pbr' not in f.read():
50 if short_name in excludes:
52 yield (short_name, dict(name=name, short_name=short_name))
55 class TestIntegration(base.BaseTestCase):
57 scenarios = list(all_projects())
60 # Integration tests need a higher default - big repos can be slow to
61 # clone, particularly under guest load.
62 env = fixtures.EnvironmentVariable(
63 'OS_TEST_TIMEOUT', os.environ.get('OS_TEST_TIMEOUT', '600'))
65 super(TestIntegration, self).setUp()
68 @testtools.skipUnless(
69 os.environ.get('PBR_INTEGRATION', None) == '1',
70 'integration tests not enabled')
71 def test_integration(self):
73 # - run sdist from the repo in a venv
74 # - install the resulting tarball in a new venv
75 # - pip install the repo
76 # - pip install -e the repo
77 # We don't break these into separate tests because we'd need separate
78 # source dirs to isolate from side effects of running pip, and the
79 # overheads of setup would start to beat the benefits of parallelism.
80 self.useFixture(base.CapturedSubprocess(
82 ['python', 'update.py', os.path.join(REPODIR, self.short_name)],
83 cwd=os.path.join(REPODIR, 'requirements')))
84 self.useFixture(base.CapturedSubprocess(
85 'commit-requirements',
86 'git diff --quiet || git commit -amrequirements',
87 cwd=os.path.join(REPODIR, self.short_name), shell=True))
89 self.useFixture(fixtures.TempDir()).path, 'project')
90 self.useFixture(base.CapturedSubprocess(
92 ['git', 'clone', os.path.join(REPODIR, self.short_name), path]))
93 venv = self.useFixture(
94 test_packaging.Venv('sdist',
95 modules=['pip', 'wheel', PBRVERSION],
98 self.useFixture(base.CapturedSubprocess(
99 'sdist', [python, 'setup.py', 'sdist'], cwd=path))
100 venv = self.useFixture(
101 test_packaging.Venv('tarball',
102 modules=['pip', 'wheel', PBRVERSION],
105 filename = os.path.join(
106 path, 'dist', os.listdir(os.path.join(path, 'dist'))[0])
107 self.useFixture(base.CapturedSubprocess(
108 'tarball', [python] + PIP_CMD + [filename]))
109 venv = self.useFixture(
110 test_packaging.Venv('install-git',
111 modules=['pip', 'wheel', PBRVERSION],
115 self.useFixture(base.CapturedSubprocess(
116 'install-git', [python] + PIP_CMD + ['git+file://' + path]))
117 if self.short_name == 'nova':
119 for _, _, filenames in os.walk(root):
120 if 'migrate.cfg' in filenames:
122 self.assertTrue(found)
123 venv = self.useFixture(
124 test_packaging.Venv('install-e',
125 modules=['pip', 'wheel', PBRVERSION],
129 self.useFixture(base.CapturedSubprocess(
130 'install-e', [python] + PIP_CMD + ['-e', path]))
133 class TestInstallWithoutPbr(base.BaseTestCase):
135 @testtools.skipUnless(
136 os.environ.get('PBR_INTEGRATION', None) == '1',
137 'integration tests not enabled')
138 def test_install_without_pbr(self):
139 # Test easy-install of a thing that depends on a thing using pbr
140 tempdir = self.useFixture(fixtures.TempDir()).path
141 # A directory containing sdists of the things we're going to depend on
143 dist_dir = os.path.join(tempdir, 'distdir')
145 self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
146 allow_fail=False, cwd=PBR_ROOT)
147 # testpkg - this requires a pbr-using package
148 test_pkg_dir = os.path.join(tempdir, 'testpkg')
149 os.mkdir(test_pkg_dir)
152 'setup.py': textwrap.dedent("""\
153 #!/usr/bin/env python
157 tests_require = ['pkgReq'],
161 'setup.cfg': textwrap.dedent("""\
166 'requirements.txt': textwrap.dedent("""\
169 'pkgReq/__init__.py': textwrap.dedent("""\
170 print("FakeTest loaded and ran")
173 pkg_dirs = self.useFixture(
174 test_packaging.CreatePackages(pkgs)).package_dirs
175 test_pkg_dir = pkg_dirs['pkgTest']
176 req_pkg_dir = pkg_dirs['pkgReq']
178 self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
179 allow_fail=False, cwd=req_pkg_dir)
180 # A venv to test within
181 venv = self.useFixture(test_packaging.Venv('nopbr', ['pip', 'wheel']))
183 # Run the depending script
184 self.useFixture(base.CapturedSubprocess(
185 'nopbr', [python] + ['setup.py', 'test'], cwd=test_pkg_dir))
188 class TestMarkersPip(base.BaseTestCase):
191 ('pip-1.5', {'modules': ['pip>=1.5,<1.6']}),
192 ('pip-6.0', {'modules': ['pip>=6.0,<6.1']}),
193 ('pip-latest', {'modules': ['pip']}),
194 ('setuptools-EL7', {'modules': ['pip==1.4.1', 'setuptools==0.9.8']}),
195 ('setuptools-Trusty', {'modules': ['pip==1.5', 'setuptools==2.2']}),
196 ('setuptools-minimum', {'modules': ['pip==1.5', 'setuptools==0.7.2']}),
199 @testtools.skipUnless(
200 os.environ.get('PBR_INTEGRATION', None) == '1',
201 'integration tests not enabled')
202 def test_pip_versions(self):
205 {'requirements.txt': textwrap.dedent("""\
206 pkg_a; python_version=='1.2'
207 pkg_b; python_version!='1.2'
212 pkg_dirs = self.useFixture(
213 test_packaging.CreatePackages(pkgs)).package_dirs
214 temp_dir = self.useFixture(fixtures.TempDir()).path
215 repo_dir = os.path.join(temp_dir, 'repo')
216 venv = self.useFixture(test_packaging.Venv('markers'))
217 bin_python = venv.python
219 for module in self.modules:
222 ['-m', 'pip', 'install', '--upgrade', module],
223 cwd=venv.path, allow_fail=False)
226 bin_python, ['setup.py', 'sdist', '-d', repo_dir],
227 cwd=pkg_dirs[pkg], allow_fail=False)
230 ['-m', 'pip', 'install', '--no-index', '-f', repo_dir,
232 cwd=venv.path, allow_fail=False)
233 self.assertIn('pkg-b', self._run_cmd(
234 bin_python, ['-m', 'pip', 'freeze'], cwd=venv.path,
235 allow_fail=False)[0])
238 class TestLTSSupport(base.BaseTestCase):
240 # These versions come from the versions installed from the 'virtualenv'
241 # command from the 'python-virtualenv' package.
243 ('EL7', {'modules': ['pip==1.4.1', 'setuptools==0.9.8'],
244 'py3support': True}), # And EPEL6
245 ('Trusty', {'modules': ['pip==1.5', 'setuptools==2.2'],
246 'py3support': True}),
247 ('Jessie', {'modules': ['pip==1.5.6', 'setuptools==5.5.1'],
248 'py3support': True}),
249 # Wheezy has pip1.1, which cannot be called with '-m pip'
250 # So we'll use a different version of pip here.
251 ('WheezyPrecise', {'modules': ['pip==1.4.1', 'setuptools==0.6c11'],
252 'py3support': False})
255 @testtools.skipUnless(
256 os.environ.get('PBR_INTEGRATION', None) == '1',
257 'integration tests not enabled')
258 def test_lts_venv_default_versions(self):
259 if (sys.version_info[0] == 3 and not self.py3support):
260 self.skipTest('This combination will not install with py3, '
262 venv = self.useFixture(
263 test_packaging.Venv('setuptools', modules=self.modules))
264 bin_python = venv.python
265 pbr = 'file://%s#egg=pbr' % PBR_ROOT
266 # Installing PBR is a reasonable indication that we are not broken on
267 # this particular combination of setuptools and pip.
268 self._run_cmd(bin_python, ['-m', 'pip', 'install', pbr],
269 cwd=venv.path, allow_fail=False)