[Python-3000-checkins] r56261 - python/branches/py3k-struni/Lib/ctypes/test/test_buffers.py python/branches/py3k-struni/Lib/ctypes/test/test_byteswap.py python/branches/py3k-struni/Lib/ctypes/test/test_numbers.py

thomas.heller python-3000-checkins at python.org
Wed Jul 11 14:25:26 CEST 2007


Author: thomas.heller
Date: Wed Jul 11 14:25:26 2007
New Revision: 56261

Modified:
   python/branches/py3k-struni/Lib/ctypes/test/test_buffers.py
   python/branches/py3k-struni/Lib/ctypes/test/test_byteswap.py
   python/branches/py3k-struni/Lib/ctypes/test/test_numbers.py
Log:
Fix some simple ctypes tests.

Modified: python/branches/py3k-struni/Lib/ctypes/test/test_buffers.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_buffers.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_buffers.py	Wed Jul 11 14:25:26 2007
@@ -7,12 +7,12 @@
         b = create_string_buffer(32)
         self.failUnlessEqual(len(b), 32)
         self.failUnlessEqual(sizeof(b), 32 * sizeof(c_char))
-        self.failUnless(type(b[0]) is str)
+        self.failUnless(type(b[0]) is str8)
 
         b = create_string_buffer("abc")
         self.failUnlessEqual(len(b), 4) # trailing nul char
         self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
-        self.failUnless(type(b[0]) is str)
+        self.failUnless(type(b[0]) is str8)
         self.failUnlessEqual(b[0], "a")
         self.failUnlessEqual(b[:], "abc\0")
 
@@ -20,7 +20,7 @@
         b = create_string_buffer("abc")
         self.failUnlessEqual(len(b), 4) # trailing nul char
         self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
-        self.failUnless(type(b[0]) is str)
+        self.failUnless(type(b[0]) is str8)
         self.failUnlessEqual(b[0], "a")
         self.failUnlessEqual(b[:], "abc\0")
 

Modified: python/branches/py3k-struni/Lib/ctypes/test/test_byteswap.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_byteswap.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_byteswap.py	Wed Jul 11 14:25:26 2007
@@ -4,7 +4,7 @@
 from ctypes import *
 
 def bin(s):
-    return hexlify(buffer(s)).upper()
+    return str(hexlify(buffer(s))).upper()
 
 # Each *simple* type that supports different byte orders has an
 # __ctype_be__ attribute that specifies the same type in BIG ENDIAN

Modified: python/branches/py3k-struni/Lib/ctypes/test/test_numbers.py
==============================================================================
--- python/branches/py3k-struni/Lib/ctypes/test/test_numbers.py	(original)
+++ python/branches/py3k-struni/Lib/ctypes/test/test_numbers.py	Wed Jul 11 14:25:26 2007
@@ -12,10 +12,10 @@
     for t in types:
         fmt = t._type_
         size = struct.calcsize(fmt)
-        a = struct.unpack(fmt, ("\x00"*32)[:size])[0]
-        b = struct.unpack(fmt, ("\xFF"*32)[:size])[0]
-        c = struct.unpack(fmt, ("\x7F"+"\x00"*32)[:size])[0]
-        d = struct.unpack(fmt, ("\x80"+"\xFF"*32)[:size])[0]
+        a = struct.unpack(fmt, (b"\x00"*32)[:size])[0]
+        b = struct.unpack(fmt, (b"\xFF"*32)[:size])[0]
+        c = struct.unpack(fmt, (b"\x7F"+b"\x00"*32)[:size])[0]
+        d = struct.unpack(fmt, (b"\x80"+b"\xFF"*32)[:size])[0]
         result.append((min(a, b, c, d), max(a, b, c, d)))
     return result
 
@@ -174,13 +174,14 @@
         from ctypes import c_char
         from array import array
 
-        a = array('c', 'x')
+        a = array('b', [0])
+        a[0] = ord('x')
         v = c_char.from_address(a.buffer_info()[0])
-        self.failUnlessEqual(v.value, a[0])
+        self.failUnlessEqual(v.value, 'x')
         self.failUnless(type(v) is c_char)
 
-        a[0] = '?'
-        self.failUnlessEqual(v.value, a[0])
+        a[0] = ord('?')
+        self.failUnlessEqual(v.value, '?')
 
     # array does not support c_bool / 't'
     # def test_bool_from_address(self):


More information about the Python-3000-checkins mailing list