Skip to content

Commit

Permalink
Windows does not appreciate two readers of the same file at the same …
Browse files Browse the repository at this point in the history
…time in our unit test.
  • Loading branch information
daxpryce committed Oct 23, 2024
1 parent 3cdd3cf commit 5db81de
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions python/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Licensed under the MIT license.

import unittest
import shutil
import tempfile

import numpy as np

Expand All @@ -15,25 +17,29 @@ def test_in_mem(self):
expected = random_vectors(10_000, 100, dtype=np.float32)
with vectors_as_temp_file(expected) as vecs_file:
actual = dap.vectors_from_file(vecs_file, dtype=np.float32)
self.assertTrue((expected == actual).all())
self.assertTrue((expected == actual).all(), f"{expected == actual}\n{expected}\n{actual}")

def test_memmap(self):
expected = random_vectors(10_000, 100, dtype=np.float32)
with vectors_as_temp_file(expected) as vecs_file:
actual = dap.vectors_from_file(
vecs_file,
dtype=np.float32,
use_memmap=True
)
self.assertTrue((expected == actual).all(), f"{expected == actual}\n{expected}\n{actual}")
del actual # hopefully this releases the handle on the file, as windows is not happy with this
actual = dap.vectors_from_file(
vecs_file,
dtype=np.float32,
use_memmap=True,
mode="r+"
)
self.assertTrue((expected == actual).all())
with tempfile.NamedTemporaryFile() as vecs_file_copy:
shutil.copyfile(vecs_file, vecs_file_copy)
actual = dap.vectors_from_file(
vecs_file,
dtype=np.float32,
use_memmap=True
)
self.assertTrue((expected == actual).all(), f"{expected == actual}\n{expected}\n{actual}")
# windows refuses to allow 2 active handles via memmap to touch the same file
# 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(
vecs_file_copy,
dtype=np.float32,
use_memmap=True,
mode="r+"
)
self.assertTrue((expected == actual).all(), f"{expected == actual}\n{expected}\n{actual}")


if __name__ == '__main__':
Expand Down

0 comments on commit 5db81de

Please sign in to comment.