-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.py
More file actions
90 lines (54 loc) · 2.96 KB
/
timer_test.py
File metadata and controls
90 lines (54 loc) · 2.96 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
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
import unittest
import json
import timer
import time
class TimerTest(unittest.TestCase):
def testTimeInSecondsOfSpeech(self):
timeToEnd = time.time() + 600 # 10 minute timer
timeInMinutesToAlarm = "1"
timeOfAlarm = timer.timeInSecondsOfSpeech(timeInMinutesToAlarm,timeToEnd)
expectedTimeOfAlarm = timeToEnd - 60
self.assertEqual(expectedTimeOfAlarm, timeOfAlarm)
def testTimeInSecondsOfSpeechWithSeconds(self):
timeToEnd = time.time() + 600 # 10 minute timer
timeInMinutesToAlarm = "1:10"
timeOfAlarm = timer.timeInSecondsOfSpeech(timeInMinutesToAlarm,timeToEnd)
expectedTimeOfAlarm = timeToEnd - 70
self.assertEqual(expectedTimeOfAlarm, timeOfAlarm)
def testBuildMapForSpeakTimeTest(self):
#set the time to end to be 5 minutes from now
currentTime = time.time()
timeToEnd = currentTime + (5 *60)
inputData = '{"speaktime":[{"time":"5", "say":"GO"}, {"time":"1","say":"1 minute remaining"}]}'
#inputData = '{"speaktime":"123"}'
inputData = json.loads(inputData)
speakTimeList = inputData["speaktime"]
#print("inputData:" + speakTimeList[0]["time"] )
speakTestMap = timer.buildMapForSpeakTime(timeToEnd, speakTimeList)
strTime = str(currentTime)
# since our test data is a five minute timer, then it should have an entry for current time
self.assertEqual(speakTestMap[strTime]["phrase"], "GO")
#self.assertEqual(speakTestMap["1"], "1 minute remaining")
def testBuildMapForSpeakTimeWithParamsTest(self):
#set the time to end to be 5 minutes from now
currentTime = time.time()
timeToEnd = currentTime + (5 *60)
inputData = '{"speaktime":[{"time":"5", "say":"GO", "parms":"-s 100"}, {"time":"1","say":"1 minute remaining", "parms":"-s 100"}]}'
#inputData = '{"speaktime":"123"}'
inputData = json.loads(inputData)
speakTimeList = inputData["speaktime"]
#print("inputData:" + speakTimeList[0]["time"] )
speakTestMap = timer.buildMapForSpeakTime(timeToEnd, speakTimeList)
strTime = str(currentTime)
speakDict = speakTestMap[strTime]
# since our test data is a five minute timer, then it should have an entry for current time
self.assertEqual(speakDict["phrase"], "GO")
#self.assertEqual(speakTestMap["1"], "1 minute remaining")
def testBuildMapForSpeakIntervalTest(self):
inputData = '{"speakinterval":[{"interval":"5", "say":"%min% Minutes Remaining, %min% Minutes."}]}'
inputData = json.loads(inputData)
speakTimeList = inputData["speakinterval"]
speakIntervalMap = timer.buildMapForSpeakInterval(speakTimeList)
self.assertEqual(speakIntervalMap["5"], "%min% Minutes Remaining, %min% Minutes.")
if __name__ == '__main__':
unittest.main()