diff options
Diffstat (limited to 'numpy/f2py')
-rw-r--r-- | numpy/f2py/tests/util.py | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/numpy/f2py/tests/util.py b/numpy/f2py/tests/util.py index 8d06d9680..0c9e91568 100644 --- a/numpy/f2py/tests/util.py +++ b/numpy/f2py/tests/util.py @@ -19,7 +19,7 @@ import random from numpy.compat import asbytes, asstr import numpy.f2py -from numpy.testing import SkipTest +from numpy.testing import SkipTest, temppath try: from hashlib import md5 @@ -159,16 +159,11 @@ def build_code(source_code, options=[], skip=[], only=[], suffix=None, """ if suffix is None: suffix = '.f' - - fd, tmp_fn = tempfile.mkstemp(suffix=suffix) - os.write(fd, asbytes(source_code)) - os.close(fd) - - try: - return build_module([tmp_fn], options=options, skip=skip, only=only, + with temppath(suffix=suffix) as path: + with open(path, 'w') as f: + f.write(source_code) + return build_module([path], options=options, skip=skip, only=only, module_name=module_name) - finally: - os.unlink(tmp_fn) # # Check if compilers are available at all... @@ -209,22 +204,19 @@ sys.exit(99) """ code = code % dict(syspath=repr(sys.path)) - fd, script = tempfile.mkstemp(suffix='.py') - os.write(fd, asbytes(code)) - os.close(fd) + with temppath(suffix='.py') as script: + with open(script, 'w') as f: + f.write(code) - try: cmd = [sys.executable, script, 'config'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, err = p.communicate() - m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out) - if m: - _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))), - bool(int(m.group(3)))) - finally: - os.unlink(script) + m = re.search(asbytes(r'COMPILERS:(\d+),(\d+),(\d+)'), out) + if m: + _compiler_status = (bool(int(m.group(1))), bool(int(m.group(2))), + bool(int(m.group(3)))) # Finished return _compiler_status |