diff options
author | Greg Ward <gward@python.net> | 2006-07-23 02:25:53 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 2006-07-23 02:25:53 (GMT) |
commit | 7802af426eee29071b9aaa23297119ca71d091f9 (patch) | |
tree | 3a7557526d2f5c698170637c81f4bf0b6d331444 | |
parent | cde0fa9c61192d5bfdcc065c85a53b02fb9e4197 (diff) | |
download | cpython-7802af426eee29071b9aaa23297119ca71d091f9.zip cpython-7802af426eee29071b9aaa23297119ca71d091f9.tar.gz cpython-7802af426eee29071b9aaa23297119ca71d091f9.tar.bz2 |
Be a lot smarter about whether this test passes: instead of assuming
that a 2.93 sec audio file will always take 3.1 sec (as it did on the
hardware I had when I first wrote the test), expect that it will take
2.93 sec +/- 10%, and only fail if it's outside of that range.
Compute the expected
-rw-r--r-- | Lib/test/output/test_ossaudiodev | 3 | ||||
-rw-r--r-- | Lib/test/test_ossaudiodev.py | 15 |
2 files changed, 14 insertions, 4 deletions
diff --git a/Lib/test/output/test_ossaudiodev b/Lib/test/output/test_ossaudiodev index 9f55afa..f0df5d2 100644 --- a/Lib/test/output/test_ossaudiodev +++ b/Lib/test/output/test_ossaudiodev @@ -1,3 +1,2 @@ test_ossaudiodev -playing test sound file... -elapsed time: 3.1 sec +playing test sound file (expected running time: 2.93 sec) diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index 8810516..9f64406 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -69,14 +69,25 @@ def play_sound_file(data, rate, ssize, nchannels): except TypeError: pass + # Compute expected running time of sound sample (in seconds). + expected_time = float(len(data)) / (ssize/8) / nchannels / rate + # set parameters based on .au file headers dsp.setparameters(AFMT_S16_NE, nchannels, rate) + print ("playing test sound file (expected running time: %.2f sec)" + % expected_time) t1 = time.time() - print "playing test sound file..." dsp.write(data) dsp.close() t2 = time.time() - print "elapsed time: %.1f sec" % (t2-t1) + elapsed_time = t2 - t1 + + percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100 + #print ("actual running time was %.2f sec (%.1f%% difference)" + # % (elapsed_time, percent_diff)) + assert percent_diff <= 10.0, \ + ("elapsed time (%.2f sec) > 10%% off of expected time (%.2f sec)" + % (elapsed_time, expected_time)) def test_setparameters(dsp): # Two configurations for testing: |