~homeworkprod/byceps

ref: ee44f550bd6c9f49e72424cd5826669dd1f57c1c byceps/tests/unit/util/test_instances.py -rw-r--r-- 1.5 KiB
ee44f550 — Jochen Kupperschmidt Avoid same German translation for different meanings of "cancel" 1 year, 6 months ago
                                                                                
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
"""
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from byceps.util.instances import ReprBuilder


def test_without_any_values():
    instance = Instance()

    actual = ReprBuilder(instance).build()

    assert actual == '<Instance()>'


def test_with_looked_up_values():
    instance = Instance()

    actual = ReprBuilder(instance) \
        .add_with_lookup('first_name') \
        .add_with_lookup('last_name') \
        .add_with_lookup('age') \
        .add_with_lookup('delivers_pizza') \
        .add_with_lookup('favorite_customer') \
        .build()

    assert actual == "<Instance(first_name='Hiro', last_name='Protagonist', age=26, delivers_pizza=True, favorite_customer=None)>"


def test_with_given_value():
    instance = Instance()

    actual = ReprBuilder(instance) \
        .add_with_lookup('last_name') \
        .add('last_name length', 11) \
        .build()

    assert actual == "<Instance(last_name='Protagonist', last_name length=11)>"


def test_with_custom_value():
    instance = Instance()

    actual = ReprBuilder(instance) \
        .add('last_name', 'Protagonist') \
        .add_custom('is of full age') \
        .build()

    assert actual == "<Instance(last_name='Protagonist', is of full age)>"


class Instance:

    def __init__(self):
        self.first_name = 'Hiro'
        self.last_name = 'Protagonist'
        self.age = 26
        self.delivers_pizza = True
        self.favorite_customer = None