1 0
import os
2 0
import sys
3 0
import types
4 0
from copy import deepcopy
5 0
from importlib import machinery
6 0
from distutils.core import Extension
7

8 0
from ..openmp_helpers import add_openmp_flags_if_available, generate_openmp_enabled_py
9 0
from ..setup_helpers import _module_state, register_commands
10

11 0
IS_TRAVIS_LINUX = os.environ.get('TRAVIS_OS_NAME', None) == 'linux'
12 0
IS_TRAVIS_OSX = os.environ.get('TRAVIS_OS_NAME', None) == 'osx'
13 0
IS_APPVEYOR = os.environ.get('APPVEYOR', None) == 'True'
14 0
OPENMP_EXPECTED = os.environ.get('OPENMP_EXPECTED', False) == 'True'
15 0
PY3_LT_35 = sys.version_info[0] == 3 and sys.version_info[1] < 5
16

17 0
_state = None
18

19

20 0
def setup_function(function):
21
    global state
22 0
    state = deepcopy(_module_state)
23

24

25 0
def teardown_function(function):
26 0
    _module_state.clear()
27 0
    _module_state.update(state)
28

29

30 0
def test_add_openmp_flags_if_available():
31

32 0
    register_commands('openmp_testing', '0.0', False)
33

34 0
    using_openmp = add_openmp_flags_if_available(Extension('test', []))
35

36
    # Make sure that on Travis (Linux) and AppVeyor OpenMP does get used (for
37
    # MacOS X usually it will not work but this will depend on the compiler).
38
    # Having this is useful because we'll find out if OpenMP no longer works
39
    # for any reason on platforms on which it does work at the time of writing.
40 0
    if OPENMP_EXPECTED:
41 0
        assert using_openmp
42
    else:
43 0
        assert not using_openmp
44

45

46 0
def test_generate_openmp_enabled_py():
47

48 0
    register_commands('openmp_autogeneration_testing', '0.0', False)
49

50
    # Test file generation
51 0
    generate_openmp_enabled_py('')
52 0
    assert os.path.isfile('openmp_enabled.py')
53

54
    # Load openmp_enabled file as a module to check the result
55 0
    loader = machinery.SourceFileLoader('openmp_enabled', 'openmp_enabled.py')
56 0
    mod = types.ModuleType(loader.name)
57 0
    loader.exec_module(mod)
58

59 0
    is_openmp_enabled = mod.is_openmp_enabled()
60

61
    # Test is_openmp_enabled()
62 0
    assert isinstance(is_openmp_enabled, bool)
63

64 0
    if OPENMP_EXPECTED:
65 0
        assert is_openmp_enabled
66
    else:
67 0
        assert not is_openmp_enabled

Read our documentation on viewing source code .

Loading