From 4d16b915aa58efc62ed098080fd00c42f5fa0770 Mon Sep 17 00:00:00 2001 From: Greg Ward Date: Tue, 25 Jul 2006 02:11:12 +0000 Subject: Don't use standard assert: want tests to fail even when run with -O. Delete cruft. --- Lib/test/test_ossaudiodev.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index 9f64406..d2f63ae 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -40,6 +40,10 @@ def read_sound_file(path): data = audioop.ulaw2lin(data, 2) return (data, rate, 16, nchannels) +# version of assert that still works with -O +def _assert(expr, message=None): + if not expr: + raise AssertionError(message or "assertion failed") def play_sound_file(data, rate, ssize, nchannels): try: @@ -57,9 +61,9 @@ def play_sound_file(data, rate, ssize, nchannels): dsp.fileno() # Make sure the read-only attributes work. - assert dsp.closed is False, "dsp.closed is not False" - assert dsp.name == "/dev/dsp" - assert dsp.mode == 'w', "bad dsp.mode: %r" % dsp.mode + _assert(dsp.closed is False, "dsp.closed is not False") + _assert(dsp.name == "/dev/dsp") + _assert(dsp.mode == 'w', "bad dsp.mode: %r" % dsp.mode) # And make sure they're really read-only. for attr in ('closed', 'name', 'mode'): @@ -83,11 +87,9 @@ def play_sound_file(data, rate, ssize, nchannels): 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)) + _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: @@ -112,11 +114,11 @@ def test_setparameters(dsp): # setparameters() should be able to set this configuration in # either strict or non-strict mode. result = dsp.setparameters(fmt, channels, rate, False) - assert result == (fmt, channels, rate), \ - "setparameters%r: returned %r" % (config + result) + _assert(result == (fmt, channels, rate), + "setparameters%r: returned %r" % (config + result)) result = dsp.setparameters(fmt, channels, rate, True) - assert result == (fmt, channels, rate), \ - "setparameters%r: returned %r" % (config + result) + _assert(result == (fmt, channels, rate), + "setparameters%r: returned %r" % (config + result)) def test_bad_setparameters(dsp): @@ -134,8 +136,8 @@ def test_bad_setparameters(dsp): ]: (fmt, channels, rate) = config result = dsp.setparameters(fmt, channels, rate, False) - assert result != config, \ - "setparameters: unexpectedly got requested configuration" + _assert(result != config, + "setparameters: unexpectedly got requested configuration") try: result = dsp.setparameters(fmt, channels, rate, True) @@ -156,6 +158,6 @@ def test(): #test_bad_setparameters(dsp) finally: dsp.close() - assert dsp.closed is True, "dsp.closed is not True" + _assert(dsp.closed is True, "dsp.closed is not True") test() -- cgit v0.12