Coverage for shared/test_shared_input.py: 100%

59 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-05-12 11:24 -0400

1import pytest 

2 

3from birdbrain_exception import BirdbrainException 

4from birdbrain_finch import BirdbrainFinch 

5from birdbrain_hummingbird import BirdbrainHummingbird 

6 

7def helper_test_acceleration(device): 

8 response = device.acceleration() 

9 response = device.getAcceleration() 

10 

11 assert (-100.0 <= response[0] <= 100.0) 

12 assert (-100.0 <= response[1] <= 100.0) 

13 assert (-100.0 <= response[2] <= 100.0) 

14 

15 assert isinstance(response[0], float) 

16 assert isinstance(response[1], float) 

17 assert isinstance(response[2], float) 

18 

19def helper_test_compass(device): 

20 response = device.compass() 

21 response = device.getCompass() 

22 

23 assert (0 <= response <= 359) 

24 assert isinstance(response, int) 

25 

26def helper_test_magnetometer(device): 

27 response = device.magnetometer() 

28 response = device.getMagnetometer() 

29 

30 assert (-100 <= response[0] <= 100) 

31 assert (-100 <= response[1] <= 100) 

32 assert (-100 <= response[2] <= 100) 

33 

34 assert isinstance(response[0], int) 

35 assert isinstance(response[1], int) 

36 assert isinstance(response[2], int) 

37 

38def helper_test_button(device): 

39 assert not device.button("A") 

40 assert not device.button("B") 

41 assert not device.button("LOGO") 

42 assert not device.button("Logo") 

43 assert not device.getButton("logo") 

44 

45 with pytest.raises(BirdbrainException) as e: 

46 device.button("BAD") 

47 assert e.value.message == "Error: Request to device failed" 

48 

49def helper_test_sound(device): 

50 response = device.sound(3) 

51 response = device.getSound(3) 

52 

53 assert (0 <= response <= 100) 

54 

55def helper_test_temperature(device): 

56 response = device.temperature() 

57 response = device.getTemperature() 

58 

59 assert (0 <= response <= 50) 

60 

61def helper_test_is_shaking(device): 

62 response = device.is_shaking() 

63 response = device.isShaking() 

64 

65 assert not response 

66 

67def helper_test_shared(device): 

68 helper_test_acceleration(device) 

69 helper_test_compass(device) 

70 helper_test_magnetometer(device) 

71 helper_test_button(device) 

72 helper_test_sound(device) 

73 helper_test_temperature(device) 

74 helper_test_is_shaking(device) 

75 

76def test_shared(): 

77 helper_test_shared(BirdbrainHummingbird("A")) 

78 helper_test_shared(BirdbrainFinch("B"))