Whitespace normalization.

This commit is contained in:
Tim Peters 2006-03-09 01:15:05 +00:00
parent b31c8142d5
commit e8d09e5818
25 changed files with 86 additions and 88 deletions

View File

@ -76,13 +76,13 @@ def c_buffer(init, size=None):
_c_functype_cache = {} _c_functype_cache = {}
def CFUNCTYPE(restype, *argtypes): def CFUNCTYPE(restype, *argtypes):
"""CFUNCTYPE(restype, *argtypes) -> function prototype. """CFUNCTYPE(restype, *argtypes) -> function prototype.
restype: the result type restype: the result type
argtypes: a sequence specifying the argument types argtypes: a sequence specifying the argument types
The function prototype can be called in three ways to create a The function prototype can be called in three ways to create a
callable object: callable object:
prototype(funct) - returns a C callable function calling funct prototype(funct) - returns a C callable function calling funct
prototype(vtbl_index, method_name[, paramflags]) - a Python callable that calls a COM method prototype(vtbl_index, method_name[, paramflags]) - a Python callable that calls a COM method
prototype(funct_name, dll[, paramflags]) - a Python callable that calls an exported function in a dll prototype(funct_name, dll[, paramflags]) - a Python callable that calls an exported function in a dll
@ -139,7 +139,7 @@ class c_long(_SimpleCData):
class c_ulong(_SimpleCData): class c_ulong(_SimpleCData):
_type_ = "L" _type_ = "L"
if _calcsize("i") == _calcsize("l"): if _calcsize("i") == _calcsize("l"):
# if int and long have the same size, make c_int an alias for c_long # if int and long have the same size, make c_int an alias for c_long
c_int = c_long c_int = c_long
@ -153,7 +153,7 @@ else:
class c_float(_SimpleCData): class c_float(_SimpleCData):
_type_ = "f" _type_ = "f"
class c_double(_SimpleCData): class c_double(_SimpleCData):
_type_ = "d" _type_ = "d"
@ -327,7 +327,7 @@ class PyDLL(CDLL):
_restype_ = c_int # default, can be overridden in instances _restype_ = c_int # default, can be overridden in instances
if _os.name in ("nt", "ce"): if _os.name in ("nt", "ce"):
class WinDLL(CDLL): class WinDLL(CDLL):
"""This class represents a dll exporting functions using the """This class represents a dll exporting functions using the
Windows stdcall calling convention. Windows stdcall calling convention.
@ -351,7 +351,7 @@ if _os.name in ("nt", "ce"):
# doesn't have a way to raise an exception in the caller's # doesn't have a way to raise an exception in the caller's
# frame). # frame).
_check_retval_ = _check_HRESULT _check_retval_ = _check_HRESULT
class OleDLL(CDLL): class OleDLL(CDLL):
"""This class represents a dll exporting functions using the """This class represents a dll exporting functions using the
Windows stdcall calling convention, and returning HRESULT. Windows stdcall calling convention, and returning HRESULT.
@ -424,7 +424,7 @@ else:
Return the string at addr.""" Return the string at addr."""
return _wstring_at(ptr, size) return _wstring_at(ptr, size)
if _os.name == "nt": # COM stuff if _os.name == "nt": # COM stuff
def DllGetClassObject(rclsid, riid, ppv): def DllGetClassObject(rclsid, riid, ppv):

View File

@ -55,4 +55,3 @@ elif sys.byteorder == "big":
else: else:
raise RuntimeError("Invalid byteorder") raise RuntimeError("Invalid byteorder")

View File

@ -151,7 +151,7 @@ class LibraryLoader(object):
except ValueError: except ValueError:
raise OSError("Library %s could not be found" % libname) raise OSError("Library %s could not be found" % libname)
return self.load_library(pathname, mode) return self.load_library(pathname, mode)
elif os.name == "posix": elif os.name == "posix":
# Posix # Posix
def _plat_load_version(self, name, version, mode): def _plat_load_version(self, name, version, mode):

View File

@ -83,7 +83,7 @@ def test_with_refcounts(runner, verbosity, testcase):
ptc = ctypes._pointer_type_cache.copy() ptc = ctypes._pointer_type_cache.copy()
cfc = ctypes._c_functype_cache.copy() cfc = ctypes._c_functype_cache.copy()
wfc = ctypes._win_functype_cache.copy() wfc = ctypes._win_functype_cache.copy()
# when searching for refcount leaks, we have to manually reset any # when searching for refcount leaks, we have to manually reset any
# caches that ctypes has. # caches that ctypes has.
def cleanup(): def cleanup():

View File

@ -8,7 +8,7 @@ def dump(obj):
# between the bytes. # between the bytes.
h = hexlify(buffer(obj)) h = hexlify(buffer(obj))
return re.sub(r"(..)", r"\1-", h)[:-1] return re.sub(r"(..)", r"\1-", h)[:-1]
class Value(Structure): class Value(Structure):
_fields_ = [("val", c_byte)] _fields_ = [("val", c_byte)]

View File

@ -15,7 +15,7 @@ class BITS(Structure):
("G", c_int, 7), ("G", c_int, 7),
("H", c_int, 8), ("H", c_int, 8),
("I", c_int, 9), ("I", c_int, 9),
("M", c_short, 1), ("M", c_short, 1),
("N", c_short, 2), ("N", c_short, 2),
("O", c_short, 3), ("O", c_short, 3),
@ -62,7 +62,7 @@ class BitFieldTest(unittest.TestCase):
x = X() x = X()
x.a, x.b, x.c = -1, 7, -1 x.a, x.b, x.c = -1, 7, -1
self.failUnlessEqual((x.a, x.b, x.c), (-1, 7, -1)) self.failUnlessEqual((x.a, x.b, x.c), (-1, 7, -1))
def test_ulonglong(self): def test_ulonglong(self):
class X(Structure): class X(Structure):
_fields_ = [("a", c_ulonglong, 1), _fields_ = [("a", c_ulonglong, 1),
@ -79,7 +79,7 @@ class BitFieldTest(unittest.TestCase):
for c_typ in signed_int_types: for c_typ in signed_int_types:
class X(Structure): class X(Structure):
_fields_ = [("dummy", c_typ), _fields_ = [("dummy", c_typ),
("a", c_typ, 3), ("a", c_typ, 3),
("b", c_typ, 3), ("b", c_typ, 3),
("c", c_typ, 1)] ("c", c_typ, 1)]
self.failUnlessEqual(sizeof(X), sizeof(c_typ)*2) self.failUnlessEqual(sizeof(X), sizeof(c_typ)*2)

View File

@ -8,14 +8,14 @@ class StringBufferTestCase(unittest.TestCase):
self.failUnlessEqual(len(b), 32) self.failUnlessEqual(len(b), 32)
self.failUnlessEqual(sizeof(b), 32 * sizeof(c_char)) self.failUnlessEqual(sizeof(b), 32 * sizeof(c_char))
self.failUnless(type(b[0]) is str) self.failUnless(type(b[0]) is str)
b = create_string_buffer("abc") b = create_string_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char)) self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
self.failUnless(type(b[0]) is str) self.failUnless(type(b[0]) is str)
self.failUnlessEqual(b[0], "a") self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0") self.failUnlessEqual(b[:], "abc\0")
def test_string_conversion(self): def test_string_conversion(self):
b = create_string_buffer(u"abc") b = create_string_buffer(u"abc")
self.failUnlessEqual(len(b), 4) # trailing nul char self.failUnlessEqual(len(b), 4) # trailing nul char

View File

@ -11,7 +11,7 @@ def bin(s):
# byte order, and a __ctype_le__ attribute that is the same type in # byte order, and a __ctype_le__ attribute that is the same type in
# LITTLE ENDIAN byte order. # LITTLE ENDIAN byte order.
# #
# For Structures and Unions, these types are created on demand. # For Structures and Unions, these types are created on demand.
class Test(unittest.TestCase): class Test(unittest.TestCase):
def X_test(self): def X_test(self):

View File

@ -3,7 +3,7 @@ from ctypes import *
import _ctypes_test import _ctypes_test
class Callbacks(unittest.TestCase): class Callbacks(unittest.TestCase):
functype = CFUNCTYPE functype = CFUNCTYPE
## def tearDown(self): ## def tearDown(self):
## import gc ## import gc
@ -130,7 +130,7 @@ class SampleCallbacksTestCase(unittest.TestCase):
result = integrate(0.0, 1.0, CALLBACK(func), 10) result = integrate(0.0, 1.0, CALLBACK(func), 10)
diff = abs(result - 1./3.) diff = abs(result - 1./3.)
self.failUnless(diff < 0.01, "%s not less than 0.01" % diff) self.failUnless(diff < 0.01, "%s not less than 0.01" % diff)
################################################################ ################################################################

View File

@ -122,6 +122,6 @@ class CFuncPtrTestCase(unittest.TestCase):
self.failUnlessEqual(strtok(None, "\n"), "b") self.failUnlessEqual(strtok(None, "\n"), "b")
self.failUnlessEqual(strtok(None, "\n"), "c") self.failUnlessEqual(strtok(None, "\n"), "c")
self.failUnlessEqual(strtok(None, "\n"), None) self.failUnlessEqual(strtok(None, "\n"), None)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -28,14 +28,14 @@ class FunctionTestCase(unittest.TestCase):
# But in early versions of _ctypes.c, the result of tp_new # But in early versions of _ctypes.c, the result of tp_new
# wasn't checked, and it even crashed Python. # wasn't checked, and it even crashed Python.
# Found by Greg Chapman. # Found by Greg Chapman.
try: try:
class X(object, Array): class X(object, Array):
_length_ = 5 _length_ = 5
_type_ = "i" _type_ = "i"
except TypeError: except TypeError:
pass pass
from _ctypes import _Pointer from _ctypes import _Pointer
try: try:
@ -105,7 +105,7 @@ class FunctionTestCase(unittest.TestCase):
result = f(1, 2, 3, 4, 5.0, 6.0) result = f(1, 2, 3, 4, 5.0, 6.0)
self.failUnlessEqual(result, 21) self.failUnlessEqual(result, 21)
self.failUnlessEqual(type(result), int) self.failUnlessEqual(type(result), int)
result = f(1, 2, 3, 0x10004, 5.0, 6.0) result = f(1, 2, 3, 0x10004, 5.0, 6.0)
self.failUnlessEqual(result, 21) self.failUnlessEqual(result, 21)
self.failUnlessEqual(type(result), int) self.failUnlessEqual(type(result), int)
@ -124,7 +124,7 @@ class FunctionTestCase(unittest.TestCase):
result = f(-1, -2, -3, -4, -5.0, -6.0) result = f(-1, -2, -3, -4, -5.0, -6.0)
self.failUnlessEqual(result, -21) self.failUnlessEqual(result, -21)
self.failUnlessEqual(type(result), float) self.failUnlessEqual(type(result), float)
def test_doubleresult(self): def test_doubleresult(self):
f = dll._testfunc_d_bhilfd f = dll._testfunc_d_bhilfd
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
@ -136,7 +136,7 @@ class FunctionTestCase(unittest.TestCase):
result = f(-1, -2, -3, -4, -5.0, -6.0) result = f(-1, -2, -3, -4, -5.0, -6.0)
self.failUnlessEqual(result, -21) self.failUnlessEqual(result, -21)
self.failUnlessEqual(type(result), float) self.failUnlessEqual(type(result), float)
def test_longlongresult(self): def test_longlongresult(self):
try: try:
c_longlong c_longlong
@ -226,7 +226,7 @@ class FunctionTestCase(unittest.TestCase):
self.failUnlessEqual(args, expected) self.failUnlessEqual(args, expected)
################################################################ ################################################################
def test_callbacks(self): def test_callbacks(self):
f = dll._testfunc_callback_i_if f = dll._testfunc_callback_i_if
@ -237,7 +237,7 @@ class FunctionTestCase(unittest.TestCase):
def callback(value): def callback(value):
#print "called back with", value #print "called back with", value
return value return value
cb = MyCallback(callback) cb = MyCallback(callback)
result = f(-10, cb) result = f(-10, cb)
self.failUnlessEqual(result, -18) self.failUnlessEqual(result, -18)
@ -247,7 +247,7 @@ class FunctionTestCase(unittest.TestCase):
cb = MyCallback(callback) cb = MyCallback(callback)
result = f(-10, cb) result = f(-10, cb)
self.failUnlessEqual(result, -18) self.failUnlessEqual(result, -18)
AnotherCallback = WINFUNCTYPE(c_int, c_int, c_int, c_int, c_int) AnotherCallback = WINFUNCTYPE(c_int, c_int, c_int, c_int, c_int)
# check that the prototype works: we call f with wrong # check that the prototype works: we call f with wrong
@ -271,7 +271,7 @@ class FunctionTestCase(unittest.TestCase):
#print "called back with", value #print "called back with", value
self.failUnlessEqual(type(value), int) self.failUnlessEqual(type(value), int)
return value return value
cb = MyCallback(callback) cb = MyCallback(callback)
result = f(-10, cb) result = f(-10, cb)
self.failUnlessEqual(result, -18) self.failUnlessEqual(result, -18)

View File

@ -130,7 +130,7 @@ class PointerToStructure(unittest.TestCase):
("b", POINTER(POINT))] ("b", POINTER(POINT))]
r = RECT() r = RECT()
p1 = POINT(1, 2) p1 = POINT(1, 2)
r.a = pointer(p1) r.a = pointer(p1)
r.b = pointer(p1) r.b = pointer(p1)
## from pprint import pprint as pp ## from pprint import pprint as pp

View File

@ -36,13 +36,13 @@ It'll have output like this:
from ctypes.macholib.dyld import dyld_find from ctypes.macholib.dyld import dyld_find
def find_lib(name): def find_lib(name):
possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name] possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name]
for dylib in possible: for dylib in possible:
try: try:
return os.path.realpath(dyld_find(dylib)) return os.path.realpath(dyld_find(dylib))
except ValueError: except ValueError:
pass pass
raise ValueError, "%s not found" % (name,) raise ValueError, "%s not found" % (name,)
class MachOTest(unittest.TestCase): class MachOTest(unittest.TestCase):
if sys.platform == "darwin": if sys.platform == "darwin":

View File

@ -34,14 +34,14 @@ except NameError:
else: else:
unsigned_types.append(c_ulonglong) unsigned_types.append(c_ulonglong)
signed_types.append(c_longlong) signed_types.append(c_longlong)
unsigned_ranges = valid_ranges(*unsigned_types) unsigned_ranges = valid_ranges(*unsigned_types)
signed_ranges = valid_ranges(*signed_types) signed_ranges = valid_ranges(*signed_types)
################################################################ ################################################################
class NumberTestCase(unittest.TestCase): class NumberTestCase(unittest.TestCase):
def test_default_init(self): def test_default_init(self):
# default values are set to zero # default values are set to zero
for t in signed_types + unsigned_types + float_types: for t in signed_types + unsigned_types + float_types:
@ -132,7 +132,7 @@ class NumberTestCase(unittest.TestCase):
# and alignment of an instance # and alignment of an instance
self.failUnlessEqual((code, alignment(t())), self.failUnlessEqual((code, alignment(t())),
(code, align)) (code, align))
def test_int_from_address(self): def test_int_from_address(self):
from array import array from array import array
for t in signed_types + unsigned_types: for t in signed_types + unsigned_types:
@ -152,7 +152,7 @@ class NumberTestCase(unittest.TestCase):
# changing the value at the memory location changes v's value also # changing the value at the memory location changes v's value also
a[0] = 42 a[0] = 42
self.failUnlessEqual(v.value, a[0]) self.failUnlessEqual(v.value, a[0])
def test_float_from_address(self): def test_float_from_address(self):
from array import array from array import array
@ -168,7 +168,7 @@ class NumberTestCase(unittest.TestCase):
def test_char_from_address(self): def test_char_from_address(self):
from ctypes import c_char from ctypes import c_char
from array import array from array import array
a = array('c', 'x') a = array('c', 'x')
v = c_char.from_address(a.buffer_info()[0]) v = c_char.from_address(a.buffer_info()[0])
self.failUnlessEqual(v.value, a[0]) self.failUnlessEqual(v.value, a[0])
@ -185,7 +185,7 @@ class NumberTestCase(unittest.TestCase):
## def test_perf(self): ## def test_perf(self):
## check_perf() ## check_perf()
from ctypes import _SimpleCData from ctypes import _SimpleCData
class c_int_S(_SimpleCData): class c_int_S(_SimpleCData):
_type_ = "i" _type_ = "i"
@ -227,7 +227,7 @@ def check_perf():
# c_int(): 3.35 us # c_int(): 3.35 us
# c_int(999): 3.34 us # c_int(999): 3.34 us
# c_int_S(): 3.23 us # c_int_S(): 3.23 us
# c_int_S(999): 3.24 us # c_int_S(999): 3.24 us
# Python 2.2 -OO, win2k, P4 700 MHz: # Python 2.2 -OO, win2k, P4 700 MHz:
# #

View File

@ -18,7 +18,7 @@ class SimpleTypesTestCase(unittest.TestCase):
pass pass
else: else:
set_conversion_mode(*self.prev_conv_mode) set_conversion_mode(*self.prev_conv_mode)
def test_subclasses(self): def test_subclasses(self):
from ctypes import c_void_p, c_char_p from ctypes import c_void_p, c_char_p

View File

@ -11,7 +11,7 @@ python_types = [int, int, int, int, int, long,
class PointersTestCase(unittest.TestCase): class PointersTestCase(unittest.TestCase):
def test_pointer_crash(self): def test_pointer_crash(self):
class A(POINTER(c_ulong)): class A(POINTER(c_ulong)):
pass pass
@ -84,7 +84,7 @@ class PointersTestCase(unittest.TestCase):
## print self.result ## print self.result
doit(callback) doit(callback)
## print self.result ## print self.result
def test_basics(self): def test_basics(self):
from operator import delitem from operator import delitem
for ct, pt in zip(ctype_types, python_types): for ct, pt in zip(ctype_types, python_types):
@ -132,7 +132,7 @@ class PointersTestCase(unittest.TestCase):
self.assertRaises(TypeError, len, p) self.assertRaises(TypeError, len, p)
self.failUnlessEqual(p[0], 42) self.failUnlessEqual(p[0], 42)
self.failUnlessEqual(p.contents.value, 42) self.failUnlessEqual(p.contents.value, 42)
def test_incomplete(self): def test_incomplete(self):
lpcell = POINTER("cell") lpcell = POINTER("cell")
class cell(Structure): class cell(Structure):
@ -166,6 +166,6 @@ class PointersTestCase(unittest.TestCase):
result = func( byref(argc), argv ) result = func( byref(argc), argv )
assert result == 'world', result assert result == 'world', result
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -10,7 +10,7 @@ if os.name == "posix" and sys.platform == "linux2":
def test_GL(self): def test_GL(self):
cdll.load('libGL.so', mode=RTLD_GLOBAL) cdll.load('libGL.so', mode=RTLD_GLOBAL)
cdll.load('libGLU.so') cdll.load('libGLU.so')
##if os.name == "posix" and sys.platform != "darwin": ##if os.name == "posix" and sys.platform != "darwin":
## # On platforms where the default shared library suffix is '.so', ## # On platforms where the default shared library suffix is '.so',

View File

@ -44,7 +44,7 @@ class CharPointersTestCase(unittest.TestCase):
func.argtypes = POINTER(c_int), func.argtypes = POINTER(c_int),
self.failUnlessEqual(addressof(ci), func(byref(ci))) self.failUnlessEqual(addressof(ci), func(byref(ci)))
func.argtypes = c_char_p, func.argtypes = c_char_p,
self.assertRaises(ArgumentError, func, byref(ci)) self.assertRaises(ArgumentError, func, byref(ci))
@ -73,7 +73,7 @@ class CharPointersTestCase(unittest.TestCase):
func = testdll._testfunc_p_p func = testdll._testfunc_p_p
func.restype = c_char_p func.restype = c_char_p
func.argtypes = c_char_p, func.argtypes = c_char_p,
self.failUnlessEqual(None, func(None)) self.failUnlessEqual(None, func(None))
self.failUnlessEqual("123", func("123")) self.failUnlessEqual("123", func("123"))
self.failUnlessEqual(None, func(c_char_p(None))) self.failUnlessEqual(None, func(c_char_p(None)))

View File

@ -48,7 +48,7 @@ class RefcountTestCase(unittest.TestCase):
# and may release it again # and may release it again
del f del f
self.failUnless(grc(func) >= 2) self.failUnless(grc(func) >= 2)
# but now it must be gone # but now it must be gone
gc.collect() gc.collect()
self.failUnless(grc(func) == 2) self.failUnless(grc(func) == 2)
@ -57,14 +57,14 @@ class RefcountTestCase(unittest.TestCase):
_fields_ = [("a", OtherCallback)] _fields_ = [("a", OtherCallback)]
x = X() x = X()
x.a = OtherCallback(func) x.a = OtherCallback(func)
# the CFuncPtr instance holds atr least one refcount on func: # the CFuncPtr instance holds atr least one refcount on func:
self.failUnless(grc(func) > 2) self.failUnless(grc(func) > 2)
# and may release it again # and may release it again
del x del x
self.failUnless(grc(func) >= 2) self.failUnless(grc(func) >= 2)
# and now it must be gone again # and now it must be gone again
gc.collect() gc.collect()
self.failUnlessEqual(grc(func), 2) self.failUnlessEqual(grc(func), 2)
@ -80,7 +80,7 @@ class RefcountTestCase(unittest.TestCase):
del f del f
gc.collect() gc.collect()
self.failUnlessEqual(grc(func), 2) self.failUnlessEqual(grc(func), 2)
class AnotherLeak(unittest.TestCase): class AnotherLeak(unittest.TestCase):
def test_callback(self): def test_callback(self):
import sys import sys
@ -89,7 +89,7 @@ class AnotherLeak(unittest.TestCase):
def func(a, b): def func(a, b):
return a * b * 2 return a * b * 2
f = proto(func) f = proto(func)
a = sys.getrefcount(ctypes.c_int) a = sys.getrefcount(ctypes.c_int)
f(1, 2) f(1, 2)
self.failUnlessEqual(sys.getrefcount(ctypes.c_int), a) self.failUnlessEqual(sys.getrefcount(ctypes.c_int), a)

View File

@ -16,7 +16,7 @@ class ReturnFuncPtrTestCase(unittest.TestCase):
self.failUnlessEqual(strchr("abcdef", "x"), None) self.failUnlessEqual(strchr("abcdef", "x"), None)
self.assertRaises(ArgumentError, strchr, "abcdef", 3) self.assertRaises(ArgumentError, strchr, "abcdef", 3)
self.assertRaises(TypeError, strchr, "abcdef") self.assertRaises(TypeError, strchr, "abcdef")
def test_without_prototype(self): def test_without_prototype(self):
dll = cdll.load(_ctypes_test.__file__) dll = cdll.load(_ctypes_test.__file__)
get_strchr = dll.get_strchr get_strchr = dll.get_strchr

View File

@ -46,7 +46,7 @@ class StringArrayTestCase(unittest.TestCase):
BUF = c_char * 4 BUF = c_char * 4
buf = BUF() buf = BUF()
## print c_char_p.from_param(buf) ## print c_char_p.from_param(buf)
def test_param_2(self): def test_param_2(self):
BUF = c_char * 4 BUF = c_char * 4
buf = BUF() buf = BUF()
@ -103,9 +103,9 @@ class StringTestCase(unittest.TestCase):
def XX_test_sized_strings(self): def XX_test_sized_strings(self):
# New in releases later than 0.4.0: # New in releases later than 0.4.0:
self.assertRaises(TypeError, c_string, None) self.assertRaises(TypeError, c_string, None)
# New in releases later than 0.4.0: # New in releases later than 0.4.0:
# c_string(number) returns an empty string of size number # c_string(number) returns an empty string of size number
self.failUnless(len(c_string(32).raw) == 32) self.failUnless(len(c_string(32).raw) == 32)
@ -181,7 +181,7 @@ else:
# One char too long values: # One char too long values:
self.assertRaises(ValueError, setattr, cs, "value", u"1234567") self.assertRaises(ValueError, setattr, cs, "value", u"1234567")
def run_test(rep, msg, func, arg): def run_test(rep, msg, func, arg):
items = range(rep) items = range(rep)
from time import clock from time import clock

View File

@ -56,7 +56,7 @@ class StructureTestCase(unittest.TestCase):
"f": c_float, "f": c_float,
"d": c_double, "d": c_double,
} }
def test_simple_structs(self): def test_simple_structs(self):
for code, tp in self.formats.items(): for code, tp in self.formats.items():
class X(Structure): class X(Structure):
@ -90,7 +90,7 @@ class StructureTestCase(unittest.TestCase):
("b", Y)] ("b", Y)]
self.failUnlessEqual(alignment(SI), max(alignment(Y), alignment(X))) self.failUnlessEqual(alignment(SI), max(alignment(Y), alignment(X)))
self.failUnlessEqual(sizeof(SI), calcsize("3s0i 3si 0i")) self.failUnlessEqual(sizeof(SI), calcsize("3s0i 3si 0i"))
class IS(Structure): class IS(Structure):
_fields_ = [("b", Y), _fields_ = [("b", Y),
("a", X)] ("a", X)]
@ -215,7 +215,7 @@ class StructureTestCase(unittest.TestCase):
# too long # too long
self.assertRaises(ValueError, Person, "1234567", 5) self.assertRaises(ValueError, Person, "1234567", 5)
def test_keyword_initializers(self): def test_keyword_initializers(self):
class POINT(Structure): class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)] _fields_ = [("x", c_int), ("y", c_int)]
@ -315,7 +315,7 @@ class StructureTestCase(unittest.TestCase):
func(*args) func(*args)
except Exception, detail: except Exception, detail:
return detail.__class__, str(detail) return detail.__class__, str(detail)
## def test_subclass_creation(self): ## def test_subclass_creation(self):
## meta = type(Structure) ## meta = type(Structure)
@ -373,4 +373,3 @@ class PointerMemberTestCase(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -43,22 +43,22 @@ if sys.platform == "win32":
class Structures(unittest.TestCase): class Structures(unittest.TestCase):
def test_struct_by_value(self): def test_struct_by_value(self):
class POINT(Structure): class POINT(Structure):
_fields_ = [("x", c_long), _fields_ = [("x", c_long),
("y", c_long)] ("y", c_long)]
class RECT(Structure): class RECT(Structure):
_fields_ = [("left", c_long), _fields_ = [("left", c_long),
("top", c_long), ("top", c_long),
("right", c_long), ("right", c_long),
("bottom", c_long)] ("bottom", c_long)]
dll = cdll.load(_ctypes_test.__file__) dll = cdll.load(_ctypes_test.__file__)
pt = POINT(10, 10) pt = POINT(10, 10)
rect = RECT(0, 0, 20, 20) rect = RECT(0, 0, 20, 20)
self.failUnlessEqual(1, dll.PointInRect(byref(rect), pt)) self.failUnlessEqual(1, dll.PointInRect(byref(rect), pt))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -216,10 +216,10 @@ class bdist_msi (Command):
# Prefix ProductName with Python x.y, so that # Prefix ProductName with Python x.y, so that
# it sorts together with the other Python packages # it sorts together with the other Python packages
# in Add-Remove-Programs (APR) # in Add-Remove-Programs (APR)
product_name = "Python %s %s" % (self.target_version, product_name = "Python %s %s" % (self.target_version,
self.distribution.get_fullname()) self.distribution.get_fullname())
self.db = msilib.init_database(installer_name, schema, self.db = msilib.init_database(installer_name, schema,
product_name, msilib.gen_uuid(), product_name, msilib.gen_uuid(),
sversion, author) sversion, author)
msilib.add_tables(self.db, sequence) msilib.add_tables(self.db, sequence)
props = [('DistVersion', version)] props = [('DistVersion', version)]
@ -238,7 +238,7 @@ class bdist_msi (Command):
self.db.Commit() self.db.Commit()
if hasattr(self.distribution, 'dist_files'): if hasattr(self.distribution, 'dist_files'):
self.distribution.dist_files.append(('bdist_msi', self.target_version, fullname)) self.distribution.dist_files.append(('bdist_msi', self.target_version, fullname))
if not self.keep_temp: if not self.keep_temp:
remove_tree(self.bdist_dir, dry_run=self.dry_run) remove_tree(self.bdist_dir, dry_run=self.dry_run)
@ -265,14 +265,14 @@ class bdist_msi (Command):
if self.install_script_key: if self.install_script_key:
raise DistutilsOptionError, "Multiple files with name %s" % file raise DistutilsOptionError, "Multiple files with name %s" % file
self.install_script_key = '[#%s]' % key self.install_script_key = '[#%s]' % key
cab.commit(db) cab.commit(db)
def add_find_python(self): def add_find_python(self):
"""Adds code to the installer to compute the location of Python. """Adds code to the installer to compute the location of Python.
Properties PYTHON.MACHINE, PYTHON.USER, PYTHONDIR and PYTHON will be set Properties PYTHON.MACHINE, PYTHON.USER, PYTHONDIR and PYTHON will be set
in both the execute and UI sequences; PYTHONDIR will be set from in both the execute and UI sequences; PYTHONDIR will be set from
PYTHON.USER if defined, else from PYTHON.MACHINE. PYTHON.USER if defined, else from PYTHON.MACHINE.
PYTHON is PYTHONDIR\python.exe""" PYTHON is PYTHONDIR\python.exe"""
install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % self.target_version install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % self.target_version
add_data(self.db, "RegLocator", add_data(self.db, "RegLocator",
@ -497,7 +497,7 @@ class bdist_msi (Command):
seldlg.title("Select Destination Directory") seldlg.title("Select Destination Directory")
version = sys.version[:3]+" " version = sys.version[:3]+" "
seldlg.text("Hint", 15, 30, 300, 40, 3, seldlg.text("Hint", 15, 30, 300, 40, 3,
"The destination directory should contain a Python %sinstallation" % version) "The destination directory should contain a Python %sinstallation" % version)
seldlg.back("< Back", None, active=0) seldlg.back("< Back", None, active=0)

View File

@ -252,7 +252,7 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
for mname in mnames: for mname in mnames:
m = __import__(mname, globals(), locals(), ["__dummy__"]) m = __import__(mname, globals(), locals(), ["__dummy__"])
m.__loader__ # to make sure we actually handled the import m.__loader__ # to make sure we actually handled the import
# Delete urllib from modules because urlparse was imported above. # Delete urllib from modules because urlparse was imported above.
# Without this hack, test_socket_ssl fails if run in this order: # Without this hack, test_socket_ssl fails if run in this order:
# regrtest.py test_codecmaps_tw test_importhooks test_socket_ssl # regrtest.py test_codecmaps_tw test_importhooks test_socket_ssl
try: try: