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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
from __future__ import absolute_import, print_function
# still needed
# tests for MingW32Compiler
# don't know how to test gcc_exists() and msvc_exists()...
import os
import sys
import tempfile
import warnings
from numpy.testing import TestCase, assert_, run_module_suite
from scipy.weave import build_tools
# filter warnings generated by checking for bad paths
warnings.filterwarnings('ignore',
message="specified build_dir",
module='scipy.weave')
def is_writable(val):
return os.access(val,os.W_OK)
class TestConfigureBuildDir(TestCase):
def test_default(self):
# default behavior is to return current directory
d = build_tools.configure_build_dir()
if is_writable('.'):
assert_(d == os.path.abspath('.'))
assert_(is_writable(d))
def test_curdir(self):
# make sure it handles relative values.
d = build_tools.configure_build_dir('.')
if is_writable('.'):
assert_(d == os.path.abspath('.'))
assert_(is_writable(d))
def test_pardir(self):
# make sure it handles relative values
d = build_tools.configure_build_dir('..')
if is_writable('..'):
assert_(d == os.path.abspath('..'))
assert_(is_writable(d))
def test_bad_path(self):
# bad path should return same as default (and warn)
d = build_tools.configure_build_dir('_bad_path_')
d2 = build_tools.configure_build_dir()
assert_(d == d2)
assert_(is_writable(d))
class TestConfigureTempDir(TestConfigureBuildDir):
def test_default(self):
# default behavior returns tempdir
# Note: this'll fail if the temp directory isn't writable.
d = build_tools.configure_temp_dir()
assert_(d == tempfile.gettempdir())
assert_(is_writable(d))
class TestConfigureSysArgv(TestCase):
def test_simple(self):
build_dir = 'build_dir'
temp_dir = 'temp_dir'
compiler = 'compiler'
pre_argv = sys.argv[:]
build_tools.configure_sys_argv(compiler,temp_dir,build_dir)
argv = sys.argv[:]
bd = argv[argv.index('--build-lib')+1]
assert_(bd == build_dir)
td = argv[argv.index('--build-temp')+1]
assert_(td == temp_dir)
argv.index('--compiler='+compiler)
build_tools.restore_sys_argv()
assert_(pre_argv == sys.argv[:])
if __name__ == "__main__":
run_module_suite()
|