|
1 | 1 | import pathlib |
| 2 | +from tempfile import TemporaryDirectory |
2 | 3 | from typing import Any |
3 | 4 |
|
4 | 5 | import magic |
|
8 | 9 | delete_callback, |
9 | 10 | get_content_mimetype, |
10 | 11 | get_file_mimetype, |
| 12 | + path_from, |
11 | 13 | ) |
12 | 14 |
|
13 | 15 |
|
@@ -54,3 +56,42 @@ def test_delete_callback(tmp_path: pathlib.Path): |
54 | 56 | delete_callback(fpath) |
55 | 57 |
|
56 | 58 | assert not fpath.exists() |
| 59 | + |
| 60 | + |
| 61 | +def test_path_from_tmp_dir(): |
| 62 | + tempdir = TemporaryDirectory() |
| 63 | + with path_from(tempdir) as tmp_dir: |
| 64 | + file = tmp_dir / "file.txt" |
| 65 | + file.touch() |
| 66 | + assert file.exists() |
| 67 | + assert pathlib.Path(tempdir.name).exists() |
| 68 | + |
| 69 | + assert not pathlib.Path(tempdir.name).exists() |
| 70 | + |
| 71 | + |
| 72 | +def test_path_from_path(): |
| 73 | + tempdir = TemporaryDirectory() |
| 74 | + tempdir_path = pathlib.Path(tempdir.name) |
| 75 | + with path_from(tempdir_path) as tmp_dir: |
| 76 | + file = tmp_dir / "file.txt" |
| 77 | + file.touch() |
| 78 | + assert file.exists() |
| 79 | + assert pathlib.Path(tempdir.name).exists() |
| 80 | + |
| 81 | + assert pathlib.Path(tempdir.name).exists() |
| 82 | + tempdir.cleanup() |
| 83 | + assert not pathlib.Path(tempdir.name).exists() |
| 84 | + |
| 85 | + |
| 86 | +def test_path_from_str(): |
| 87 | + tempdir = TemporaryDirectory() |
| 88 | + tempdir_path = pathlib.Path(tempdir.name) |
| 89 | + with path_from(str(tempdir_path)) as tmp_dir: |
| 90 | + file = tmp_dir / "file.txt" |
| 91 | + file.touch() |
| 92 | + assert file.exists() |
| 93 | + assert pathlib.Path(tempdir.name).exists() |
| 94 | + |
| 95 | + assert pathlib.Path(tempdir.name).exists() |
| 96 | + tempdir.cleanup() |
| 97 | + assert not pathlib.Path(tempdir.name).exists() |
0 commit comments