From a3c068519111763ee2167919a297e652870f574f Mon Sep 17 00:00:00 2001 From: Dax Pryce Date: Thu, 24 Oct 2024 05:11:54 +0000 Subject: [PATCH] . --- python/tests/test_files.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/python/tests/test_files.py b/python/tests/test_files.py index c40c8b027..c7fd2d708 100644 --- a/python/tests/test_files.py +++ b/python/tests/test_files.py @@ -24,9 +24,8 @@ def test_in_mem(self): def test_memmap(self): expected = random_vectors(10_000, 100, dtype=np.float32) with vectors_as_temp_file(expected) as vecs_file: - vecs_files_copy = Path(tempfile.mkstemp()) - try: - shutil.copyfile(vecs_file, str(vecs_file_copy)) + with tempfile.NamedTemporaryFile(delete=False) as vecs_file_copy: + shutil.copyfile(vecs_file, vecs_file_copy.name) actual = dap.vectors_from_file( vecs_file, dtype=np.float32, @@ -37,15 +36,13 @@ def test_memmap(self): # that's why we made a copy of the file itself and are using the copy here to test # the read+append(inmem) actual = dap.vectors_from_file( - str(vecs_file_copy), + vecs_file_copy.name, dtype=np.float32, use_memmap=True, mode="r+" ) self.assertTrue((expected == actual).all(), f"{expected == actual}\n{expected}\n{actual}") - finally: - if vecs_file_copy.exists(): - vecs_file_copy.unlink() + vecs_file_copy.unlink() if __name__ == '__main__':