Skip to content

Commit

Permalink
This scenario is cursed
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpryce committed Oct 24, 2024
1 parent 0941721 commit 7a7b4f3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import shutil
import tempfile

from pathlib import Path

import numpy as np

from fixtures import random_vectors, vectors_as_temp_file
Expand All @@ -22,8 +24,9 @@ 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:
with tempfile.NamedTemporaryFile() as vecs_file_copy:
shutil.copyfile(vecs_file, vecs_file_copy.name)
try:
vecs_files_copy = Path(tempfile.mkstemp())
shutil.copyfile(vecs_file, str(vecs_file_copy))
actual = dap.vectors_from_file(
vecs_file,
dtype=np.float32,
Expand All @@ -34,12 +37,15 @@ 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(
vecs_file_copy.name,
str(vecs_file_copy),
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()


if __name__ == '__main__':
Expand Down

0 comments on commit 7a7b4f3

Please sign in to comment.