summaryrefslogtreecommitdiff
path: root/numpy/distutils/tests/test_fcompiler.py
blob: 4ab1522d7176a613ad2bd372eed9bd7fbcde8fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from __future__ import division, absolute_import, print_function

from numpy.testing import assert_
import numpy.distutils.fcompiler
import os

customizable_flags = [
    ('f77', 'F77FLAGS'),
    ('f90', 'F90FLAGS'),
    ('free', 'FREEFLAGS'),
    ('arch', 'FARCH'),
    ('debug', 'FDEBUG'),
    ('flags', 'FFLAGS'),
    ('linker_so', 'LDFLAGS'),
]


def test_fcompiler_flags_override(monkeypatch):
    monkeypatch.setitem(os.environ, 'NPY_DISTUTILS_APPEND_FLAGS', '0')
    fc = numpy.distutils.fcompiler.new_fcompiler(compiler='none')
    flag_vars = fc.flag_vars.clone(lambda *args, **kwargs: None)

    for opt, envvar in customizable_flags:
        new_flag = '-dummy-{}-flag'.format(opt)
        prev_flags = getattr(flag_vars, opt)

        monkeypatch.setitem(os.environ, envvar, new_flag)
        new_flags = getattr(flag_vars, opt)
        assert_(new_flags == [new_flag])


def test_fcompiler_flags_append(monkeypatch):
    monkeypatch.setitem(os.environ, 'NPY_DISTUTILS_APPEND_FLAGS', '1')
    fc = numpy.distutils.fcompiler.new_fcompiler(compiler='none')
    flag_vars = fc.flag_vars.clone(lambda *args, **kwargs: None)

    for opt, envvar in customizable_flags:
        new_flag = '-dummy-{}-flag'.format(opt)
        prev_flags = getattr(flag_vars, opt)

        monkeypatch.setitem(os.environ, envvar, new_flag)
        new_flags = getattr(flag_vars, opt)
        if prev_flags is None:
            assert_(new_flags == [new_flag])
        else:
            assert_(new_flags == prev_flags + [new_flag])