Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / tests / test_integration.py
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
4 #
5 #    http://www.apache.org/licenses/LICENSE-2.0
6 #
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
10 # implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 import os.path
15 import shlex
16 import sys
17
18 import fixtures
19 import testtools
20 import textwrap
21
22 from pbr.tests import base
23 from pbr.tests import test_packaging
24
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__, '..', '..', '..'))
33
34
35 def all_projects():
36     if not REPODIR:
37         return
38     # Future: make this path parameterisable.
39     excludes = set(['tempest', 'requirements'])
40     for name in PROJECTS:
41         name = name.strip()
42         short_name = name.split('/')[-1]
43         try:
44             with open(os.path.join(
45                     REPODIR, short_name, 'setup.py'), 'rt') as f:
46                 if 'pbr' not in f.read():
47                     continue
48         except IOError:
49             continue
50         if short_name in excludes:
51             continue
52         yield (short_name, dict(name=name, short_name=short_name))
53
54
55 class TestIntegration(base.BaseTestCase):
56
57     scenarios = list(all_projects())
58
59     def setUp(self):
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'))
64         with env:
65             super(TestIntegration, self).setUp()
66         base._config_git()
67
68     @testtools.skipUnless(
69         os.environ.get('PBR_INTEGRATION', None) == '1',
70         'integration tests not enabled')
71     def test_integration(self):
72         # Test that we can:
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(
81             'sync-req',
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))
88         path = os.path.join(
89             self.useFixture(fixtures.TempDir()).path, 'project')
90         self.useFixture(base.CapturedSubprocess(
91             'clone',
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],
96                                 pip_cmd=PIP_CMD))
97         python = venv.python
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],
103                                 pip_cmd=PIP_CMD))
104         python = venv.python
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],
112                                 pip_cmd=PIP_CMD))
113         root = venv.path
114         python = venv.python
115         self.useFixture(base.CapturedSubprocess(
116             'install-git', [python] + PIP_CMD + ['git+file://' + path]))
117         if self.short_name == 'nova':
118             found = False
119             for _, _, filenames in os.walk(root):
120                 if 'migrate.cfg' in filenames:
121                     found = True
122             self.assertTrue(found)
123         venv = self.useFixture(
124             test_packaging.Venv('install-e',
125                                 modules=['pip', 'wheel', PBRVERSION],
126                                 pip_cmd=PIP_CMD))
127         root = venv.path
128         python = venv.python
129         self.useFixture(base.CapturedSubprocess(
130             'install-e', [python] + PIP_CMD + ['-e', path]))
131
132
133 class TestInstallWithoutPbr(base.BaseTestCase):
134
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
142         # in using-package.
143         dist_dir = os.path.join(tempdir, 'distdir')
144         os.mkdir(dist_dir)
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)
150         pkgs = {
151             'pkgTest': {
152                 'setup.py': textwrap.dedent("""\
153                     #!/usr/bin/env python
154                     import setuptools
155                     setuptools.setup(
156                         name = 'pkgTest',
157                         tests_require = ['pkgReq'],
158                         test_suite='pkgReq'
159                     )
160                 """),
161                 'setup.cfg': textwrap.dedent("""\
162                     [easy_install]
163                     find_links = %s
164                 """ % dist_dir)},
165             'pkgReq': {
166                 'requirements.txt': textwrap.dedent("""\
167                     pbr
168                 """),
169                 'pkgReq/__init__.py': textwrap.dedent("""\
170                     print("FakeTest loaded and ran")
171                 """)},
172         }
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']
177
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']))
182         python = venv.python
183         # Run the depending script
184         self.useFixture(base.CapturedSubprocess(
185             'nopbr', [python] + ['setup.py', 'test'], cwd=test_pkg_dir))
186
187
188 class TestMarkersPip(base.BaseTestCase):
189
190     scenarios = [
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']}),
197     ]
198
199     @testtools.skipUnless(
200         os.environ.get('PBR_INTEGRATION', None) == '1',
201         'integration tests not enabled')
202     def test_pip_versions(self):
203         pkgs = {
204             'test_markers':
205                 {'requirements.txt': textwrap.dedent("""\
206                     pkg_a; python_version=='1.2'
207                     pkg_b; python_version!='1.2'
208                 """)},
209             'pkg_a': {},
210             'pkg_b': {},
211         }
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
218         os.mkdir(repo_dir)
219         for module in self.modules:
220             self._run_cmd(
221                 bin_python,
222                 ['-m', 'pip', 'install', '--upgrade', module],
223                 cwd=venv.path, allow_fail=False)
224         for pkg in pkg_dirs:
225             self._run_cmd(
226                 bin_python, ['setup.py', 'sdist', '-d', repo_dir],
227                 cwd=pkg_dirs[pkg], allow_fail=False)
228         self._run_cmd(
229             bin_python,
230             ['-m', 'pip', 'install', '--no-index', '-f', repo_dir,
231              'test_markers'],
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])
236
237
238 class TestLTSSupport(base.BaseTestCase):
239
240     # These versions come from the versions installed from the 'virtualenv'
241     # command from the 'python-virtualenv' package.
242     scenarios = [
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})
253     ]
254
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, '
261                           'skipping test')
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)