11from __future__ import division , absolute_import , print_function
22
3- from numpy .testing import assert_
3+ import pytest
4+
5+ from numpy .testing import assert_ , suppress_warnings
46import numpy .distutils .fcompiler
57
68customizable_flags = [
@@ -25,6 +27,7 @@ def test_fcompiler_flags(monkeypatch):
2527
2628 monkeypatch .setenv (envvar , new_flag )
2729 new_flags = getattr (flag_vars , opt )
30+
2831 monkeypatch .delenv (envvar )
2932 assert_ (new_flags == [new_flag ])
3033
@@ -33,12 +36,41 @@ def test_fcompiler_flags(monkeypatch):
3336 for opt , envvar in customizable_flags :
3437 new_flag = '-dummy-{}-flag' .format (opt )
3538 prev_flags = getattr (flag_vars , opt )
36-
3739 monkeypatch .setenv (envvar , new_flag )
3840 new_flags = getattr (flag_vars , opt )
41+
3942 monkeypatch .delenv (envvar )
4043 if prev_flags is None :
4144 assert_ (new_flags == [new_flag ])
4245 else :
4346 assert_ (new_flags == prev_flags + [new_flag ])
4447
48+
49+ def test_fcompiler_flags_append_warning (monkeypatch ):
50+ # Test to check that the warning for append behavior changing in future
51+ # is triggered. Need to use a real compiler instance so that we have
52+ # non-empty flags to start with (otherwise the "if var and append" check
53+ # will always be false).
54+ try :
55+ fc = numpy .distutils .fcompiler .new_fcompiler (compiler = 'gnu95' )
56+ fc .customize ()
57+ except numpy .distutils .fcompiler .CompilerNotFound :
58+ pytest .skip ("gfortran not found, so can't execute this test" )
59+
60+ # Ensure NPY_DISTUTILS_APPEND_FLAGS not defined
61+ monkeypatch .delenv ('NPY_DISTUTILS_APPEND_FLAGS' , raising = False )
62+
63+ for opt , envvar in customizable_flags :
64+ new_flag = '-dummy-{}-flag' .format (opt )
65+ prev_flags = getattr (fc .flag_vars , opt )
66+ monkeypatch .setenv (envvar , new_flag )
67+ with suppress_warnings () as sup :
68+ sup .record ()
69+ new_flags = getattr (fc .flag_vars , opt )
70+ if prev_flags :
71+ # Check that warning was issued
72+ assert len (sup .log ) == 1
73+
74+ monkeypatch .delenv (envvar )
75+ assert_ (new_flags == [new_flag ])
76+
0 commit comments