summaryrefslogtreecommitdiff
path: root/t/unit/test_matcher.py
blob: 37ae5207a22dd0ef21b6691800d93bac9c02f201 (plain)
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
from __future__ import annotations

import pytest

from kombu.matcher import (MatcherNotInstalled, fnmatch, match, register,
                           registry, rematch, unregister)


class test_Matcher:

    def test_register_match_unregister_matcher(self):
        register("test_matcher", rematch)
        registry.matcher_pattern_first.append("test_matcher")
        assert registry._matchers["test_matcher"] == rematch
        assert match("data", r"d.*", "test_matcher") is not None
        assert registry._default_matcher == fnmatch
        registry._set_default_matcher("test_matcher")
        assert registry._default_matcher == rematch
        unregister("test_matcher")
        assert "test_matcher" not in registry._matchers
        registry._set_default_matcher("glob")
        assert registry._default_matcher == fnmatch

    def test_unregister_matcher_not_registered(self):
        with pytest.raises(MatcherNotInstalled):
            unregister('notinstalled')

    def test_match_using_unregistered_matcher(self):
        with pytest.raises(MatcherNotInstalled):
            match("data", r"d.*", "notinstalled")