Update of /cvsroot/pywin32/pywin32/win32/test
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv3985/win32/test
Modified Files:
Tag: py3k
test_pywintypes.py test_win32file.py
Log Message:
merge various changes, particularly PyTime, from trunk
Index: test_win32file.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/test_win32file.py,v
retrieving revision 1.13.2.5
retrieving revision 1.13.2.6
diff -C2 -d -r1.13.2.5 -r1.13.2.6
*** test_win32file.py 7 Jan 2009 06:25:16 -0000 1.13.2.5
--- test_win32file.py 8 Jan 2009 03:45:50 -0000 1.13.2.6
***************
*** 10,13 ****
--- 10,19 ----
import shutil
import socket
+ import datetime
+
+ try:
+ set
+ except NameError:
+ from sets import Set as set
class TestSimpleOps(unittest.TestCase):
***************
*** 116,119 ****
--- 122,168 ----
os.unlink(filename)
+ def testFileTimes(self):
+ if issubclass(pywintypes.TimeType, datetime.datetime):
+ from win32timezone import GetLocalTimeZone
+ now = datetime.datetime.now(tz=GetLocalTimeZone())
+ ok_delta = datetime.timedelta(seconds=1)
+ later = now + datetime.timedelta(seconds=120)
+ else:
+ tick = int(time.time())
+ now = pywintypes.Time(tick)
+ ok_delta = 1
+ later = pywintypes.Time(tick+120)
+
+ filename = tempfile.mktemp("-testFileTimes")
+ # Windows docs the 'last time' isn't valid until the last write
+ # handle is closed - so create the file, then re-open it to check.
+ open(filename,"w").close()
+ f = win32file.CreateFile(filename, win32file.GENERIC_READ|win32file.GENERIC_WRITE,
+ 0, None,
+ win32con.OPEN_EXISTING, 0, None)
+ # *sob* - before we had tz aware datetime objects, we are faced
+ # with FILETIME objects being +GST out from now(). So just skip
+ # this...
+ if not issubclass(pywintypes.TimeType, datetime.datetime):
+ return
+ try:
+ ct, at, wt = win32file.GetFileTime(f)
+ self.failUnless(ct >= now, "File was created in the past - now=%s, created=%s" % (now, ct))
+ self.failUnless( now <= ct <= now + ok_delta, (now, ct))
+ self.failUnless(wt >= now, "File was written-to in the past now=%s, written=%s" % (now,wt))
+ self.failUnless( now <= wt <= now + ok_delta, (now, wt))
+
+ # Now set the times.
+ win32file.SetFileTime(f, later, later, later)
+ # Get them back.
+ ct, at, wt = win32file.GetFileTime(f)
+ self.failUnlessEqual(ct, later)
+ self.failUnlessEqual(at, later)
+ self.failUnlessEqual(wt, later)
+
+ finally:
+ f.Close()
+ os.unlink(filename)
+
class TestOverlapped(unittest.TestCase):
def testSimpleOverlapped(self):
***************
*** 198,204 ****
# reference counting should catch that error.
overlapped = None
! self.failUnlessRaises(RuntimeError,
! win32file.GetQueuedCompletionStatus, port, -1)
! handle.Close()
return
--- 247,257 ----
# reference counting should catch that error.
overlapped = None
! # even if we fail, be sure to close the handle; prevents hangs
! # on Vista 64...
! try:
! self.failUnlessRaises(RuntimeError,
! win32file.GetQueuedCompletionStatus, port, -1)
! finally:
! handle.Close()
return
***************
*** 231,235 ****
t = threading.Thread(target=self._IOCPServerThread, args=(handle,port, test_overlapped_death))
- # hrmph - markh is seeing failures here on x64 - and a hang!
t.setDaemon(True) # avoid hanging entire test suite on failure.
t.start()
--- 284,287 ----
Index: test_pywintypes.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/test/test_pywintypes.py,v
retrieving revision 1.3.4.3
retrieving revision 1.3.4.4
diff -C2 -d -r1.3.4.3 -r1.3.4.4
*** test_pywintypes.py 7 Jan 2009 06:25:16 -0000 1.3.4.3
--- test_pywintypes.py 8 Jan 2009 03:45:50 -0000 1.3.4.4
***************
*** 3,6 ****
--- 3,7 ----
import time
from pywin32_testutil import str2bytes, ob2memory
+ import datetime
class TestCase(unittest.TestCase):
***************
*** 9,14 ****
pytime_current = pywintypes.Time(struct_current)
# try and test all the standard parts of the format
! format_string = "%a %A %b %B %c %d %H %I %j %m %M %p %S %U %w %W %x %X %y %Y %Z"
! self.assertEquals(pytime_current.Format(format_string), time.strftime(format_string, struct_current))
def testPyTimePrint(self):
--- 10,18 ----
pytime_current = pywintypes.Time(struct_current)
# try and test all the standard parts of the format
! format_strings = "%a %A %b %B %c %d %H %I %j %m %M %p %S %U %w %W %x %X %y %Y %Z"
! for fmt in format_strings.split():
! v1 = pytime_current.Format(fmt)
! v2 = time.strftime(fmt, struct_current)
! self.assertEquals(v1, v2, "format %s failed - %r != %r" % (fmt, v1, v2))
def testPyTimePrint(self):
***************
*** 17,26 ****
# (as hopefully this wont be true forever). So either working, or
# ValueError is OK.
- t = pywintypes.Time(-2)
try:
t.Format()
except ValueError:
return
def testPyTimeCompare(self):
t1 = pywintypes.Time(100)
--- 21,35 ----
# (as hopefully this wont be true forever). So either working, or
# ValueError is OK.
try:
+ t = pywintypes.Time(-2)
t.Format()
except ValueError:
return
+ def testTimeInDict(self):
+ d = {}
+ d['t1'] = pywintypes.Time(1)
+ self.failUnlessEqual(d['t1'], pywintypes.Time(1))
+
def testPyTimeCompare(self):
t1 = pywintypes.Time(100)
***************
*** 36,39 ****
--- 45,68 ----
self.failUnless(t2 > t1 )
+ def testTimeTuple(self):
+ now = datetime.datetime.now() # has usec...
+ # timetuple() lost usec - pt must be <=...
+ pt = pywintypes.Time(now.timetuple())
+ # *sob* - only if we have a datetime object can we compare like this.
+ if isinstance(pt, datetime.datetime):
+ self.failUnless(pt <= now)
+
+ def testTimeTuplems(self):
+ now = datetime.datetime.now() # has usec...
+ tt = now.timetuple() + (now.microsecond // 1000,)
+ pt = pywintypes.Time(tt)
+ # we can't compare if using the old type, as it loses all sub-second res.
+ if isinstance(pt, datetime.datetime):
+ self.failUnlessEqual(now, pt)
+
+ def testPyTimeFromTime(self):
+ t1 = pywintypes.Time(time.time())
+ self.failUnless(pywintypes.Time(t1) is t1)
+
def testGUID(self):
s = "{00020400-0000-0000-C000-000000000046}"
|