Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(32952)

Delta Between Two Patch Sets: Lib/test/test_ossaudiodev.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years ago
Right Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_os.py ('k') | Lib/test/test_peepholer.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from test import support 1 from test import support
2 support.requires('audio') 2 support.requires('audio')
3 3
4 from test.support import findfile 4 from test.support import findfile
5 5
6 ossaudiodev = support.import_module('ossaudiodev') 6 ossaudiodev = support.import_module('ossaudiodev')
7 7
8 import errno 8 import errno
9 import sys 9 import sys
10 import sunau 10 import sunau
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 except (TypeError, AttributeError): 69 except (TypeError, AttributeError):
70 pass 70 pass
71 else: 71 else:
72 self.fail("dsp.%s not read-only" % attr) 72 self.fail("dsp.%s not read-only" % attr)
73 73
74 # Compute expected running time of sound sample (in seconds). 74 # Compute expected running time of sound sample (in seconds).
75 expected_time = float(len(data)) / (ssize/8) / nchannels / rate 75 expected_time = float(len(data)) / (ssize/8) / nchannels / rate
76 76
77 # set parameters based on .au file headers 77 # set parameters based on .au file headers
78 dsp.setparameters(AFMT_S16_NE, nchannels, rate) 78 dsp.setparameters(AFMT_S16_NE, nchannels, rate)
79 self.assertLess(abs(expected_time - 3.51), 1e-2, expected_time) 79 self.assertAlmostEqual(expected_time, 3.51, delta=1e-2)
80 t1 = time.time() 80 t1 = time.time()
81 dsp.write(data) 81 dsp.write(data)
82 dsp.close() 82 dsp.close()
83 t2 = time.time() 83 t2 = time.time()
84 elapsed_time = t2 - t1 84 elapsed_time = t2 - t1
85 85
86 percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100 86 percent_diff = (abs(elapsed_time - expected_time) / expected_time) * 100
87 self.assertLessEqual(percent_diff, 10.0, 87 self.assertLessEqual(percent_diff, 10.0,
88 "elapsed time (%s) > 10%% off of expected time (%s)" % 88 "elapsed time (%s) > 10%% off of expected time (%s)" %
89 (elapsed_time, expected_time)) 89 (elapsed_time, expected_time))
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 except (ossaudiodev.error, OSError) as msg: 193 except (ossaudiodev.error, OSError) as msg:
194 if msg.args[0] in (errno.EACCES, errno.ENOENT, 194 if msg.args[0] in (errno.EACCES, errno.ENOENT,
195 errno.ENODEV, errno.EBUSY): 195 errno.ENODEV, errno.EBUSY):
196 raise unittest.SkipTest(msg) 196 raise unittest.SkipTest(msg)
197 raise 197 raise
198 dsp.close() 198 dsp.close()
199 support.run_unittest(__name__) 199 support.run_unittest(__name__)
200 200
201 if __name__ == "__main__": 201 if __name__ == "__main__":
202 test_main() 202 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+