Completed
Push — develop ( 86b58f...0a86d2 )
by Jace
03:19
created

tests/test_mapped_signature.py (1 issue)

1
"""Integration tests to ensure a mapped object's signature remains unchanged."""
2
# pylint: disable=redefined-outer-name,unused-variable,expression-not-assigned
3
4
import pytest
5
from expecter import expect
6
7
from yorm import decorators
8
9
10
class SampleWithMagicMethods:
11
12
    def __init__(self):
13
        self.values = []
14
15
    def __setattr__(self, name, value):
16
        if name == 'foobar':
17
            self.values.append(('__setattr__', name, value))
18
        super().__setattr__(name, value)
19
20
21
@pytest.yield_fixture
22
def mapped():
23
    import yorm
24
    yorm.settings.fake = True
25
    yield decorators.sync(SampleWithMagicMethods(), "sample.yml")
26
    yorm.settings.fake = False
27
28
29
@pytest.fixture
30
def unmapped():
31
    return SampleWithMagicMethods()
32
33
34
def fuzzy_repr(obj):
35
    return repr(obj).split(" object at ")[0] + ">"
36
37
38
def describe_mapped_object():
39
40
    def it_retains_representation(mapped, unmapped):
41
        expect(fuzzy_repr(mapped)) == fuzzy_repr(unmapped)
42
43
    def it_retains_docstring(mapped, unmapped):
44
        expect(mapped.__doc__) == unmapped.__doc__
45
46
    def it_retains_class(mapped, unmapped):
47
        expect(mapped.__class__) == unmapped.__class__
48
49
    def it_retains_magic_methods(mapped):
50
        setattr(mapped, 'foobar', 42)
51
        expect(mapped.values) == [('__setattr__', 'foobar', 42)]
52
53
    def it_does_not_affect_unmapped_objects(mapped, unmapped):
0 ignored issues
show
Coding Style Naming introduced by
The name it_does_not_affect_unmapped_objects does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
54
        expect(hasattr(mapped, '__mapper__')) is True
55
        expect(hasattr(unmapped, '__mapper__')) is False
56
        expect(hasattr(mapped.__setattr__, '_modified_by_yorm')) is True
57
        expect(hasattr(unmapped.__setattr__, '_modified_by_yorm')) is False
58