Skip to content

Commit 2fee4d5

Browse files
committed
don't keep the file open on Windows
1 parent 51a03f4 commit 2fee4d5

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tests/test_blake3.py

+22-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from binascii import unhexlify
33
import json
44
import numpy
5+
import os
56
from pathlib import Path
67
import subprocess
78
import sys
@@ -433,22 +434,25 @@ def test_module_name() -> None:
433434

434435
def test_mmap() -> None:
435436
input_bytes = bytes([42]) * 1_000_000
436-
with tempfile.NamedTemporaryFile() as f:
437+
# Note that we can't use NamedTemporaryFile here, because we can't open it
438+
# again on Windows.
439+
(fd, temp_path) = tempfile.mkstemp()
440+
os.close(fd)
441+
with open(temp_path, "wb") as f:
437442
f.write(input_bytes)
438-
f.flush()
439-
440-
# Test all three threading modes, and both str and Path arguments. Note
441-
# that PyO3 doesn't support converting Python bytes to a Rust PathBuf,
442-
# I think because that's not generally possible on Windows.
443-
hasher1 = blake3()
444-
hasher1.update_mmap(f.name)
445-
assert blake3(input_bytes).digest() == hasher1.digest()
446-
447-
hasher2 = blake3(max_threads=blake3.AUTO)
448-
hasher2.update_mmap(Path(f.name))
449-
assert blake3(input_bytes).digest() == hasher2.digest()
450-
451-
hasher3 = blake3(max_threads=4)
452-
hasher3.update_mmap(path=f.name)
453-
hasher3.update_mmap(path=Path(f.name))
454-
assert blake3(2 * input_bytes).digest() == hasher3.digest()
443+
444+
# Test all three threading modes, and both str and Path arguments. Note
445+
# that PyO3 doesn't support converting Python bytes to a Rust PathBuf,
446+
# I think because that's not generally possible on Windows.
447+
hasher1 = blake3()
448+
hasher1.update_mmap(temp_path)
449+
assert blake3(input_bytes).digest() == hasher1.digest()
450+
451+
hasher2 = blake3(max_threads=blake3.AUTO)
452+
hasher2.update_mmap(Path(temp_path))
453+
assert blake3(input_bytes).digest() == hasher2.digest()
454+
455+
hasher3 = blake3(max_threads=4)
456+
hasher3.update_mmap(temp_path)
457+
hasher3.update_mmap(path=Path(temp_path))
458+
assert blake3(2 * input_bytes).digest() == hasher3.digest()

0 commit comments

Comments
 (0)