forked from djhedges/exit_speed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgyroscope_test.py
executable file
·53 lines (46 loc) · 1.75 KB
/
gyroscope_test.py
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
#!/usr/bin/python3
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Unitests for gyroscope.py"""
import sys
import mock
import unittest
from absl.testing import absltest
# pylint: disable=wrong-import-position
# Fixes dotstar import on Travis.
import fake_rpi
sys.modules['RPi'] = fake_rpi.RPi # Fake RPi
sys.modules['RPi.GPIO'] = fake_rpi.RPi.GPIO # Fake GPIO
sys.modules['smbus'] = fake_rpi.smbus # Fake smbus (I2C)
import adafruit_platformdetect
with mock.patch.object(adafruit_platformdetect, 'Detector') as mock_detector:
mock_detector.chip.id.return_value = 'BCM2XXX'
import adafruit_fxas21002c
import busio
import gyroscope
# pylint: enable=wrong-import-position
class TestGyroscope(unittest.TestCase):
"""Gyroscope unittests."""
def setUp(self):
super().setUp()
with mock.patch.object(busio, 'I2C'):
with mock.patch.object(adafruit_fxas21002c, 'FXAS21002C'):
self.gyroscope = gyroscope.Gyroscope()
def testGetRotationalValues(self):
self.gyroscope.sensor.gyroscope = (
0.024816400301794373, -0.27052603405912107, -0.9467047653591117)
expected = (1.421875, -15.5, -54.2421875)
self.assertTupleEqual(expected, self.gyroscope.GetRotationalValues())
if __name__ == '__main__':
absltest.main()