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

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

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 9 months ago
Right Patch Set: Created 5 years, 6 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 26 matching lines...) Expand all
37 37
38 # Convert the data to 16-bit signed. 38 # Convert the data to 16-bit signed.
39 data = audioop.ulaw2lin(data, 2) 39 data = audioop.ulaw2lin(data, 2)
40 return (data, rate, 16, nchannels) 40 return (data, rate, 16, nchannels)
41 41
42 class OSSAudioDevTests(unittest.TestCase): 42 class OSSAudioDevTests(unittest.TestCase):
43 43
44 def play_sound_file(self, data, rate, ssize, nchannels): 44 def play_sound_file(self, data, rate, ssize, nchannels):
45 try: 45 try:
46 dsp = ossaudiodev.open('w') 46 dsp = ossaudiodev.open('w')
47 except IOError as msg: 47 except OSError as msg:
48 if msg.args[0] in (errno.EACCES, errno.ENOENT, 48 if msg.args[0] in (errno.EACCES, errno.ENOENT,
49 errno.ENODEV, errno.EBUSY): 49 errno.ENODEV, errno.EBUSY):
50 raise unittest.SkipTest(msg) 50 raise unittest.SkipTest(msg)
51 raise 51 raise
52 52
53 # at least check that these methods can be invoked 53 # at least check that these methods can be invoked
54 dsp.bufsize() 54 dsp.bufsize()
55 dsp.obufcount() 55 dsp.obufcount()
56 dsp.obuffree() 56 dsp.obuffree()
57 dsp.getptr() 57 dsp.getptr()
(...skipping 11 matching lines...) Expand all
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 self.assertRaises(ValueError, dsp.obuffree) 183 self.assertRaises(ValueError, dsp.obuffree)
184 self.assertRaises(ValueError, dsp.getptr) 184 self.assertRaises(ValueError, dsp.getptr)
185 185
186 mixer = ossaudiodev.openmixer() 186 mixer = ossaudiodev.openmixer()
187 mixer.close() 187 mixer.close()
188 self.assertRaises(ValueError, mixer.fileno) 188 self.assertRaises(ValueError, mixer.fileno)
189 189
190 def test_main(): 190 def test_main():
191 try: 191 try:
192 dsp = ossaudiodev.open('w') 192 dsp = ossaudiodev.open('w')
193 except (ossaudiodev.error, IOError) 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+