Commit abb8efdc authored by Jason R. Coombs's avatar Jason R. Coombs

Update test to use local timestamps, so the tests pass in any timezone.

parent 4ad02f9f
...@@ -2,6 +2,7 @@ import sys ...@@ -2,6 +2,7 @@ import sys
import tempfile import tempfile
import os import os
import zipfile import zipfile
import datetime
import pkg_resources import pkg_resources
...@@ -17,9 +18,25 @@ class EggRemover(unicode): ...@@ -17,9 +18,25 @@ class EggRemover(unicode):
if os.path.exists(self): if os.path.exists(self):
os.remove(self) os.remove(self)
ZERO = datetime.timedelta(0)
class UTC(datetime.tzinfo):
"""UTC"""
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO
class TestZipProvider(object): class TestZipProvider(object):
finalizers = [] finalizers = []
ref_time = datetime.datetime(2013, 5, 12, 13, 25, 0)
"A reference time for a file modification"
@classmethod @classmethod
def setup_class(cls): def setup_class(cls):
"create a zip egg and add it to sys.path" "create a zip egg and add it to sys.path"
...@@ -27,11 +44,11 @@ class TestZipProvider(object): ...@@ -27,11 +44,11 @@ class TestZipProvider(object):
zip_egg = zipfile.ZipFile(egg, 'w') zip_egg = zipfile.ZipFile(egg, 'w')
zip_info = zipfile.ZipInfo() zip_info = zipfile.ZipInfo()
zip_info.filename = 'mod.py' zip_info.filename = 'mod.py'
zip_info.date_time = 2013, 5, 12, 13, 25, 0 zip_info.date_time = cls.ref_time.timetuple()
zip_egg.writestr(zip_info, 'x = 3\n') zip_egg.writestr(zip_info, 'x = 3\n')
zip_info = zipfile.ZipInfo() zip_info = zipfile.ZipInfo()
zip_info.filename = 'data.dat' zip_info.filename = 'data.dat'
zip_info.date_time = 2013, 5, 12, 13, 25, 0 zip_info.date_time = cls.ref_time.timetuple()
zip_egg.writestr(zip_info, 'hello, world!') zip_egg.writestr(zip_info, 'hello, world!')
zip_egg.close() zip_egg.close()
egg.close() egg.close()
...@@ -55,11 +72,13 @@ class TestZipProvider(object): ...@@ -55,11 +72,13 @@ class TestZipProvider(object):
manager = pkg_resources.ResourceManager() manager = pkg_resources.ResourceManager()
zp = pkg_resources.ZipProvider(mod) zp = pkg_resources.ZipProvider(mod)
filename = zp.get_resource_filename(manager, 'data.dat') filename = zp.get_resource_filename(manager, 'data.dat')
assert os.stat(filename).st_mtime == 1368379500 actual = datetime.datetime.fromtimestamp(os.stat(filename).st_mtime)
assert actual == self.ref_time
f = open(filename, 'w') f = open(filename, 'w')
f.write('hello, world?') f.write('hello, world?')
f.close() f.close()
os.utime(filename, (1368379500, 1368379500)) ts = self.ref_time.timestamp()
os.utime(filename, (ts, ts))
filename = zp.get_resource_filename(manager, 'data.dat') filename = zp.get_resource_filename(manager, 'data.dat')
f = open(filename) f = open(filename)
assert f.read() == 'hello, world!' assert f.read() == 'hello, world!'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment