|
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 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
|
|
|
|
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.