File: base_test.py

package info (click to toggle)
python-pook 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 3,558; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 1,103 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
import pytest

from pook.matchers.base import BaseMatcher


class _BaseMatcher(BaseMatcher):
    def match(self, x):
        pass


def test_base_matcher_instance():
    matcher = _BaseMatcher("foo")
    assert matcher.name == "_BaseMatcher"
    assert matcher.negate is False
    assert matcher.expectation == "foo"
    assert matcher.to_dict() == {"_BaseMatcher": "foo"}
    assert matcher.__repr__() == "_BaseMatcher(foo)"
    assert matcher.__str__() == "foo"


def test_base_matcher_compare():
    assert _BaseMatcher("foo").compare("foo", "foo")

    assert _BaseMatcher("foo").compare("foo", "foo")

    with pytest.raises(AssertionError):
        assert _BaseMatcher("foo").compare("foo", "bar")


def test_base_matcher_exceptions():
    assert _BaseMatcher("foo").match(None) is None

    with pytest.raises(ValueError, match="expectation argument cannot be empty"):
        _BaseMatcher(None)


def test_base_matcher_matcher():
    assert BaseMatcher.matcher(lambda x: True)(BaseMatcher)

    matcher = _BaseMatcher("foo", negate=True)
    assert BaseMatcher.matcher(lambda x: False)(matcher)