MCPcopy Create free account
hub / github.com/numpy/numpy / temppath

Function temppath

numpy/testing/_private/utils.py:1917–1935  ·  view source on GitHub ↗

Context manager for temporary files. Context manager that returns the path to a closed temporary file. Its parameters are the same as for tempfile.mkstemp and are passed directly to that function. The underlying file is removed when the context is exited, so it should be closed at t

(*args, **kwargs)

Source from the content-addressed store, hash-verified

1915
1916@contextlib.contextmanager
1917def temppath(*args, **kwargs):
1918 """Context manager for temporary files.
1919
1920 Context manager that returns the path to a closed temporary file. Its
1921 parameters are the same as for tempfile.mkstemp and are passed directly
1922 to that function. The underlying file is removed when the context is
1923 exited, so it should be closed at that time.
1924
1925 Windows does not allow a temporary file to be opened if it is already
1926 open, so the underlying file must be closed after opening before it
1927 can be opened again.
1928
1929 """
1930 fd, path = mkstemp(*args, **kwargs)
1931 os.close(fd)
1932 try:
1933 yield path
1934 finally:
1935 os.remove(path)
1936
1937
1938class clear_and_catch_warnings(warnings.catch_warnings):

Callers 15

test_fromfile_bogusMethod · 0.90
test_fromfile_complexMethod · 0.90
test_fromfileMethod · 0.90
test_genfromtxtMethod · 0.90
test_loadtxtMethod · 0.90
test_tofile_roundtripMethod · 0.90
test_tofile_fromfileMethod · 0.90
test_big_arraysMethod · 0.90
writerMethod · 0.90
test_closing_fidMethod · 0.90

Calls 1

closeMethod · 0.45

Tested by 15

test_fromfile_bogusMethod · 0.72
test_fromfile_complexMethod · 0.72
test_fromfileMethod · 0.72
test_genfromtxtMethod · 0.72
test_loadtxtMethod · 0.72
test_tofile_roundtripMethod · 0.72
test_tofile_fromfileMethod · 0.72
test_big_arraysMethod · 0.72
writerMethod · 0.72
test_closing_fidMethod · 0.72