summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-03-24 11:35:01 +0000
committerJason R. Coombs <jaraco@jaraco.com>2014-03-24 11:35:01 +0000
commitbde115a6c99198bb1e362f3003cf4f66cfbef8cc (patch)
treefa1d39ca14e1c2629f4eea501c4871f96aaf10e1 /tests
parent209d078823d342d0f6b299698677483e8e5758a7 (diff)
downloadpython-setuptools-bitbucket-bde115a6c99198bb1e362f3003cf4f66cfbef8cc.tar.gz
Update test to use local timestamps, so the tests pass in any timezone.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pkg_resources.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/tests/test_pkg_resources.py b/tests/test_pkg_resources.py
index dfa27120..8ce77255 100644
--- a/tests/test_pkg_resources.py
+++ b/tests/test_pkg_resources.py
@@ -2,6 +2,7 @@ import sys
import tempfile
import os
import zipfile
+import datetime
import pkg_resources
@@ -17,9 +18,25 @@ class EggRemover(unicode):
if os.path.exists(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):
finalizers = []
+ ref_time = datetime.datetime(2013, 5, 12, 13, 25, 0)
+ "A reference time for a file modification"
+
@classmethod
def setup_class(cls):
"create a zip egg and add it to sys.path"
@@ -27,11 +44,11 @@ class TestZipProvider(object):
zip_egg = zipfile.ZipFile(egg, 'w')
zip_info = zipfile.ZipInfo()
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_info = zipfile.ZipInfo()
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.close()
egg.close()
@@ -55,11 +72,13 @@ class TestZipProvider(object):
manager = pkg_resources.ResourceManager()
zp = pkg_resources.ZipProvider(mod)
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.write('hello, world?')
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')
f = open(filename)
assert f.read() == 'hello, world!'