# Coverage for drone.py : 79%

## 63 statements 53 run 10 missing 0 excluded 5 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | from time import sleep from random import randint class HexacopterStatus: def __init__(self, motor_speed, is_turned_on): self.motor_speed = motor_speed self.is_turned_on = is_turned_on class Hexacopter: MIN_MOTOR_SPEED = 0 MAX_MOTOR_SPEED = 500 def __init__(self): self._motor_speed = self.__class__.MIN_MOTOR_SPEED self._is_turned_on = False @property def motor_speed(self): return self._motor_speed @motor_speed.setter def motor_speed(self, value): 25 ↛ 26 line 25 didn't jump to line 26, because the condition on line 25 was never true if value < self.__class__.MIN_MOTOR_SPEED: raise ValueError('The minimum speed is {0}'.format(self.__class__.MIN_MOTOR_SPEED)) 27 ↛ 28 line 27 didn't jump to line 28, because the condition on line 27 was never true if value > self.__class__.MAX_MOTOR_SPEED: raise ValueError('The maximum speed is {0}'.format(self.__class__.MAX_MOTOR_SPEED)) self._motor_speed = value self._is_turned_on = (self.motor_speed is not 0) sleep(2) @property def is_turned_on(self): return self._is_turned_on @property def status(self): sleep(3) return HexacopterStatus(self.motor_speed, self.is_turned_on) class LightEmittingDiode: MIN_BRIGHTNESS_LEVEL = 0 MAX_BRIGHTNESS_LEVEL = 255 def __init__(self, id, description): self.id = id self.description = description self._brightness_level = self.__class__.MIN_BRIGHTNESS_LEVEL @property def brightness_level(self): sleep(1) return self._brightness_level @brightness_level.setter def brightness_level(self, value): 59 ↛ 60 line 59 didn't jump to line 60, because the condition on line 59 was never true if value < self.__class__.MIN_BRIGHTNESS_LEVEL: raise ValueError('The minimum brightness level is {0}'.format(self.__class__.MIN_BRIGHTNESS_LEVEL)) 61 ↛ 62 line 61 didn't jump to line 62, because the condition on line 61 was never true if value > self.__class__.MAX_BRIGHTNESS_LEVEL: raise ValueError('The maximum brightness level is {0}'.format(self.__class__.MAX_BRIGHTNESS_LEVEL)) sleep(2) self._brightness_level = value class Altimeter: @property def altitude(self): sleep(1) return randint(0, 3000) class Drone: def __init__(self): self.hexacopter = Hexacopter() self.altimeter = Altimeter() self.red_led = LightEmittingDiode(1, 'Red LED') self.green_led = LightEmittingDiode(2, 'Green LED') self.blue_led = LightEmittingDiode(3, 'Blue LED') self.leds = { self.red_led.id: self.red_led, self.green_led.id: self.green_led, self.blue_led.id: self.blue_led} 87 ↛ 88 line 87 didn't jump to line 88, because the condition on line 87 was never true if __name__ == '__main__': hexacopter = Hexacopter() hexacopter.motor_speed = 100 print(hexacopter.is_turned_on) print(hexacopter.motor_speed) print(hexacopter.status.motor_speed) print(hexacopter.status.is_turned_on)