|
2 | 2 | import sys |
3 | 3 | import stat |
4 | 4 | import shutil |
| 5 | +import warnings |
5 | 6 | import contextlib |
6 | 7 |
|
7 | 8 | import pytest |
|
12 | 13 |
|
13 | 14 | from ..setup_helpers import get_package_info, register_commands |
14 | 15 | from ..commands import build_ext |
| 16 | +from ..utils import AstropyDeprecationWarning |
15 | 17 |
|
16 | 18 | from . import reset_setup_helpers, reset_distutils_log, fix_hide_setuptools # noqa |
17 | 19 | from . import run_setup, cleanup_import |
18 | 20 |
|
19 | 21 |
|
| 22 | +# Determine whether we're in a PY2 environment without using six |
| 23 | +USING_PY2 = sys.version_info < (3,0,0) |
| 24 | + |
| 25 | + |
20 | 26 | def _extension_test_package(tmpdir, request, extension_type='c'): |
21 | 27 | """Creates a simple test package with an extension module.""" |
22 | 28 |
|
@@ -170,11 +176,18 @@ def test_compiler_module(c_extension_test_package): |
170 | 176 | with test_pkg.as_cwd(): |
171 | 177 | # This is one of the simplest ways to install just a package into a |
172 | 178 | # test directory |
173 | | - run_setup('setup.py', |
174 | | - ['install', |
175 | | - '--single-version-externally-managed', |
176 | | - '--install-lib={0}'.format(install_temp), |
177 | | - '--record={0}'.format(install_temp.join('record.txt'))]) |
| 179 | + with warnings.catch_warnings(record=True) as w: |
| 180 | + run_setup('setup.py', |
| 181 | + ['install', |
| 182 | + '--single-version-externally-managed', |
| 183 | + '--install-lib={0}'.format(install_temp), |
| 184 | + '--record={0}'.format(install_temp.join('record.txt'))]) |
| 185 | + # Skip this portion of the test on windows systems with Py 2.7 since |
| 186 | + # it is known to produce additional warnings. |
| 187 | + if not (USING_PY2 or sys.platform.startswith('win')): |
| 188 | + # Warning expected from get_git_devstr, called by generate_version_py |
| 189 | + assert len(w) == 1 |
| 190 | + assert str(w[0].message).startswith("No git repository present at") |
178 | 191 |
|
179 | 192 | with install_temp.as_cwd(): |
180 | 193 | import apyhtest_eva |
@@ -205,7 +218,12 @@ def test_no_cython_buildext(c_extension_test_package, monkeypatch): |
205 | 218 | lambda *args: False) |
206 | 219 |
|
207 | 220 | with test_pkg.as_cwd(): |
208 | | - run_setup('setup.py', ['build_ext', '--inplace']) |
| 221 | + with warnings.catch_warnings(record=True) as w: |
| 222 | + run_setup('setup.py', ['build_ext', '--inplace']) |
| 223 | + # Warning expected from get_git_devstr, called by generate_version_py |
| 224 | + if not USING_PY2: |
| 225 | + assert len(w) == 1 |
| 226 | + assert str(w[0].message).startswith("No git repository present at") |
209 | 227 |
|
210 | 228 | sys.path.insert(0, str(test_pkg)) |
211 | 229 |
|
@@ -234,7 +252,13 @@ def test_missing_cython_c_files(pyx_extension_test_package, monkeypatch): |
234 | 252 |
|
235 | 253 | with test_pkg.as_cwd(): |
236 | 254 | with pytest.raises(SystemExit) as exc_info: |
237 | | - run_setup('setup.py', ['build_ext', '--inplace']) |
| 255 | + with warnings.catch_warnings(record=True) as w: |
| 256 | + run_setup('setup.py', ['build_ext', '--inplace']) |
| 257 | + # Warning expected from get_git_devstr, called by generate_version_py |
| 258 | + if not USING_PY2: |
| 259 | + assert len(w) == 1 |
| 260 | + assert str(w[0].message).startswith( |
| 261 | + "No git repository present at") |
238 | 262 |
|
239 | 263 | msg = ('Could not find C/C++ file ' |
240 | 264 | '{0}.(c/cpp)'.format('apyhtest_eva/unit02'.replace('/', os.sep))) |
@@ -323,7 +347,8 @@ class B(A): |
323 | 347 | elif mode == 'cli-l': |
324 | 348 | run_setup('setup.py', ['build_docs', '-l']) |
325 | 349 | elif mode == 'deprecated': |
326 | | - run_setup('setup.py', ['build_sphinx']) |
| 350 | + with pytest.warns(AstropyDeprecationWarning): |
| 351 | + run_setup('setup.py', ['build_sphinx']) |
327 | 352 | elif mode == 'direct': # to check coverage |
328 | 353 | with docs_dir.as_cwd(): |
329 | 354 | from sphinx import main |
|
0 commit comments