summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qaudio.py
diff options
context:
space:
mode:
authorHector Fernandez <hector@iatec.biz>2020-07-01 10:45:34 +0200
committerHector Fernandez <hector@iatec.biz>2020-07-01 10:45:34 +0200
commit34df86b37d6838b115e65e5f3a332344afeb86b8 (patch)
tree946e1d7d6d55a4339e453c84c4fbbf4b785a1712 /test-cli/test/tests/qaudio.py
parent9ac8a326412b04e4873b883c2f2a056ca0b22480 (diff)
downloadboard-34df86b37d6838b115e65e5f3a332344afeb86b8.zip
board-34df86b37d6838b115e65e5f3a332344afeb86b8.tar.gz
board-34df86b37d6838b115e65e5f3a332344afeb86b8.tar.bz2
Changes to adapt to new way to save results in DB. Created audio test. Added protections against unexpected status in DB.
Diffstat (limited to 'test-cli/test/tests/qaudio.py')
-rw-r--r--test-cli/test/tests/qaudio.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/test-cli/test/tests/qaudio.py b/test-cli/test/tests/qaudio.py
new file mode 100644
index 0000000..5baffe4
--- /dev/null
+++ b/test-cli/test/tests/qaudio.py
@@ -0,0 +1,59 @@
+import unittest
+import sh
+import wave
+import contextlib
+
+
+def calc_audio_duration(fname):
+ with contextlib.closing(wave.open(fname, 'r')) as f:
+ frames = f.getnframes()
+ rate = f.getframerate()
+ duration = frames / float(rate)
+ f.close()
+ return duration
+
+
+class Qaudio(unittest.TestCase):
+ params = None
+ __resultlist = None # resultlist is a python list of python dictionaries
+ __dtmf_secuence = ["1", "3", "5", "7", "9"]
+
+ def __init__(self, testname, testfunc, varlist):
+ self.params = varlist
+ super(Qaudio, self).__init__(testfunc)
+ self._testMethodDoc = testname
+ self.__resultlist = []
+
+ def execute(self):
+ # analize audio file
+ recordtime = calc_audio_duration("test/files/dtmf-13579.wav") + 0.15
+ # play and record
+ p1 = sh.aplay("test/files/dtmf-13579.wav", _bg=True)
+ p2 = sh.arecord("-r", 8000, "-d", recordtime, "/tmp/station/recorded.wav", _bg=True)
+ p1.wait()
+ p2.wait()
+ if p1.exit_code == 0 and p2.exit_code == 0:
+ p = sh.multimon("-t", "wav", "-a", "DTMF", "/tmp/station/recorded.wav", "-q")
+ if p.exit_code == 0:
+ lines = p.stdout.decode('ascii').splitlines()
+ self.__dtmf_secuence_result = []
+ for li in lines:
+ if li.split(" ")[0] == "DTMF:":
+ self.__dtmf_secuence_result.append(li.split(" ")[1])
+ # compare original and processed dtmf sequence
+ if len(self.__dtmf_secuence) == len(self.__dtmf_secuence_result):
+ for i in range(len(self.__dtmf_secuence)):
+ if self.__dtmf_secuence[i] != self.__dtmf_secuence_result[i]:
+ self.fail("failed: sent and received DTMF sequence don't match.")
+ else:
+ self.fail("failed: received DTMF sequence is shorter than expected.")
+ else:
+ self.fail("failed: unable to use multimon command.")
+ else:
+ self.fail("failed: unable to play/record audio.")
+
+ def getresults(self):
+ return self.__resultlist
+
+ def gettextresult(self):
+ return ""