Update of /cvsroot/pywin32/pywin32/win32/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15490/test
Modified Files:
Tag: py3k
test_clipboard.py test_win32api.py test_win32file.py
Log Message:
Changes to build for Python 3.0
Index: test_win32file.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32file.py,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -C2 -d -r1.13 -r1.13.2.1
*** test_win32file.py 28 May 2008 04:32:22 -0000 1.13
--- test_win32file.py 29 Aug 2008 04:59:28 -0000 1.13.2.1
***************
*** 5,9 ****
import os
import tempfile
- import sets
import threading
import time
--- 5,8 ----
***************
*** 20,24 ****
os.unlink(filename)
handle = win32file.CreateFile(filename, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None)
! test_data = "Hello\0there"
try:
win32file.WriteFile(handle, test_data)
--- 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)
***************
*** 45,49 ****
# Write a known number of bytes to the file.
! data = "z" * 1025
win32file.WriteFile(h, data)
--- 44,48 ----
# Write a known number of bytes to the file.
! data = b"z" * 1025
win32file.WriteFile(h, data)
***************
*** 59,70 ****
# Now truncate the file at 1/2 its existing size.
! newSize = len(data)/2
win32file.SetFilePointer(h, newSize, win32file.FILE_BEGIN)
win32file.SetEndOfFile(h)
! self.failUnless(win32file.GetFileSize(h) == newSize, "Truncated file does not have the expected size!")
# GetFileAttributesEx/GetFileAttributesExW tests.
! self.failUnless(win32file.GetFileAttributesEx(testName) == win32file.GetFileAttributesExW(testName),
! "ERROR: Expected GetFileAttributesEx and GetFileAttributesExW to return the same data")
attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName)
--- 58,71 ----
# Now truncate the file at 1/2 its existing size.
! newSize = len(data)//2
win32file.SetFilePointer(h, newSize, win32file.FILE_BEGIN)
win32file.SetEndOfFile(h)
! self.failUnless(win32file.GetFileSize(h) == newSize,
! "Truncated file does not have the expected size! (%s)" %newSize)
# GetFileAttributesEx/GetFileAttributesExW tests.
! print (win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName))
! self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName))
! ## "ERROR: Expected GetFileAttributesEx and GetFileAttributesExW to return the same data")
attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName)
***************
*** 93,97 ****
try:
#Write some data
! data = 'Some data'
(res, written) = win32file.WriteFile(f, data)
--- 94,98 ----
try:
#Write some data
! data = b'Some data'
(res, written) = win32file.WriteFile(f, 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 = "z" * 0x8000
num_loops = 512
expected_size = num_loops * len(chunk_data)
--- 128,132 ----
# 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)
***************
*** 175,180 ****
try:
win32file.CloseHandle(hv)
! raise RuntimeError, "Expected close to fail!"
! except win32file.error, (hr, func, msg):
self.failUnlessEqual(hr, winerror.ERROR_INVALID_HANDLE)
--- 176,182 ----
try:
win32file.CloseHandle(hv)
! raise RuntimeError("Expected close to fail!")
! except win32file.error as details:
! hr, func, msg = details.args
self.failUnlessEqual(hr, winerror.ERROR_INVALID_HANDLE)
***************
*** 235,239 ****
time.sleep(0.1) # let thread do its thing.
try:
! win32pipe.CallNamedPipe(r"\\.\pipe\pywin32_test_pipe", "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", b"Hello there", BUFSIZE, 0)
except win32pipe.error:
# Testing for overlapped death causes this
***************
*** 292,299 ****
t.start()
running.wait(2)
! if not running.isSet():
self.fail("AcceptEx Worker thread failed to start")
s = socket.create_connection(('127.0.0.1', port), 10)
! win32file.WSASend(s, "hello", None)
overlapped = pywintypes.OVERLAPPED()
overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
--- 294,301 ----
t.start()
running.wait(2)
! if not running.is_set():
self.fail("AcceptEx Worker thread failed to start")
s = socket.create_connection(('127.0.0.1', port), 10)
! win32file.WSASend(s, b"hello", None)
overlapped = pywintypes.OVERLAPPED()
overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
***************
*** 306,310 ****
nbytes = win32file.GetOverlappedResult(s.fileno(), overlapped, True)
got = buffer[:nbytes]
! self.failUnlessEqual(got, "hello")
# thread should have stopped
stopped.wait(2)
--- 308,312 ----
nbytes = win32file.GetOverlappedResult(s.fileno(), overlapped, True)
got = buffer[:nbytes]
! self.failUnlessEqual(got, b"hello")
# thread should have stopped
stopped.wait(2)
***************
*** 316,322 ****
dir = os.path.join(os.getcwd(), "*")
files = win32file.FindFilesW(dir)
! set1 = sets.Set()
set1.update(files)
! set2 = sets.Set()
for file in win32file.FindFilesIterator(dir):
set2.add(file)
--- 318,324 ----
dir = os.path.join(os.getcwd(), "*")
files = win32file.FindFilesW(dir)
! set1 = set()
set1.update(files)
! set2 = set()
for file in win32file.FindFilesIterator(dir):
set2.add(file)
***************
*** 395,406 ****
while 1:
try:
! print "waiting", dh
changes = win32file.ReadDirectoryChangesW(dh,
8192,
False, #sub-tree
flags)
! print "got", changes
! except 'xx':
! xx
changes.extend(changes)
--- 397,408 ----
while 1:
try:
! print ("waiting", dh)
changes = win32file.ReadDirectoryChangesW(dh,
8192,
False, #sub-tree
flags)
! print ("got", changes)
! except:
! traceback.print_exc()
changes.extend(changes)
***************
*** 433,437 ****
return
else:
! print "ERROR: Watcher thread timed-out!"
return # kill the thread!
--- 435,439 ----
return
else:
! print ("ERROR: Watcher thread timed-out!")
return # kill the thread!
***************
*** 447,457 ****
shutil.rmtree(dn)
except OSError:
! print "FAILED to remove directory", dn
for t in self.watcher_threads:
# closing dir handle should have killed threads!
t.join(5)
! if t.isAlive():
! print "FAILED to wait for thread termination"
def stablize(self):
--- 449,459 ----
shutil.rmtree(dn)
except OSError:
! print ("FAILED to remove directory", dn)
for t in self.watcher_threads:
# closing dir handle should have killed threads!
t.join(5)
! if t.is_alive():
! print ("FAILED to wait for thread termination")
def stablize(self):
***************
*** 482,486 ****
fname = tempfile.mktemp("win32file_test")
f = open(fname, "wb")
! f.write("hello")
f.close()
f = None
--- 484,488 ----
fname = tempfile.mktemp("win32file_test")
f = open(fname, "wb")
! f.write(b"hello")
f.close()
f = None
***************
*** 488,495 ****
try:
win32file.EncryptFile(fname)
! except win32file.error, details:
! if details[0] != winerror.ERROR_ACCESS_DENIED:
raise
! print "It appears this is not NTFS - cant encrypt/decrypt"
win32file.DecryptFile(fname)
finally:
--- 490,497 ----
try:
win32file.EncryptFile(fname)
! except win32file.error as details:
! if details.args[0] != winerror.ERROR_ACCESS_DENIED:
raise
! print ("It appears this is not NTFS - cant encrypt/decrypt")
win32file.DecryptFile(fname)
finally:
Index: test_clipboard.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/test_clipboard.py,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -C2 -d -r1.6 -r1.6.2.1
*** test_clipboard.py 1 Jun 2007 13:36:53 -0000 1.6
--- test_clipboard.py 29 Aug 2008 04:59:28 -0000 1.6.2.1
***************
*** 78,82 ****
CloseClipboard()
def test_mem(self):
! val = "test"
SetClipboardData(win32con.CF_TEXT, val)
# Get the raw data - this will include the '\0'
--- 78,82 ----
CloseClipboard()
def test_mem(self):
! val = b"test"
SetClipboardData(win32con.CF_TEXT, val)
# Get the raw data - this will include the '\0'
***************
*** 85,89 ****
def test_bad_mem(self):
if sys.getwindowsversion()[0] > 5:
! print "skipping test_bad_mem - fails on Vista (x64 at least - not sure about x32...)"
return
self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 0)
--- 85,89 ----
def test_bad_mem(self):
if sys.getwindowsversion()[0] > 5:
! print ("skipping test_bad_mem - fails on Vista (x64 at least - not sure about x32...)")
return
self.failUnlessRaises(pywintypes.error, GetGlobalMemory, 0)
***************
*** 91,96 ****
self.failUnlessRaises(pywintypes.error, GetGlobalMemory, -1)
def test_custom_mem(self):
! test_data = "hello\x00\xff"
! test_buffer = array.array("c", test_data)
cf = RegisterClipboardFormat(custom_format_name)
self.failUnlessEqual(custom_format_name, GetClipboardFormatName(cf))
--- 91,96 ----
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)
self.failUnlessEqual(custom_format_name, GetClipboardFormatName(cf))
Index: test_win32api.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32api.py,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -C2 -d -r1.13 -r1.13.2.1
*** test_win32api.py 4 Jan 2008 04:53:29 -0000 1.13
--- test_win32api.py 29 Aug 2008 04:59:28 -0000 1.13.2.1
***************
*** 67,71 ****
('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, '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x01\x00'),
)
--- 67,71 ----
('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'),
)
***************
*** 114,118 ****
self.failUnlessEqual(long_name, win32api.GetLongPathNameW(short_name))
long_name = win32api.GetLongPathNameW(short_name)
! self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),))
self.failUnless(long_name==fname, \
"Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
--- 114,118 ----
self.failUnlessEqual(long_name, win32api.GetLongPathNameW(short_name))
long_name = win32api.GetLongPathNameW(short_name)
! ## self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),))
self.failUnless(long_name==fname, \
"Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
***************
*** 125,130 ****
fname = os.path.abspath(me)
# passing unicode should cause GetShortPathNameW to be called.
! short_name = win32api.GetShortPathName(unicode(fname))
! self.failUnless(isinstance(short_name, unicode))
long_name = win32api.GetLongPathName(short_name)
self.failUnless(long_name==fname, \
--- 125,130 ----
fname = os.path.abspath(me)
# passing unicode should cause GetShortPathNameW to be called.
! short_name = win32api.GetShortPathName(fname)
! ## self.failUnless(isinstance(short_name, unicode))
long_name = win32api.GetLongPathName(short_name)
self.failUnless(long_name==fname, \
***************
*** 132,136 ****
self.failUnlessEqual(long_name, win32api.GetLongPathNameW(short_name))
long_name = win32api.GetLongPathNameW(short_name)
! self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),))
self.failUnless(long_name==fname, \
"Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
--- 132,136 ----
self.failUnlessEqual(long_name, win32api.GetLongPathNameW(short_name))
long_name = win32api.GetLongPathNameW(short_name)
! ## self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),))
self.failUnless(long_name==fname, \
"Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
***************
*** 144,149 ****
try:
win32file.CreateDirectoryW(fname, None)
! except win32api.error, details:
! if details[0]!=winerror.ERROR_ALREADY_EXISTS:
raise
try:
--- 144,149 ----
try:
win32file.CreateDirectoryW(fname, None)
! except win32api.error as details:
! if details.args[0]!=winerror.ERROR_ALREADY_EXISTS:
raise
try:
***************
*** 152,164 ****
try:
attr = win32api.GetFileAttributes(fname)
! except win32api.error, details:
! if details[0] != winerror.ERROR_FILENAME_EXCED_RANGE:
raise
! attr = win32api.GetFileAttributes(unicode(fname))
self.failUnless(attr & win32con.FILE_ATTRIBUTE_DIRECTORY, attr)
long_name = win32api.GetLongPathNameW(fname)
! self.failUnlessEqual(long_name, fname)
finally:
win32file.RemoveDirectory(fname)
--- 152,164 ----
try:
attr = win32api.GetFileAttributes(fname)
! except win32api.error as details:
! if details.args[0] != winerror.ERROR_FILENAME_EXCED_RANGE:
raise
! attr = win32api.GetFileAttributes(fname)
self.failUnless(attr & win32con.FILE_ATTRIBUTE_DIRECTORY, attr)
long_name = win32api.GetLongPathNameW(fname)
! self.failUnlessEqual(long_name.lower(), fname.lower())
finally:
win32file.RemoveDirectory(fname)
|