diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2015-12-20 10:47:42 -0700 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2015-12-20 10:47:42 -0700 |
| commit | 765422cfa5a959985808bbf11f7a6a58a9dc5e46 (patch) | |
| tree | 23be151e3ee2dc61441a024d7ff047ff3e4d35f4 /numpy/testing/tests/test_utils.py | |
| parent | f125b7d456717b366df1ed756656e3670a8a8d54 (diff) | |
| parent | c4156cfbe9c22ab99473346b7757d2b54b46baa3 (diff) | |
| download | numpy-765422cfa5a959985808bbf11f7a6a58a9dc5e46.tar.gz | |
Merge pull request #6866 from charris/tempfile-context-manager
ENH: Tempfile context manager
Diffstat (limited to 'numpy/testing/tests/test_utils.py')
| -rw-r--r-- | numpy/testing/tests/test_utils.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 13aeffe02..23bd491bc 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function import warnings import sys +import os import numpy as np from numpy.testing import ( @@ -10,7 +11,7 @@ from numpy.testing import ( assert_warns, assert_no_warnings, assert_allclose, assert_approx_equal, assert_array_almost_equal_nulp, assert_array_max_ulp, clear_and_catch_warnings, run_module_suite, - assert_string_equal + assert_string_equal, assert_, tempdir, temppath, ) import unittest @@ -780,6 +781,40 @@ def test_clear_and_catch_warnings(): assert_warn_len_equal(my_mod, 2) +def test_tempdir(): + with tempdir() as tdir: + fpath = os.path.join(tdir, 'tmp') + with open(fpath, 'w'): + pass + assert_(not os.path.isdir(tdir)) + + raised = False + try: + with tempdir() as tdir: + raise ValueError() + except ValueError: + raised = True + assert_(raised) + assert_(not os.path.isdir(tdir)) + + + +def test_temppath(): + with temppath() as fpath: + with open(fpath, 'w') as f: + pass + assert_(not os.path.isfile(fpath)) + + raised = False + try: + with temppath() as fpath: + raise ValueError() + except ValueError: + raised = True + assert_(raised) + assert_(not os.path.isfile(fpath)) + + class my_cacw(clear_and_catch_warnings): class_modules = (sys.modules[__name__],) |
