summaryrefslogtreecommitdiff
path: root/numpy/distutils
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-01-02 08:34:54 -0700
committerCharles Harris <charlesr.harris@gmail.com>2016-01-02 08:34:54 -0700
commit9bd67153c6efab990b33ff34342b7782256de1f9 (patch)
tree287a4129443eb75f8c7ec7cef46104b635d22d5c /numpy/distutils
parent22c84f5ea585645b458b1ed0ca31d739cf3085c6 (diff)
parente89d9bb2e16c1746ce234b81aff4731277b31ddd (diff)
downloadnumpy-9bd67153c6efab990b33ff34342b7782256de1f9.tar.gz
Merge pull request #6886 from charris/use-temppath
MAINT: Simplify some tests using temppath context manager.
Diffstat (limited to 'numpy/distutils')
-rw-r--r--numpy/distutils/tests/test_npy_pkg_config.py54
1 files changed, 21 insertions, 33 deletions
diff --git a/numpy/distutils/tests/test_npy_pkg_config.py b/numpy/distutils/tests/test_npy_pkg_config.py
index 9a7284270..bdef47167 100644
--- a/numpy/distutils/tests/test_npy_pkg_config.py
+++ b/numpy/distutils/tests/test_npy_pkg_config.py
@@ -1,10 +1,9 @@
from __future__ import division, absolute_import, print_function
import os
-from tempfile import mkstemp
from numpy.distutils.npy_pkg_config import read_config, parse_flags
-from numpy.testing import TestCase, run_module_suite
+from numpy.testing import TestCase, run_module_suite, temppath
simple = """\
[meta]
@@ -39,41 +38,30 @@ simple_variable_d = {'cflags': '-I/foo/bar/include', 'libflags': '-L/foo/bar/lib
class TestLibraryInfo(TestCase):
def test_simple(self):
- fd, filename = mkstemp('foo.ini')
- try:
- pkg = os.path.splitext(filename)[0]
- try:
- os.write(fd, simple.encode('ascii'))
- finally:
- os.close(fd)
-
+ with temppath('foo.ini') as path:
+ with open(path, 'w') as f:
+ f.write(simple)
+ pkg = os.path.splitext(path)[0]
out = read_config(pkg)
- self.assertTrue(out.cflags() == simple_d['cflags'])
- self.assertTrue(out.libs() == simple_d['libflags'])
- self.assertTrue(out.name == simple_d['name'])
- self.assertTrue(out.version == simple_d['version'])
- finally:
- os.remove(filename)
- def test_simple_variable(self):
- fd, filename = mkstemp('foo.ini')
- try:
- pkg = os.path.splitext(filename)[0]
- try:
- os.write(fd, simple_variable.encode('ascii'))
- finally:
- os.close(fd)
+ self.assertTrue(out.cflags() == simple_d['cflags'])
+ self.assertTrue(out.libs() == simple_d['libflags'])
+ self.assertTrue(out.name == simple_d['name'])
+ self.assertTrue(out.version == simple_d['version'])
+ def test_simple_variable(self):
+ with temppath('foo.ini') as path:
+ with open(path, 'w') as f:
+ f.write(simple_variable)
+ pkg = os.path.splitext(path)[0]
out = read_config(pkg)
- self.assertTrue(out.cflags() == simple_variable_d['cflags'])
- self.assertTrue(out.libs() == simple_variable_d['libflags'])
- self.assertTrue(out.name == simple_variable_d['name'])
- self.assertTrue(out.version == simple_variable_d['version'])
-
- out.vars['prefix'] = '/Users/david'
- self.assertTrue(out.cflags() == '-I/Users/david/include')
- finally:
- os.remove(filename)
+
+ self.assertTrue(out.cflags() == simple_variable_d['cflags'])
+ self.assertTrue(out.libs() == simple_variable_d['libflags'])
+ self.assertTrue(out.name == simple_variable_d['name'])
+ self.assertTrue(out.version == simple_variable_d['version'])
+ out.vars['prefix'] = '/Users/david'
+ self.assertTrue(out.cflags() == '-I/Users/david/include')
class TestParseFlags(TestCase):
def test_simple_cflags(self):