[Python-checkins] r50775 - in python/trunk/Lib/test: output/test_ossaudiodev test_ossaudiodev.py

greg.ward python-checkins at python.org
Sun Jul 23 04:25:54 CEST 2006


Author: greg.ward
Date: Sun Jul 23 04:25:53 2006
New Revision: 50775

Modified:
   python/trunk/Lib/test/output/test_ossaudiodev
   python/trunk/Lib/test/test_ossaudiodev.py
Log:
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 


Modified: python/trunk/Lib/test/output/test_ossaudiodev
==============================================================================
--- python/trunk/Lib/test/output/test_ossaudiodev	(original)
+++ python/trunk/Lib/test/output/test_ossaudiodev	Sun Jul 23 04:25:53 2006
@@ -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)

Modified: python/trunk/Lib/test/test_ossaudiodev.py
==============================================================================
--- python/trunk/Lib/test/test_ossaudiodev.py	(original)
+++ python/trunk/Lib/test/test_ossaudiodev.py	Sun Jul 23 04:25:53 2006
@@ -69,14 +69,25 @@
         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:


More information about the Python-checkins mailing list