File: test_conftest.py

package info (click to toggle)
sentry-python 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,004 kB
  • sloc: python: 55,908; makefile: 114; sh: 111; xml: 2
file content (107 lines) | stat: -rw-r--r-- 3,409 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pytest


@pytest.mark.parametrize(
    "test_string, expected_result",
    [
        # type matches
        ("dogs are great!", True),  # full containment - beginning
        ("go, dogs, go!", True),  # full containment - middle
        ("I like dogs", True),  # full containment - end
        ("dogs", True),  # equality
        ("", False),  # reverse containment
        ("dog", False),  # reverse containment
        ("good dog!", False),  # partial overlap
        ("cats", False),  # no overlap
        # type mismatches
        (1231, False),
        (11.21, False),
        ([], False),
        ({}, False),
        (True, False),
    ],
)
def test_string_containing(
    test_string, expected_result, StringContaining  # noqa: N803
):
    assert (test_string == StringContaining("dogs")) is expected_result


@pytest.mark.parametrize(
    "test_dict, expected_result",
    [
        # type matches
        ({"dogs": "yes", "cats": "maybe", "spiders": "nope"}, True),  # full containment
        ({"dogs": "yes", "cats": "maybe"}, True),  # equality
        ({}, False),  # reverse containment
        ({"dogs": "yes"}, False),  # reverse containment
        ({"dogs": "yes", "birds": "only outside"}, False),  # partial overlap
        ({"coyotes": "from afar"}, False),  # no overlap
        # type mismatches
        ('{"dogs": "yes", "cats": "maybe"}', False),
        (1231, False),
        (11.21, False),
        ([], False),
        (True, False),
    ],
)
def test_dictionary_containing(
    test_dict, expected_result, DictionaryContaining  # noqa: N803
):
    assert (
        test_dict == DictionaryContaining({"dogs": "yes", "cats": "maybe"})
    ) is expected_result


class Animal:  # noqa: B903
    def __init__(self, name=None, age=None, description=None):
        self.name = name
        self.age = age
        self.description = description


class Dog(Animal):
    pass


class Cat(Animal):
    pass


@pytest.mark.parametrize(
    "test_obj, type_and_attrs_result, type_only_result, attrs_only_result",
    [
        # type matches
        (Dog("Maisey", 7, "silly"), True, True, True),  # full attr containment
        (Dog("Maisey", 7), True, True, True),  # type and attr equality
        (Dog(), False, True, False),  # reverse attr containment
        (Dog("Maisey"), False, True, False),  # reverse attr containment
        (Dog("Charlie", 7, "goofy"), False, True, False),  # partial attr overlap
        (Dog("Bodhi", 6, "floppy"), False, True, False),  # no attr overlap
        # type mismatches
        (Cat("Maisey", 7), False, False, True),  # attr equality
        (Cat("Piper", 1, "doglike"), False, False, False),
        ("Good girl, Maisey", False, False, False),
        ({"name": "Maisey", "age": 7}, False, False, False),
        (1231, False, False, False),
        (11.21, False, False, False),
        ([], False, False, False),
        (True, False, False, False),
    ],
)
def test_object_described_by(
    test_obj,
    type_and_attrs_result,
    type_only_result,
    attrs_only_result,
    ObjectDescribedBy,  # noqa: N803
):
    assert (
        test_obj == ObjectDescribedBy(type=Dog, attrs={"name": "Maisey", "age": 7})
    ) is type_and_attrs_result

    assert (test_obj == ObjectDescribedBy(type=Dog)) is type_only_result

    assert (
        test_obj == ObjectDescribedBy(attrs={"name": "Maisey", "age": 7})
    ) is attrs_only_result