Completed
Push — develop ( 2e9112...0af8d5 )
by Jace
01:53
created

tests.it_does_not_affect_unmapped_objects()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
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
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
6
7
from yorm import utilities
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 utilities.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):
54
        expect(hasattr(mapped, '__mapper__')) is True
55
        expect(hasattr(unmapped, '__mapper__')) is False
56