File: test_folder.py

package info (click to toggle)
python-b2sdk 2.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,228 kB
  • sloc: python: 32,094; sh: 13; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 1,509 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
######################################################################
#
# File: test/unit/scan/test_folder.py
#
# Copyright 2025 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import platform
from pathlib import Path

import pytest

from b2sdk._internal.scan.exception import UnsupportedFilename
from b2sdk._internal.scan.folder import LocalFolder


@pytest.mark.skipif(
    platform.system() == 'Windows',
    reason="Windows doesn't allow / or \\ in filenames",
)
class TestFolder:
    @pytest.fixture
    def root_path(self, tmp_path: Path):
        return tmp_path / 'dir'

    @pytest.fixture
    def folder(self, root_path: Path):
        return LocalFolder(str(root_path))

    @pytest.mark.parametrize('file_path_str', ['dir/foo.txt', 'dir/foo/bar.txt', 'foo.txt'])
    def test_make_full_path(self, folder: LocalFolder, root_path: Path, file_path_str: str):
        file_path = root_path / file_path_str
        assert folder.make_full_path(str(file_path)) == str(root_path / file_path_str)

    @pytest.mark.parametrize('file_path_str', ['invalid/test.txt', 'dirinvalid.txt'])
    def test_make_full_path_invalid_prefix(
        self, folder: LocalFolder, tmp_path: Path, file_path_str: str
    ):
        file_path = tmp_path / file_path_str

        with pytest.raises(UnsupportedFilename):
            folder.make_full_path(str(file_path))