Lichen

Annotated tests/attr_providers.py

580:e703b981b9b1
2017-02-13 Paul Boddie Eliminated redundant struct usage. method-wrapper-for-context
paul@2 1
class C:
paul@2 2
    def __init__(self):
paul@2 3
        self.a = 1
paul@252 4
        self.c = 3
paul@2 5
paul@2 6
    b = 2
paul@2 7
paul@2 8
class D:
paul@2 9
    def __init__(self):
paul@2 10
        self.a = 3
paul@2 11
        self.b = 4
paul@2 12
paul@2 13
class E:
paul@2 14
    a = 5
paul@2 15
    b = 6
paul@2 16
paul@2 17
def f(x):
paul@2 18
    return x.a, x.b
paul@2 19
paul@107 20
def g(x):
paul@107 21
paul@107 22
    # Should only permit D instance and E.
paul@107 23
paul@107 24
    x.a = 7
paul@107 25
    x.b = 8
paul@252 26
    return f(x)
paul@252 27
paul@252 28
def h(x):
paul@252 29
    x.c
paul@252 30
    x.a = 4
paul@252 31
    x.b
paul@252 32
    return f(x)
paul@107 33
paul@2 34
c = C()
paul@2 35
d = D()
paul@2 36
e = E()
paul@2 37
paul@252 38
print f(c)          # (1, 2)
paul@252 39
print f(d)          # (3, 4)
paul@252 40
print f(e)          # (5, 6)
paul@252 41
print f(E)          # (5, 6)
paul@252 42
paul@252 43
try:
paul@252 44
    print g(c)      # should fail with an error caused by a test
paul@252 45
except TypeError:
paul@252 46
    print "g(c): c is not a suitable argument."
paul@252 47
paul@252 48
print g(d)          # (7, 8)
paul@252 49
paul@252 50
try:
paul@252 51
    print g(e)      # should fail with an error caused by a test
paul@252 52
except TypeError:
paul@252 53
    print "g(e): e is not a suitable argument."
paul@252 54
paul@252 55
print g(E)          # (7, 8)
paul@252 56
paul@315 57
print h(c)          # (4, 2)