Discussion:
[Python-3000-checkins] r65734 - in python/branches/py3k/Lib: sunau.py test/test_ossaudiodev.py
antoine.pitrou
2008-08-17 00:38:32 UTC
Permalink
Author: antoine.pitrou
Date: Sun Aug 17 02:38:32 2008
New Revision: 65734

Log:
#3567: fix sunau for running with -bb and make test_ossaudiodev work.



Modified:
python/branches/py3k/Lib/sunau.py
python/branches/py3k/Lib/test/test_ossaudiodev.py

Modified: python/branches/py3k/Lib/sunau.py
==============================================================================
--- python/branches/py3k/Lib/sunau.py (original)
+++ python/branches/py3k/Lib/sunau.py Sun Aug 17 02:38:32 2008
@@ -135,7 +135,7 @@
x = 0
for i in range(4):
byte = file.read(1)
- if byte == '':
+ if not byte:
raise EOFError
x = x*256 + ord(byte)
return x
@@ -144,10 +144,9 @@
data = []
for i in range(4):
d, m = divmod(x, 256)
- data.insert(0, m)
+ data.insert(0, int(m))
x = d
- for i in range(4):
- file.write(chr(int(data[i])))
+ file.write(bytes(data))

class Au_read:

@@ -198,7 +197,7 @@
if self._hdr_size > 24:
self._info = file.read(self._hdr_size - 24)
for i in range(len(self._info)):
- if self._info[i] == '\0':
+ if self._info[i] == b'\0':
self._info = self._info[:i]
break
else:
@@ -451,7 +450,7 @@
_write_u32(self._file, self._framerate)
_write_u32(self._file, self._nchannels)
self._file.write(self._info)
- self._file.write('\0'*(header_size - len(self._info) - 24))
+ self._file.write(b'\0'*(header_size - len(self._info) - 24))

def _patchheader(self):
self._file.seek(8)

Modified: python/branches/py3k/Lib/test/test_ossaudiodev.py
==============================================================================
--- python/branches/py3k/Lib/test/test_ossaudiodev.py (original)
+++ python/branches/py3k/Lib/test/test_ossaudiodev.py Sun Aug 17 02:38:32 2008
@@ -57,7 +57,7 @@
dsp.fileno()

# Make sure the read-only attributes work.
- self.failUnless(dsp.close)
+ self.failIf(dsp.closed)
self.assertEqual(dsp.name, "/dev/dsp")
self.assertEqual(dsp.mode, "w", "bad dsp.mode: %r" % dsp.mode)

@@ -65,7 +65,7 @@
for attr in ('closed', 'name', 'mode'):
try:
setattr(dsp, attr, 42)
- except TypeError:
+ except (TypeError, AttributeError):
pass
else:
self.fail("dsp.%s not read-only" % attr)
@@ -75,7 +75,7 @@

# set parameters based on .au file headers
dsp.setparameters(AFMT_S16_NE, nchannels, rate)
- self.assertEquals("%.2f" % expected_time, "2.93")
+ self.assertTrue(abs(expected_time - 2.94) < 1e-2, expected_time)
t1 = time.time()
dsp.write(data)
dsp.close()

Loading...