File: test_filter.py

package info (click to toggle)
python-b2sdk 2.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,020 kB
  • sloc: python: 30,902; sh: 13; makefile: 8
file content (39 lines) | stat: -rw-r--r-- 1,374 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
######################################################################
#
# File: test/unit/filter/test_filter.py
#
# Copyright 2024 Backblaze Inc. All Rights Reserved.
#
# License https://www.backblaze.com/using_b2_code.html
#
######################################################################
from __future__ import annotations

import pytest
from apiver_deps import Filter

from b2sdk._internal.filter import FilterMatcher


@pytest.mark.parametrize(
    ('filters', 'expr', 'expected'),
    (
        ([], 'a', True),
        ([Filter.exclude('*')], 'something', False),
        ([Filter.include('a-*')], 'a-', True),
        ([Filter.include('a-*')], 'b-', False),
        ([Filter.exclude('*.txt')], 'a.txt', False),
        ([Filter.exclude('*.txt')], 'a.csv', True),
        ([Filter.exclude('*'), Filter.include('*.[ct]sv')], 'a.csv', True),
        ([Filter.exclude('*'), Filter.include('*.[ct]sv')], 'a.tsv', True),
        ([Filter.exclude('*'), Filter.include('*.[ct]sv')], 'a.ksv', False),
        (
            [Filter.exclude('*'), Filter.include('*.[ct]sv'), Filter.exclude('a.csv')],
            'a.csv',
            False,
        ),
        ([Filter.exclude('*'), Filter.include('*.[ct]sv'), Filter.exclude('a.csv')], 'b.csv', True),
    ),
)
def test_filter_matcher(filters, expr, expected):
    assert FilterMatcher(filters).match(expr) == expected