-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
executable file
·174 lines (129 loc) · 4.66 KB
/
tests.py
File metadata and controls
executable file
·174 lines (129 loc) · 4.66 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import time
from listener import Dictaphone, ButtonMonitor, Phone
import os
###### TEST THE DICTAPHONE OBJECT ######
test_playback = True
test_recording = False
###### TEST THE SIGNAL SENDER AND RECIEVER ######
test_signalman = False
###### TEST THE PHONE OBJECT, WITH BOTH OF THE ABOVE ######
test_phone = False
if test_playback or test_recording:
fname = "AUDIO_FILES/mortal_kombat.wav"
dic = Dictaphone(audio_dir='AUDIO_FILES')
if test_signalman:
signaller = ButtonMonitor(dummy_mode=True)
#### Playback #####
if test_playback:
print("Playing a random file...")
dic.start("play_random")
time.sleep(5)
# Interrupt playback
dic.interrupt_playback()
print("Interrupt sent\n -> Music should STOP")
time.sleep(5)
print("Restarting playback\n -> Music should BEGIN")
dic.start("play_file", fname)
time.sleep(5)
print("Trying to start playback over previous playback\n -> Music should CONTINUE, NOTHING should begin")
dic.start('play_random')
time.sleep(10)
dic.interrupt_playback()
print("Termination sent!\n -> Music should STOP")
time.sleep(5)
#### Recording ####
if test_recording:
print("Making a recording in the RECORDED dir, called TEST.wav, 10s long")
if os.path.isfile("AUDIO_FILES/RECORDED/TEST.wav"):
os.remove("AUDIO_FILES/RECORDED/TEST.wav")
dic.start('make_recording', 'TEST.wav')
print("Started!")
time.sleep(10)
dic.stop_recording()
print("Done!")
time.sleep(3)
print("Playing TEST.wav")
dic.start('play_file', 'AUDIO_FILES/RECORDED/TEST.wav')
time.sleep(10)
print("Done!")
time.sleep(3)
print("Starting playback, then a recording.")
print("Playback should BEGIN, then when recording starts, playback should STOP")
dic.start("play_file", 'AUDIO_FILES/DICTAPHONE_DIARIES/VN860028.wav')
time.sleep(5)
if os.path.isfile("AUDIO_FILES/RECORDED/TEST2.wav"):
os.remove("AUDIO_FILES/RECORDED/TEST2.wav")
dic.start("make_recording", "TEST2.wav")
time.sleep(10)
dic.stop_recording()
print("Recording over")
#### Signaller ####
if test_signalman:
print("THIS IS ALL OUTDATED AND NO LONGER TESTS ANYTHING!!!")
print("Time to test the signaller")
print("Pressing the button 1")
signaller.mock_pins[1].drive_low()
time.sleep(0.1)
print("Un-pressing 1")
signaller.mock_pins[1].drive_high()
time.sleep(2)
print("The signaller needs to handle functions for the following button:")
print(signaller.call_button)
print("\n\nRepeating the above, but lifting the handset first")
signaller.mock_pins[22].drive_low()
time.sleep(2)
print("Pressing the button 1")
signaller.mock_pins[1].drive_low()
time.sleep(0.5)
print("Un-pressing 1")
signaller.mock_pins[1].drive_high()
time.sleep(5)
print("The signaller needs to handle functions for the following button:")
print(signaller.call_button)
print("Sending signal that the button has been handled")
signaller.called_button()
print("The signaller needs to handle functions for the following button:")
print(signaller.call_button)
print("Testing the signallers' ability to track button sequence. Pressing the buttons B2, B3, B4...")
for i in range(2, 11):
signaller.mock_pins[i].drive_low()
time.sleep(0.1)
signaller.mock_pins[i].drive_high()
time.sleep(0.1)
print("The signaller wants us to parse the function for button {}".format(signaller.call_button))
print("Reducing verbosity to 3")
signaller.LOUD = 3
signaller.POLLING_RATE = 1.0
print("The signaller recorded the sequence:\n {}".format(signaller.sequence))
time.sleep(3)
print("Sending handset down")
signaller.mock_pins[0].drive_high()
time.sleep(2)
print("The signaller recorded the sequence:\n {}".format(signaller.sequence))
time.sleep(2)
print("Done testing signaller")
#### Phone as a whole ####
if test_phone:
phone = Phone("AUDIO_FILES")
print("\n\n\nStarting phone. Should have the monitor begin reporting")
phone.start()
time.sleep(3)
print("Pressing B2 on the monitor")
phone.monitor.mock_pins[2].drive_low()
time.sleep(2)
print("Releasing B2 on the monitor")
phone.monitor.mock_pins[2].drive_high()
time.sleep(5)
print("Lifting handset")
phone.monitor.mock_pins[0].drive_low()
time.sleep(2)
print("Pressing B2 on the monitor")
phone.monitor.mock_pins[2].drive_low()
time.sleep(2)
phone.monitor.mock_pins[2].drive_high()
time.sleep(5)
print("Replacing handset")
phone.monitor.mock_pins[0].drive_high()
time.sleep(5)
phone.stop()
print("Done testing.")