[pywin32-checkins] pywin32/win32/test handles.py,1.2,1.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-24 06:47:29
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1:/tmp/cvs-serv5127 Modified Files: handles.py Log Message: Add a test that would cause a GC fatal error, and add some tests of TypeError exceptions. Index: handles.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/handles.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** handles.py 2 May 2003 00:05:27 -0000 1.2 --- handles.py 23 Oct 2003 04:09:56 -0000 1.3 *************** *** 1,3 **** --- 1,11 ---- import unittest + import pywintypes + import win32api + + # A class that will never die vie refcounting, but will die via GC. + class Cycle: + def __init__(self, handle): + self.cycle = self + self.handle = handle class PyHandleTestCase(unittest.TestCase): *************** *** 5,15 **** # We used to clobber all outstanding exceptions. def f1(invalidate): - """ This function throws a ZeroDivisionError. """ import win32event h = win32event.CreateEvent(None, 0, 0, None) if invalidate: - import win32api win32api.CloseHandle(int(h)) 1/0 def f2(invalidate): --- 13,24 ---- # We used to clobber all outstanding exceptions. def f1(invalidate): import win32event h = win32event.CreateEvent(None, 0, 0, None) if invalidate: win32api.CloseHandle(int(h)) 1/0 + # If we invalidated, then the object destruction code will attempt + # to close an invalid handle. We don't wan't an exception in + # this case def f2(invalidate): *************** *** 29,33 **** # The worst this does is cause an ".XXX undetected error (why=3)" # So avoiding that is the goal ! import win32event, win32api h = win32event.CreateEvent(None, 0, 0, None) # Close the handle underneath the object. --- 38,42 ---- # The worst this does is cause an ".XXX undetected error (why=3)" # So avoiding that is the goal ! import win32event h = win32event.CreateEvent(None, 0, 0, None) # Close the handle underneath the object. *************** *** 38,42 **** def testCleanup3(self): # And again with a class - no __del__ ! import win32event, win32api class Test: def __init__(self): --- 47,51 ---- def testCleanup3(self): # And again with a class - no __del__ ! import win32event class Test: def __init__(self): *************** *** 48,52 **** def testCleanupGood(self): # And check that normal error semantics *do* work. ! import win32event, win32api h = win32event.CreateEvent(None, 0, 0, None) win32api.CloseHandle(int(h)) --- 57,61 ---- def testCleanupGood(self): # And check that normal error semantics *do* work. ! import win32event h = win32event.CreateEvent(None, 0, 0, None) win32api.CloseHandle(int(h)) *************** *** 56,62 **** def testInvalid(self): - import pywintypes h=pywintypes.HANDLE(-2) self.assertRaises(win32api.error, h.Close) if __name__ == '__main__': --- 65,86 ---- def testInvalid(self): h=pywintypes.HANDLE(-2) self.assertRaises(win32api.error, h.Close) + + def testGC(self): + # This used to provoke: + # Fatal Python error: unexpected exception during garbage collection + def make(): + h=pywintypes.HANDLE(-2) + c = Cycle(h) + import gc + make() + gc.collect() + + def testTypes(self): + self.assertRaises(TypeError, pywintypes.HANDLE, "foo") + self.assertRaises(TypeError, pywintypes.HANDLE, ()) + # should be able to get a long! + pywintypes.HANDLE(0L) if __name__ == '__main__': |