|
2 | 2 | from binascii import unhexlify
|
3 | 3 | import json
|
4 | 4 | import numpy
|
| 5 | +import os |
5 | 6 | from pathlib import Path
|
6 | 7 | import subprocess
|
7 | 8 | import sys
|
@@ -433,22 +434,25 @@ def test_module_name() -> None:
|
433 | 434 |
|
434 | 435 | def test_mmap() -> None:
|
435 | 436 | 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: |
437 | 442 | 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