|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import subprocess |
| 4 | +import shlex |
| 5 | +import shutil |
| 6 | +import sys |
| 7 | +import time |
| 8 | +import datetime |
| 9 | +import pytest |
| 10 | + |
| 11 | +HERE = os.path.abspath(os.path.dirname(__file__)) |
| 12 | + |
| 13 | +skip_on_osx = pytest.mark.skipif('sys.platform == "darwin"', reason="not working on osx") |
| 14 | +skip_on_linux = pytest.mark.skipif('sys.platform == "linux2"', reason="not working on linux") |
| 15 | +skip_always = pytest.mark.skipif('1 == 1', reason="tests are broken") |
| 16 | + |
| 17 | + |
| 18 | +def exe(command): |
| 19 | + """ |
| 20 | + Executes command and returns string representations of stdout and stderr captured from the console. |
| 21 | + When universal_newlines=True stdout and stderr are opened in text mode. |
| 22 | + Otherwise, they are opened in binary mode. In that case captured stdout and stderr |
| 23 | + are not strings and Python 3 throws type error when compared against strings later in tests. |
| 24 | + Note: |
| 25 | + This feature is only available if Python is built with universal newline support (the default). |
| 26 | + Also, the newlines attribute of the file objects stdout, stdin and stderr are not updated by the |
| 27 | + communicate() method. |
| 28 | + See https://docs.python.org/2/library/subprocess.html |
| 29 | + """ |
| 30 | + stdout, stderr = subprocess.Popen(shlex.split(command), |
| 31 | + stdout=subprocess.PIPE, |
| 32 | + stderr=subprocess.PIPE, |
| 33 | + universal_newlines=True).communicate() |
| 34 | + |
| 35 | + if stderr: |
| 36 | + sys.stderr.write(stdout) |
| 37 | + sys.stderr.write(stderr) |
| 38 | + |
| 39 | + return stdout, stderr |
| 40 | + |
| 41 | + |
| 42 | +def configure_build_and_exe(name, setup_command, launcher=None): |
| 43 | + |
| 44 | + stamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S') |
| 45 | + |
| 46 | + os.chdir(os.path.join(HERE, name, 'cmake')) |
| 47 | + shutil.copy(os.path.join('..', '..', '..', 'update.py'), 'update.py') |
| 48 | + |
| 49 | + if os.path.exists('autocmake'): |
| 50 | + shutil.rmtree('autocmake') |
| 51 | + shutil.copytree(os.path.join('..', '..', '..', 'autocmake'), 'autocmake') |
| 52 | + |
| 53 | + stdout, stderr = exe('python update.py ..') |
| 54 | + os.chdir(os.path.join(HERE, name)) |
| 55 | + |
| 56 | + make_command = 'make' |
| 57 | + binary = './bin/example' |
| 58 | + if sys.platform == 'win32': |
| 59 | + setup_command += ' --generator="MinGW Makefiles"' |
| 60 | + make_command = 'mingw32-make' |
| 61 | + binary = 'bin\\\example.exe' |
| 62 | + |
| 63 | + if launcher: |
| 64 | + binary = '%s %s' % (launcher, binary) |
| 65 | + |
| 66 | + setup_command += ' build-%s' % stamp |
| 67 | + |
| 68 | + stdout, stderr = exe(setup_command) |
| 69 | + assert stderr == '' |
| 70 | + |
| 71 | + os.chdir(os.path.join(HERE, name, 'build-%s' % stamp)) |
| 72 | + |
| 73 | + stdout, stderr = exe(make_command) |
| 74 | + # we do not check for empty stderr due to warnings flushed to stderr |
| 75 | + |
| 76 | + stdout, stderr = exe(binary) |
| 77 | + assert stderr == '' |
| 78 | + |
| 79 | + assert 'PASSED' in stdout |
| 80 | + |
| 81 | + |
| 82 | +def test_fc(): |
| 83 | + configure_build_and_exe('fc', 'python setup --fc=gfortran') |
| 84 | + |
| 85 | + |
| 86 | +def test_fc_blas(): |
| 87 | + configure_build_and_exe('fc_blas', 'python setup --fc=gfortran --blas') |
| 88 | + |
| 89 | + |
| 90 | +@skip_on_osx |
| 91 | +def test_fc_openblas(): |
| 92 | + configure_build_and_exe('fc_openblas', 'python setup --fc=gfortran --openblas') |
0 commit comments