[pywin32-checkins] pywin32/win32/test test_win32api.py,1.3,1.4
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <mha...@us...> - 2003-10-18 07:06:06
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory sc8-pr-cvs1:/tmp/cvs-serv17495 Modified Files: test_win32api.py Log Message: Test RegNotifyChangeKeyValue, from Roger Upole Index: test_win32api.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32api.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_win32api.py 2 Jul 2003 04:06:57 -0000 1.3 --- test_win32api.py 18 Oct 2003 05:56:27 -0000 1.4 *************** *** 3,7 **** import unittest ! import win32api, win32con class CurrentUserTestCase(unittest.TestCase): --- 3,7 ---- import unittest ! import win32api, win32con, win32event class CurrentUserTestCase(unittest.TestCase): *************** *** 24,32 **** class Registry(unittest.TestCase): def test1(self): # This used to leave a stale exception behind. - key_name = r'PythonTestHarness\Whatever' def reg_operation(): ! hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, key_name) x = 3/0 # or a statement like: raise 'error' # do the test --- 24,32 ---- class Registry(unittest.TestCase): + key_name = r'PythonTestHarness\Whatever' def test1(self): # This used to leave a stale exception behind. def reg_operation(): ! hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, self.key_name) x = 3/0 # or a statement like: raise 'error' # do the test *************** *** 38,44 **** 1/0 # Force exception finally: ! win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, key_name) except ZeroDivisionError: pass if __name__ == '__main__': --- 38,65 ---- 1/0 # Force exception finally: ! win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, self.key_name) except ZeroDivisionError: pass + def testNotifyChange(self): + def change(): + hkey = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER, self.key_name) + try: + win32api.RegSetValue(hkey, None, win32con.REG_SZ, "foo") + finally: + win32api.RegDeleteKey(win32con.HKEY_CURRENT_USER, self.key_name) + + evt = win32event.CreateEvent(None,0,0,None) + ## REG_NOTIFY_CHANGE_LAST_SET - values + ## REG_CHANGE_NOTIFY_NAME - keys + ## REG_NOTIFY_CHANGE_SECURITY - security descriptor + ## REG_NOTIFY_CHANGE_ATTRIBUTES + win32api.RegNotifyChangeKeyValue(win32con.HKEY_CURRENT_USER,1,win32api.REG_NOTIFY_CHANGE_LAST_SET,evt,True) + ret_code=win32event.WaitForSingleObject(evt,0) + # Should be no change. + self.failUnless(ret_code==win32con.WAIT_TIMEOUT) + change() + # Our event should now be in a signalled state. + ret_code=win32event.WaitForSingleObject(evt,0) + self.failUnless(ret_code==win32con.WAIT_OBJECT_0) if __name__ == '__main__': |