|
15 | 15 | import fsspec
|
16 | 16 | from fsspec import compression
|
17 | 17 | from fsspec.core import OpenFile, get_fs_token_paths, open_files
|
18 |
| -from fsspec.implementations.local import LocalFileSystem, make_path_posix |
| 18 | +from fsspec.implementations.local import LocalFileSystem, get_umask, make_path_posix |
19 | 19 | from fsspec.tests.test_utils import WIN
|
20 | 20 |
|
21 | 21 | files = {
|
@@ -508,6 +508,60 @@ def test_commit_discard(tmpdir):
|
508 | 508 | assert not fs.exists(tmpdir + "/bfile")
|
509 | 509 |
|
510 | 510 |
|
| 511 | +def test_same_permissions_with_and_without_transaction(tmpdir): |
| 512 | + tmpdir = str(tmpdir) |
| 513 | + |
| 514 | + with fsspec.open(tmpdir + "/afile", "wb") as f: |
| 515 | + f.write(b"data") |
| 516 | + |
| 517 | + fs, urlpath = fsspec.core.url_to_fs(tmpdir + "/bfile") |
| 518 | + with fs.transaction, fs.open(urlpath, "wb") as f: |
| 519 | + f.write(b"data") |
| 520 | + |
| 521 | + assert fs.info(tmpdir + "/afile")["mode"] == fs.info(tmpdir + "/bfile")["mode"] |
| 522 | + |
| 523 | + |
| 524 | +def test_get_umask_uses_cache(): |
| 525 | + get_umask.cache_clear() # Clear the cache before the test for testing purposes. |
| 526 | + get_umask() # Retrieve the current umask value. |
| 527 | + get_umask() # Retrieve the umask again; this should result in a cache hit. |
| 528 | + assert get_umask.cache_info().hits == 1 |
| 529 | + |
| 530 | + |
| 531 | +def test_multiple_file_transaction_use_umask_cache(tmpdir): |
| 532 | + get_umask.cache_clear() # Clear the cache before the test for testing purposes. |
| 533 | + fs = LocalFileSystem() |
| 534 | + with fs.transaction: |
| 535 | + with fs.open(tmpdir + "/afile", "wb") as f: |
| 536 | + f.write(b"data") |
| 537 | + with fs.open(tmpdir + "/bfile", "wb") as f: |
| 538 | + f.write(b"data") |
| 539 | + assert get_umask.cache_info().hits == 1 |
| 540 | + |
| 541 | + |
| 542 | +def test_multiple_transactions_use_umask_cache(tmpdir): |
| 543 | + get_umask.cache_clear() # Clear the cache before the test for testing purposes. |
| 544 | + fs = LocalFileSystem() |
| 545 | + with fs.transaction: |
| 546 | + with fs.open(tmpdir + "/afile", "wb") as f: |
| 547 | + f.write(b"data") |
| 548 | + with fs.transaction: |
| 549 | + with fs.open(tmpdir + "/bfile", "wb") as f: |
| 550 | + f.write(b"data") |
| 551 | + assert get_umask.cache_info().hits == 1 |
| 552 | + |
| 553 | + |
| 554 | +def test_multiple_filesystems_use_umask_cache(tmpdir): |
| 555 | + get_umask.cache_clear() # Clear the cache before the test for testing purposes. |
| 556 | + fs1 = LocalFileSystem() |
| 557 | + fs2 = LocalFileSystem() |
| 558 | + with fs1.transaction, fs1.open(tmpdir + "/afile", "wb") as f: |
| 559 | + f.write(b"data") |
| 560 | + with fs2.transaction, fs2.open(tmpdir + "/bfile", "wb") as f: |
| 561 | + f.write(b"data") |
| 562 | + assert get_umask.cache_info().hits == 1 |
| 563 | + |
| 564 | + |
511 | 565 | def test_make_path_posix():
|
512 | 566 | cwd = os.getcwd()
|
513 | 567 | if WIN:
|
|
0 commit comments