[pywin32-checkins] pywin32/win32/test test_clipboard.py, 1.6.2.3, 1.6.2.4 test_odbc.py, 1.7.2.3, 1.
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-01-07 06:25:24
|
Update of /cvsroot/pywin32/pywin32/win32/test In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv7136/win32/test Modified Files: Tag: py3k test_clipboard.py test_odbc.py test_pywintypes.py test_security.py test_sspi.py test_win32api.py test_win32crypt.py test_win32file.py test_win32inet.py test_win32pipe.py test_win32wnet.py testall.py Log Message: merge recent test changes from the trunk Index: test_security.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_security.py,v retrieving revision 1.4.4.2 retrieving revision 1.4.4.3 diff -C2 -d -r1.4.4.2 -r1.4.4.3 *** test_security.py 11 Dec 2008 04:13:36 -0000 1.4.4.2 --- test_security.py 7 Jan 2009 06:25:16 -0000 1.4.4.3 *************** *** 2,5 **** --- 2,7 ---- import sys, os import unittest + import winerror + from pywin32_testutil import testmain, TestSkipped, ob2memory import win32api, win32con, win32security, ntsecuritycon *************** *** 18,25 **** def testBuffer(self): ! # hrm - what about py3k - intent is to check the buffer slots return ! # something sane. ! self.failUnlessEqual(buffer(win32security.LookupAccountName('','Administrator')[0]), ! buffer(win32security.LookupAccountName('','Administrator')[0])) def testMemory(self): --- 20,25 ---- def testBuffer(self): ! self.failUnlessEqual(ob2memory(win32security.LookupAccountName('','Administrator')[0]), ! ob2memory(win32security.LookupAccountName('','Administrator')[0])) def testMemory(self): *************** *** 42,46 **** sd4.SetSecurityDescriptorSacl(1,sacl,0) ! class TestDS(unittest.TestCase): def testDsGetDcName(self): # Not sure what we can actually test here! At least calling it --- 42,61 ---- sd4.SetSecurityDescriptorSacl(1,sacl,0) ! class DomainTests(unittest.TestCase): ! def setUp(self): ! self.ds_handle = None ! try: ! # saving the handle means the other test itself should bind faster. ! self.ds_handle = win32security.DsBind() ! except win32security.error as exc: ! if exc.winerror != winerror.ERROR_NO_SUCH_DOMAIN: ! raise ! raise TestSkipped(exc) ! ! def tearDown(self): ! if self.ds_handle is not None: ! self.ds_handle.close() ! ! class TestDS(DomainTests): def testDsGetDcName(self): # Not sure what we can actually test here! At least calling it *************** *** 75,79 **** self.failUnlessEqual(expected, result[0][2]) ! class TestTranslate(unittest.TestCase): def _testTranslate(self, fmt_from, fmt_to): name = win32api.GetUserNameEx(fmt_from) --- 90,94 ---- self.failUnlessEqual(expected, result[0][2]) ! class TestTranslate(DomainTests): def _testTranslate(self, fmt_from, fmt_to): name = win32api.GetUserNameEx(fmt_from) *************** *** 95,97 **** if __name__=='__main__': ! unittest.main() --- 110,112 ---- if __name__=='__main__': ! testmain() Index: test_win32pipe.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32pipe.py,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** test_win32pipe.py 7 Jun 2008 07:23:54 -0000 1.4 --- test_win32pipe.py 7 Jan 2009 06:25:16 -0000 1.4.2.1 *************** *** 2,5 **** --- 2,6 ---- import time import threading + from pywin32_testutil import str2bytes # py3k-friendly helper *************** *** 19,25 **** self.failUnless(hr in (0, winerror.ERROR_PIPE_CONNECTED), "Got error code 0x%x" % (hr,)) hr, got = win32file.ReadFile(pipe_handle, 100) ! self.failUnless(got == "foo\0bar") time.sleep(wait_time) ! win32file.WriteFile(pipe_handle, "bar\0foo") pipe_handle.Close() event.set() --- 20,26 ---- self.failUnless(hr in (0, winerror.ERROR_PIPE_CONNECTED), "Got error code 0x%x" % (hr,)) hr, got = win32file.ReadFile(pipe_handle, 100) ! self.failUnlessEqual(got, str2bytes("foo\0bar")) time.sleep(wait_time) ! win32file.WriteFile(pipe_handle, str2bytes("bar\0foo")) pipe_handle.Close() event.set() *************** *** 48,53 **** self.startPipeServer(event) ! got = win32pipe.CallNamedPipe(self.pipename,"foo\0bar", 1024, win32pipe.NMPWAIT_WAIT_FOREVER) ! self.failUnlessEqual(got, "bar\0foo") event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") --- 49,54 ---- self.startPipeServer(event) ! got = win32pipe.CallNamedPipe(self.pipename,str2bytes("foo\0bar"), 1024, win32pipe.NMPWAIT_WAIT_FOREVER) ! self.failUnlessEqual(got, str2bytes("bar\0foo")) event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") *************** *** 70,75 **** hpipe, win32pipe.PIPE_READMODE_MESSAGE, None, None) ! hr, got = win32pipe.TransactNamedPipe(hpipe, "foo\0bar", 1024, None) ! self.failUnlessEqual(got, "bar\0foo") event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") --- 71,76 ---- hpipe, win32pipe.PIPE_READMODE_MESSAGE, None, None) ! hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), 1024, None) ! self.failUnlessEqual(got, str2bytes("bar\0foo")) event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") *************** *** 95,100 **** buffer = win32file.AllocateReadBuffer(1024) ! hr, got = win32pipe.TransactNamedPipe(hpipe, "foo\0bar", buffer, None) ! self.failUnlessEqual(got, "bar\0foo") event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") --- 96,101 ---- buffer = win32file.AllocateReadBuffer(1024) ! hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), buffer, None) ! self.failUnlessEqual(got, str2bytes("bar\0foo")) event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") *************** *** 120,128 **** buffer = win32file.AllocateReadBuffer(1024) ! hr, got = win32pipe.TransactNamedPipe(hpipe, "foo\0bar", buffer, overlapped) self.failUnlessEqual(hr, winerror.ERROR_IO_PENDING) nbytes = win32file.GetOverlappedResult(hpipe, overlapped, True) got = buffer[:nbytes] ! self.failUnlessEqual(got, "bar\0foo") event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") --- 121,129 ---- buffer = win32file.AllocateReadBuffer(1024) ! hr, got = win32pipe.TransactNamedPipe(hpipe, str2bytes("foo\0bar"), buffer, overlapped) self.failUnlessEqual(hr, winerror.ERROR_IO_PENDING) nbytes = win32file.GetOverlappedResult(hpipe, overlapped, True) got = buffer[:nbytes] ! self.failUnlessEqual(got, str2bytes("bar\0foo")) event.wait(5) self.failUnless(event.isSet(), "Pipe server thread didn't terminate") Index: test_sspi.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_sspi.py,v retrieving revision 1.3.4.2 retrieving revision 1.3.4.3 diff -C2 -d -r1.3.4.2 -r1.3.4.3 *** test_sspi.py 3 Oct 2008 22:44:37 -0000 1.3.4.2 --- test_sspi.py 7 Jan 2009 06:25:16 -0000 1.3.4.3 *************** *** 3,8 **** --- 3,21 ---- # See also the other SSPI demos. import win32security, sspi, sspicon, win32api + from pywin32_testutil import TestSkipped, testmain, str2bytes import unittest + # It is quite likely that the Kerberos tests will fail due to not being + # installed. The NTLM tests do *not* get the same behaviour as they should + # always be there. + def applyHandlingSkips(func, *args): + try: + return func(*args) + except win32api.error as exc: + if exc.winerror == sspicon.SEC_E_NO_CREDENTIALS: + raise TestSkipped(exc) + raise + + class TestSSPI(unittest.TestCase): *************** *** 32,36 **** def testImpersonateKerberos(self): ! self._doTestImpersonate("Kerberos") def testImpersonateNTLM(self): --- 45,49 ---- def testImpersonateKerberos(self): ! applyHandlingSkips(self._doTestImpersonate, "Kerberos") def testImpersonateNTLM(self): *************** *** 42,46 **** pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES) ! msg=b'some data to be encrypted ......' trailersize=pkg_size_info['SecurityTrailer'] --- 55,59 ---- pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES) ! msg=str2bytes('some data to be encrypted ......') trailersize=pkg_size_info['SecurityTrailer'] *************** *** 53,61 **** self.failUnlessEqual(msg, encbuf[0].Buffer) # and test the higher-level functions ! data, sig = sspiclient.encrypt(b"hello") ! self.assertEqual(sspiserver.decrypt(data, sig), b"hello") ! data, sig = sspiserver.encrypt(b"hello") ! self.assertEqual(sspiclient.decrypt(data, sig), b"hello") def testEncryptNTLM(self): --- 66,75 ---- self.failUnlessEqual(msg, encbuf[0].Buffer) # and test the higher-level functions ! data_in = str2bytes("hello") ! data, sig = sspiclient.encrypt(data_in) ! self.assertEqual(sspiserver.decrypt(data, sig), data_in) ! data, sig = sspiserver.encrypt(data_in) ! self.assertEqual(sspiclient.decrypt(data, sig), data_in) def testEncryptNTLM(self): *************** *** 63,67 **** def testEncryptKerberos(self): ! self._doTestEncrypt("Kerberos") def _doTestSign(self, pkg_name): --- 77,81 ---- def testEncryptKerberos(self): ! applyHandlingSkips(self._doTestEncrypt, "Kerberos") def _doTestSign(self, pkg_name): *************** *** 70,74 **** pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES) ! msg=b'some data to be encrypted ......' sigsize=pkg_size_info['MaxSignature'] --- 84,88 ---- pkg_size_info=sspiclient.ctxt.QueryContextAttributes(sspicon.SECPKG_ATTR_SIZES) ! msg=str2bytes('some data to be encrypted ......') sigsize=pkg_size_info['MaxSignature'] *************** *** 82,97 **** sspiclient.next_seq_num = 1 sspiserver.next_seq_num = 1 ! key = sspiclient.sign(b"hello") ! sspiserver.verify(b"hello", key) ! key = sspiclient.sign(b"hello") self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiserver.verify, b"hellox", key) # and the other way ! key = sspiserver.sign(b"hello") ! sspiclient.verify(b"hello", key) ! key = sspiserver.sign(b"hello") self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiclient.verify, b"hellox", key) def testSignNTLM(self): --- 96,112 ---- sspiclient.next_seq_num = 1 sspiserver.next_seq_num = 1 ! data = str2bytes("hello") ! key = sspiclient.sign(data) ! sspiserver.verify(data, key) ! key = sspiclient.sign(data) self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiserver.verify, data + data, key) # and the other way ! key = sspiserver.sign(data) ! sspiclient.verify(data, key) ! key = sspiserver.sign(data) self.assertRaisesHRESULT(sspicon.SEC_E_MESSAGE_ALTERED, ! sspiclient.verify, data + data, key) def testSignNTLM(self): *************** *** 99,120 **** def testSignKerberos(self): ! self._doTestSign("Kerberos") ! def testSequenceSign(self): # Only Kerberos supports sequence detection. sspiclient, sspiserver = self._doAuth("Kerberos") ! key = sspiclient.sign(b"hello") ! sspiclient.sign(b"hello") self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, ! sspiserver.verify, b'hello', key) ! def testSequenceEncrypt(self): # Only Kerberos supports sequence detection. sspiclient, sspiserver = self._doAuth("Kerberos") ! blob, key = sspiclient.encrypt(b"hello",) ! blob, key = sspiclient.encrypt(b"hello") self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, sspiserver.decrypt, blob, key) if __name__=='__main__': ! unittest.main() --- 114,141 ---- def testSignKerberos(self): ! applyHandlingSkips(self._doTestSign, "Kerberos") ! def _testSequenceSign(self): # Only Kerberos supports sequence detection. sspiclient, sspiserver = self._doAuth("Kerberos") ! key = sspiclient.sign("hello") ! sspiclient.sign("hello") self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, ! sspiserver.verify, 'hello', key) ! def testSequenceSign(self): ! applyHandlingSkips(self._testSequenceSign) ! ! def _testSequenceEncrypt(self): # Only Kerberos supports sequence detection. sspiclient, sspiserver = self._doAuth("Kerberos") ! blob, key = sspiclient.encrypt("hello",) ! blob, key = sspiclient.encrypt("hello") self.assertRaisesHRESULT(sspicon.SEC_E_OUT_OF_SEQUENCE, sspiserver.decrypt, blob, key) + def testSequenceEncrypt(self): + applyHandlingSkips(self._testSequenceEncrypt) + if __name__=='__main__': ! testmain() Index: test_win32api.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32api.py,v retrieving revision 1.13.2.3 retrieving revision 1.13.2.4 diff -C2 -d -r1.13.2.3 -r1.13.2.4 *** test_win32api.py 11 Dec 2008 04:13:36 -0000 1.13.2.3 --- test_win32api.py 7 Jan 2009 06:25:16 -0000 1.13.2.4 *************** *** 2,5 **** --- 2,6 ---- import unittest + from pywin32_testutil import str2bytes import win32api, win32con, win32event, winerror *************** *** 68,72 **** ('REG_MULTI_SZ', win32con.REG_MULTI_SZ, ['string 1','string 2','string 3','string 4']), ('REG_DWORD', win32con.REG_DWORD, 666), ! ('REG_BINARY', win32con.REG_BINARY, b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00'), ) --- 69,73 ---- ('REG_MULTI_SZ', win32con.REG_MULTI_SZ, ['string 1','string 2','string 3','string 4']), ('REG_DWORD', win32con.REG_DWORD, 666), ! ('REG_BINARY', win32con.REG_BINARY, str2bytes('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00')), ) Index: test_win32inet.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32inet.py,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -C2 -d -r1.1.4.2 -r1.1.4.3 *** test_win32inet.py 11 Dec 2008 07:17:46 -0000 1.1.4.2 --- test_win32inet.py 7 Jan 2009 06:25:16 -0000 1.1.4.3 *************** *** 1,4 **** --- 1,5 ---- from win32inet import * from win32inetcon import * + from pywin32_testutil import str2bytes # py3k-friendly helper import unittest *************** *** 36,41 **** break chunks.append(chunk) ! data = ''.join(chunks) ! assert data.find("Python")>0, repr(data) # This must appear somewhere on the main page! def testFtpCommand(self): --- 37,42 ---- break chunks.append(chunk) ! data = str2bytes('').join(chunks) ! assert data.find(str2bytes("Python"))>0, repr(data) # This must appear somewhere on the main page! def testFtpCommand(self): Index: test_odbc.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_odbc.py,v retrieving revision 1.7.2.3 retrieving revision 1.7.2.4 diff -C2 -d -r1.7.2.3 -r1.7.2.4 *** test_odbc.py 11 Dec 2008 07:02:51 -0000 1.7.2.3 --- test_odbc.py 7 Jan 2009 06:25:16 -0000 1.7.2.4 *************** *** 6,9 **** --- 6,11 ---- import tempfile + from pywin32_testutil import str2bytes, str2memory, TestSkipped + # We use the DAO ODBC driver from win32com.client.gencache import EnsureDispatch *************** *** 31,35 **** pass else: ! raise RuntimeError("Can't find a DB engine") workspace = dbe.Workspaces(0) --- 33,37 ---- pass else: ! raise TestSkipped("Can't find a DB engine") workspace = dbe.Workspaces(0) *************** *** 104,109 **** def test_insert_select_unicode_ext(self): ! userid = str(b"t-\xe0\xf2", "mbcs") ! username = str(b"test-\xe0\xf2 name", "mbcs") self.test_insert_select_unicode(userid, username) --- 106,111 ---- def test_insert_select_unicode_ext(self): ! userid = "t-\xe0\xf2" ! username = "test-\xe0\xf2 name" self.test_insert_select_unicode(userid, username) *************** *** 143,151 **** def testLongBinary(self): """ Test a long raw field in excess of internal cursor data size (65536)""" ! self._test_val('longbinaryfield', memoryview(b'\0\1\2' * 70000)) def testRaw(self): ## Test binary data ! self._test_val('rawfield', memoryview(b'\1\2\3\4\0\5\6\7\8')) def test_widechar(self): --- 145,153 ---- def testLongBinary(self): """ Test a long raw field in excess of internal cursor data size (65536)""" ! self._test_val('longbinaryfield', str2memory('\0\1\2' * 70000)) def testRaw(self): ## Test binary data ! self._test_val('rawfield', str2memory('\1\2\3\4\0\5\6\7\8')) def test_widechar(self): *************** *** 173,177 **** def test_set_zero_length(self): self.assertEqual(self.cur.execute("insert into %s (userid,username) " ! "values (?,?)" %self.tablename, [b'Frank', '']),1) self.assertEqual(self.cur.execute("select * from %s" %self.tablename), 0) self.assertEqual(len(self.cur.fetchone()[1]),0) --- 175,179 ---- def test_set_zero_length(self): self.assertEqual(self.cur.execute("insert into %s (userid,username) " ! "values (?,?)" %self.tablename, [str2bytes('Frank'), '']),1) self.assertEqual(self.cur.execute("select * from %s" %self.tablename), 0) self.assertEqual(len(self.cur.fetchone()[1]),0) Index: test_clipboard.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_clipboard.py,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -C2 -d -r1.6.2.3 -r1.6.2.4 *** test_clipboard.py 27 Nov 2008 11:31:11 -0000 1.6.2.3 --- test_clipboard.py 7 Jan 2009 06:25:16 -0000 1.6.2.4 *************** *** 8,11 **** --- 8,13 ---- import array + from pywin32_testutil import str2bytes + custom_format_name = "PythonClipboardTestFormat" *************** *** 68,77 **** # GetClipboardData doesn't to auto string conversions - so on py3k, # CF_TEXT returns bytes. ! expected = val.encode("ascii") self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), expected) SetClipboardText(val, win32con.CF_UNICODETEXT) self.failUnlessEqual(GetClipboardData(win32con.CF_UNICODETEXT), val) def test_string(self): ! val = "test".encode("ascii") SetClipboardData(win32con.CF_TEXT, val) self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), val) --- 70,79 ---- # GetClipboardData doesn't to auto string conversions - so on py3k, # CF_TEXT returns bytes. ! expected = str2bytes(val) self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), expected) SetClipboardText(val, win32con.CF_UNICODETEXT) self.failUnlessEqual(GetClipboardData(win32con.CF_UNICODETEXT), val) def test_string(self): ! val = str2bytes("test") SetClipboardData(win32con.CF_TEXT, val) self.failUnlessEqual(GetClipboardData(win32con.CF_TEXT), val) *************** *** 83,88 **** CloseClipboard() def test_mem(self): ! val = "test".encode("ascii") ! expected = "test\0".encode("ascii") SetClipboardData(win32con.CF_TEXT, val) # Get the raw data - this will include the '\0' --- 85,90 ---- CloseClipboard() def test_mem(self): ! val = str2bytes("test") ! expected = str2bytes("test\0") SetClipboardData(win32con.CF_TEXT, val) # Get the raw data - this will include the '\0' *************** *** 98,102 **** self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 1) def test_custom_mem(self): ! test_data = b"hello\x00\xff" test_buffer = array.array("b", test_data) cf = RegisterClipboardFormat(custom_format_name) --- 100,104 ---- self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 1) def test_custom_mem(self): ! test_data = str2bytes("hello\x00\xff") test_buffer = array.array("b", test_data) cf = RegisterClipboardFormat(custom_format_name) Index: test_pywintypes.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_pywintypes.py,v retrieving revision 1.3.4.2 retrieving revision 1.3.4.3 diff -C2 -d -r1.3.4.2 -r1.3.4.3 *** test_pywintypes.py 11 Dec 2008 04:13:36 -0000 1.3.4.2 --- test_pywintypes.py 7 Jan 2009 06:25:16 -0000 1.3.4.3 *************** *** 2,5 **** --- 2,6 ---- import pywintypes import time + from pywin32_testutil import str2bytes, ob2memory class TestCase(unittest.TestCase): *************** *** 38,44 **** s = "{00020400-0000-0000-C000-000000000046}" iid = pywintypes.IID(s) ! iid2 = pywintypes.IID(bytes(iid), True) self.assertEquals(iid, iid2) ! self.assertRaises(ValueError, pywintypes.IID, b'00', True) # too short self.assertRaises(TypeError, pywintypes.IID, 0, True) # no buffer --- 39,45 ---- s = "{00020400-0000-0000-C000-000000000046}" iid = pywintypes.IID(s) ! iid2 = pywintypes.IID(ob2memory(iid), True) self.assertEquals(iid, iid2) ! self.assertRaises(ValueError, pywintypes.IID, str2bytes('00'), True) # too short self.assertRaises(TypeError, pywintypes.IID, 0, True) # no buffer Index: test_win32wnet.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32wnet.py,v retrieving revision 1.1.4.2 retrieving revision 1.1.4.3 diff -C2 -d -r1.1.4.2 -r1.1.4.3 *** test_win32wnet.py 11 Dec 2008 04:13:36 -0000 1.1.4.2 --- test_win32wnet.py 7 Jan 2009 06:25:16 -0000 1.1.4.3 *************** *** 4,7 **** --- 4,9 ---- import netbios + from pywin32_testutil import str2bytes + RESOURCE_CONNECTED = 0x00000001 RESOURCE_GLOBALNET = 0x00000002 *************** *** 111,115 **** ncb.Command = netbios.NCBASTAT ncb.Lana_num = byte_to_int(la_enum.lana[i]) ! ncb.Callname = "* ".encode("ascii") # ensure bytes on py2x and 3k adapter = netbios.ADAPTER_STATUS() ncb.Buffer = adapter --- 113,117 ---- ncb.Command = netbios.NCBASTAT ncb.Lana_num = byte_to_int(la_enum.lana[i]) ! ncb.Callname = str2bytes("* ") # ensure bytes on py2x and 3k adapter = netbios.ADAPTER_STATUS() ncb.Buffer = adapter Index: test_win32file.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32file.py,v retrieving revision 1.13.2.4 retrieving revision 1.13.2.5 diff -C2 -d -r1.13.2.4 -r1.13.2.5 *** test_win32file.py 11 Dec 2008 07:06:51 -0000 1.13.2.4 --- test_win32file.py 7 Jan 2009 06:25:16 -0000 1.13.2.5 *************** *** 1,3 **** --- 1,4 ---- import unittest + from pywin32_testutil import str2bytes import win32api, win32file, win32pipe, pywintypes, winerror, win32event import win32con, ntsecuritycon *************** *** 19,23 **** os.unlink(filename) handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None) ! test_data = b"Hello\0there" try: win32file.WriteFile(handle, test_data) --- 20,24 ---- os.unlink(filename) handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None) ! test_data = str2bytes("Hello\0there") try: win32file.WriteFile(handle, test_data) *************** *** 44,48 **** # Write a known number of bytes to the file. ! data = b"z" * 1025 win32file.WriteFile(h, data) --- 45,49 ---- # Write a known number of bytes to the file. ! data = str2bytes("z") * 1025 win32file.WriteFile(h, data) *************** *** 66,70 **** # GetFileAttributesEx/GetFileAttributesExW tests. self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName)) ! attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName) self.failUnless(size==newSize, --- 67,71 ---- # GetFileAttributesEx/GetFileAttributesExW tests. self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName)) ! attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName) self.failUnless(size==newSize, *************** *** 92,96 **** try: #Write some data ! data = b'Some data' (res, written) = win32file.WriteFile(f, data) --- 93,97 ---- try: #Write some data ! data = str2bytes('Some data') (res, written) = win32file.WriteFile(f, data) *************** *** 126,130 **** # Create the file and write shit-loads of data to it. h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.CREATE_ALWAYS, 0, 0) ! chunk_data = b"z" * 0x8000 num_loops = 512 expected_size = num_loops * len(chunk_data) --- 127,131 ---- # Create the file and write shit-loads of data to it. h = win32file.CreateFile( testName, desiredAccess, 0, None, win32file.CREATE_ALWAYS, 0, 0) ! chunk_data = str2bytes("z") * 0x8000 num_loops = 512 expected_size = num_loops * len(chunk_data) *************** *** 236,240 **** time.sleep(0.1) # let thread do its thing. try: ! win32pipe.CallNamedPipe(r"\\.\pipe\pywin32_test_pipe", b"Hello there", BUFSIZE, 0) except win32pipe.error: # Testing for overlapped death causes this --- 237,241 ---- time.sleep(0.1) # let thread do its thing. try: ! win32pipe.CallNamedPipe(r"\\.\pipe\pywin32_test_pipe", str2bytes("Hello there"), BUFSIZE, 0) except win32pipe.error: # Testing for overlapped death causes this *************** *** 298,302 **** s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', port)) ! win32file.WSASend(s, b"hello", None) overlapped = pywintypes.OVERLAPPED() overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None) --- 299,303 ---- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', port)) ! win32file.WSASend(s, str2bytes("hello"), None) overlapped = pywintypes.OVERLAPPED() overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None) *************** *** 309,313 **** nbytes = win32file.GetOverlappedResult(s.fileno(), overlapped, True) got = buffer[:nbytes] ! self.failUnlessEqual(got, b"hello") # thread should have stopped stopped.wait(2) --- 310,314 ---- nbytes = win32file.GetOverlappedResult(s.fileno(), overlapped, True) got = buffer[:nbytes] ! self.failUnlessEqual(got, str2bytes("hello")) # thread should have stopped stopped.wait(2) *************** *** 485,489 **** fname = tempfile.mktemp("win32file_test") f = open(fname, "wb") ! f.write(b"hello") f.close() f = None --- 486,490 ---- fname = tempfile.mktemp("win32file_test") f = open(fname, "wb") ! f.write(str2bytes("hello")) f.close() f = None Index: test_win32crypt.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32crypt.py,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -C2 -d -r1.1 -r1.1.4.1 *** test_win32crypt.py 4 Jul 2005 05:40:29 -0000 1.1 --- test_win32crypt.py 7 Jan 2009 06:25:16 -0000 1.1.4.1 *************** *** 1,10 **** ! # Test module for win32timezone import unittest import win32crypt class Crypt(unittest.TestCase): def testSimple(self): ! data = "My test data" entropy = None desc = "My description" --- 1,12 ---- ! # Test module for win32crypt import unittest import win32crypt + from pywin32_testutil import str2bytes # py3k-friendly helper + class Crypt(unittest.TestCase): def testSimple(self): ! data = str2bytes("My test data") entropy = None desc = "My description" *************** *** 17,22 **** def testEntropy(self): ! data = "My test data" ! entropy = "My test entropy" desc = "My description" flags = 0 --- 19,24 ---- def testEntropy(self): ! data = str2bytes("My test data") ! entropy = str2bytes("My test entropy") desc = "My description" flags = 0 Index: testall.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/test/testall.py,v retrieving revision 1.6.2.5 retrieving revision 1.6.2.6 diff -C2 -d -r1.6.2.5 -r1.6.2.6 *** testall.py 11 Dec 2008 07:06:51 -0000 1.6.2.5 --- testall.py 7 Jan 2009 06:25:16 -0000 1.6.2.6 *************** *** 1,4 **** --- 1,7 ---- import sys, os + import re import unittest + import traceback + import pywin32_testutil # A list of demos that depend on user-interface of *any* kind. Tests listed *************** *** 18,24 **** } ! ok_exceptions = { ! "RegCreateKeyTransacted": ("NotImplementedError"), ! } class TestRunner: --- 21,72 ---- } ! # re to pull apart an exception line into the exception type and the args. ! re_exception = re.compile("([a-zA-Z0-9_.]*): (.*)$") ! def find_exception_in_output(data): ! have_traceback = False ! for line in data.splitlines(): ! line = line.decode('ascii') # not sure what the correct encoding is... ! if line.startswith("Traceback ("): ! have_traceback = True ! continue ! if line.startswith(" "): ! continue ! if have_traceback: ! # first line not starting with a space since the traceback. ! # must be the exception! ! m = re_exception.match(line) ! if m: ! exc_type, args = m.groups() ! # get hacky - get the *real* exception object from the name. ! bits = exc_type.split(".", 1) ! if len(bits) > 1: ! mod = __import__(bits[0]) ! exc = getattr(mod, bits[1]) ! else: ! # probably builtin ! exc = eval(bits[0]) ! else: ! # hrm - probably just an exception with no args ! try: ! exc = eval(line.strip()) ! args = "()" ! except: ! return None ! # try and turn the args into real args. ! try: ! args = eval(args) ! except: ! pass ! if not isinstance(args, tuple): ! args = (args,) ! # try and instantiate the exception. ! try: ! ret = exc(*args) ! except: ! ret = None ! return ret ! # apparently not - keep looking... ! have_traceback = False ! class TestRunner: *************** *** 42,45 **** --- 90,97 ---- if rc: base = os.path.basename(self.argv[1]) + # See if we can detect and reconstruct an exception in the output. + reconstituted = find_exception_in_output(output) + if reconstituted is not None: + raise reconstituted raise AssertionError("%s failed with exit code %s. Output is:\n%s" % (base, rc, output)) *************** *** 53,59 **** if ext != ".py" or base in ui_demos or base in bad_demos: continue - if base in ok_exceptions: - print("Ack - can't handle test %s - can't catch specific exceptions" % (base,)) - continue argv = (sys.executable, os.path.join(demo_dir, base+".py")) + \ argvs.get(base, ()) --- 105,108 ---- *************** *** 100,106 **** try: mod = __import__(base) ! except ImportError as why: ! print("FAILED to import test module") ! print(why) continue if hasattr(mod, "suite"): --- 149,155 ---- try: mod = __import__(base) ! except: ! print("FAILED to import test module %r" % base) ! traceback.print_exc() continue if hasattr(mod, "suite"): *************** *** 113,120 **** return suite ! class CustomLoader(unittest.TestLoader): def loadTestsFromModule(self, module): ! return suite() if __name__=='__main__': ! unittest.TestProgram(testLoader=CustomLoader())(argv=sys.argv) --- 162,169 ---- return suite ! class CustomLoader(pywin32_testutil.TestLoader): def loadTestsFromModule(self, module): ! return self.fixupTestsForLeakTests(suite()) if __name__=='__main__': ! pywin32_testutil.testmain(testLoader=CustomLoader()) |