Completed
Push — develop ( 3dc72f...07ede0 )
by Jace
02:06
created

tests.SampleWithMagicMethods   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 9
Duplicated Lines 0 %
Metric Value
dl 0
loc 9
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __setattr__() 0 4 2
A __init__() 0 2 1
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