MCPcopy Index your code
hub / github.com/pydata/xarray / test_file_manager_autoclose

Function test_file_manager_autoclose

xarray/tests/test_backends_file_manager.py:43–64  ·  view source on GitHub ↗
(warn_for_unclosed_files)

Source from the content-addressed store, hash-verified

41
42@pytest.mark.parametrize("warn_for_unclosed_files", [True, False])
43def test_file_manager_autoclose(warn_for_unclosed_files) -> None:
44 mock_file = mock.Mock()
45 opener = mock.Mock(return_value=mock_file)
46 cache: dict = {}
47
48 manager = CachingFileManager(opener, "filename", cache=cache)
49 manager.acquire()
50 assert cache
51
52 # can no longer use pytest.warns(None)
53 if warn_for_unclosed_files:
54 ctx = pytest.warns(RuntimeWarning)
55 else:
56 ctx = assert_no_warnings() # type: ignore[assignment]
57
58 with set_options(warn_for_unclosed_files=warn_for_unclosed_files):
59 with ctx:
60 del manager
61 gc.collect()
62
63 assert not cache
64 mock_file.close.assert_called_once_with()
65
66
67def test_file_manager_autoclose_while_locked() -> None:

Callers

nothing calls this directly

Calls 4

acquireMethod · 0.95
CachingFileManagerClass · 0.90
assert_no_warningsFunction · 0.90
set_optionsClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…