|
| 1 | +###################################################################### |
| 2 | +# |
| 3 | +# File: test/unit/scan/test_folder.py |
| 4 | +# |
| 5 | +# Copyright 2025 Backblaze Inc. All Rights Reserved. |
| 6 | +# |
| 7 | +# License https://www.backblaze.com/using_b2_code.html |
| 8 | +# |
| 9 | +###################################################################### |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +import platform |
| 13 | +from pathlib import Path |
| 14 | + |
| 15 | +import pytest |
| 16 | + |
| 17 | +from b2sdk._internal.scan.exception import UnsupportedFilename |
| 18 | +from b2sdk._internal.scan.folder import LocalFolder |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.skipif( |
| 22 | + platform.system() == 'Windows', |
| 23 | + reason="Windows doesn't allow / or \\ in filenames", |
| 24 | +) |
| 25 | +class TestFolder: |
| 26 | + @pytest.fixture |
| 27 | + def root_path(self, tmp_path: Path): |
| 28 | + return tmp_path / 'dir' |
| 29 | + |
| 30 | + @pytest.fixture |
| 31 | + def folder(self, root_path: Path): |
| 32 | + return LocalFolder(str(root_path)) |
| 33 | + |
| 34 | + @pytest.mark.parametrize('file_path_str', ['dir/foo.txt', 'dir/foo/bar.txt', 'foo.txt']) |
| 35 | + def test_make_full_path(self, folder: LocalFolder, root_path: Path, file_path_str: str): |
| 36 | + file_path = root_path / file_path_str |
| 37 | + assert folder.make_full_path(str(file_path)) == str(root_path / file_path_str) |
| 38 | + |
| 39 | + @pytest.mark.parametrize('file_path_str', ['invalid/test.txt', 'dirinvalid.txt']) |
| 40 | + def test_make_full_path_invalid_prefix( |
| 41 | + self, folder: LocalFolder, tmp_path: Path, file_path_str: str |
| 42 | + ): |
| 43 | + file_path = tmp_path / file_path_str |
| 44 | + |
| 45 | + with pytest.raises(UnsupportedFilename): |
| 46 | + folder.make_full_path(str(file_path)) |
0 commit comments