Lichen

Annotated tests/attr_class.py

820:be4f3575f605
2018-01-08 Paul Boddie Added tests for attribute initialisation plus testing for duplicate parameters.
paul@792 1
class SignalState:
paul@792 2
    Red = 1
paul@792 3
    Amber = 2
paul@792 4
    Green = 3
paul@792 5
    AmberAgain = 4
paul@792 6
    Off = None
paul@792 7
paul@792 8
class Signal:
paul@792 9
    def __init__(self):
paul@792 10
        self.disable()
paul@792 11
paul@792 12
    def enable(self):
paul@792 13
        self.state = SignalState.Red
paul@792 14
paul@792 15
    def disable(self):
paul@792 16
        self.state = SignalState.Off
paul@792 17
paul@792 18
    def next(self):
paul@792 19
        if self.state == SignalState.Red:
paul@792 20
            self.state = SignalState.Amber
paul@792 21
        elif self.state == SignalState.Amber:
paul@792 22
            self.state = SignalState.Green
paul@792 23
        elif self.state == SignalState.Green:
paul@792 24
            self.state = SignalState.AmberAgain
paul@792 25
        elif self.state == SignalState.AmberAgain:
paul@792 26
            self.state = SignalState.Red
paul@792 27
        else:
paul@792 28
            self.state = SignalState.Off
paul@792 29
paul@792 30
s = Signal()
paul@792 31
print s.state   # None
paul@792 32
s.next()
paul@792 33
print s.state   # None
paul@792 34
s.enable()
paul@792 35
print s.state   # 1
paul@792 36
s.next()
paul@792 37
print s.state   # 2
paul@792 38
s.next()
paul@792 39
print s.state   # 3
paul@792 40
s.next()
paul@792 41
print s.state   # 4
paul@792 42
s.next()
paul@792 43
print s.state   # 1