|
6 | 6 | from filesender.request_types import GuestOptions |
7 | 7 | from filesender.benchmark import make_tempfile, make_tempfiles, benchmark |
8 | 8 |
|
| 9 | +def count_files_recursively(path: Path) -> int: |
| 10 | + """ |
| 11 | + Returns a recursive count of the number of files within a directory. Subdirectories are not counted. |
| 12 | + """ |
| 13 | + return sum([1 if child.is_file() else 0 for child in path.rglob("*")]) |
9 | 14 |
|
10 | 15 | @pytest.mark.asyncio |
11 | 16 | async def test_round_trip(base_url: str, username: str, apikey: str, recipient: str): |
@@ -34,7 +39,7 @@ async def test_round_trip(base_url: str, username: str, apikey: str, recipient: |
34 | 39 | file_id=transfer["files"][0]["id"], |
35 | 40 | out_dir=Path(download_dir), |
36 | 41 | ) |
37 | | - assert len(list(Path(download_dir).iterdir())) == 1 |
| 42 | + assert count_files_recursively(Path(download_dir)) == 1 |
38 | 43 |
|
39 | 44 |
|
40 | 45 | @pytest.mark.asyncio |
@@ -62,7 +67,7 @@ async def test_round_trip_dir(base_url: str, username: str, apikey: str, recipie |
62 | 67 | token=transfer["recipients"][0]["token"], |
63 | 68 | out_dir=Path(download_dir), |
64 | 69 | ) |
65 | | - assert len(list(Path(download_dir).iterdir())) == 2 |
| 70 | + assert count_files_recursively(Path(download_dir)) == 2 |
66 | 71 |
|
67 | 72 |
|
68 | 73 | @pytest.mark.asyncio |
@@ -113,7 +118,7 @@ async def test_voucher_round_trip( |
113 | 118 | file_id=transfer["files"][0]["id"], |
114 | 119 | out_dir=Path(download_dir), |
115 | 120 | ) |
116 | | - assert len(list(Path(download_dir).iterdir())) == 1 |
| 121 | + assert count_files_recursively(Path(download_dir)) == 1 |
117 | 122 |
|
118 | 123 |
|
119 | 124 | @pytest.mark.asyncio |
|
0 commit comments