-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestBrickPiWrapper.py
More file actions
60 lines (46 loc) · 1.74 KB
/
TestBrickPiWrapper.py
File metadata and controls
60 lines (46 loc) · 1.74 KB
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
# Tests for BrickPiWrapper
#
# Copyright (c) 2014 Charles Weir. Shared under the MIT Licence.
# Run tests as
# python TestBrickPiWrapper.py
# or, if you've got it installed:
# nosetests
# Install mock and nosetests on pi or mac using:
# sudo easy_install nose
# sudo easy_install mock
from BrickPython.BrickPiWrapper import BrickPiWrapper
from BrickPython.BrickPi import BrickPi, PORT_1, TYPE_SENSOR_ULTRASONIC_CONT,\
TYPE_SENSOR_RAW
from BrickPython.Sensor import Sensor
import unittest
class TestBrickPiWrapper(unittest.TestCase):
def testClassExists(self):
assert(BrickPiWrapper() != None)
def testAllMethodsOK(self):
bp = BrickPiWrapper({'1': Sensor})
for c in range(ord('A'),ord('D')):
assert( bp.motor(chr(c)) != None)
m = bp.motor('A')
assert( m.power() == 0 )
assert( m.idChar == 'A' )
m.setPower(1)
assert( m.power() == 1 )
assert( not m.enabled() )
m.enable( True )
assert( m.enabled() )
assert( m.position() != None )
bp.update()
s = bp.sensor('1')
assert( isinstance( s.value(), int ) )
assert( s.idChar == '1' )
def testSensorSetup(self):
bp = BrickPiWrapper( {PORT_1: TYPE_SENSOR_ULTRASONIC_CONT} )
assert( BrickPi.SensorType[PORT_1] == TYPE_SENSOR_ULTRASONIC_CONT)
def testSensorSetupBetterScopingSyntax(self):
bp = BrickPiWrapper( {'1': Sensor.ULTRASONIC_CONT} )
self.assertEquals( BrickPi.SensorType[PORT_1], TYPE_SENSOR_ULTRASONIC_CONT)
def testSensorSetupWithSensorObject(self):
bp = BrickPiWrapper( {PORT_1: Sensor})
self.assertEquals( BrickPi.SensorType[PORT_1], TYPE_SENSOR_RAW)
if __name__ == '__main__':
unittest.main()