1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Implement timestamp support for local files in testenv

* testenv/README: Change timestamp format definition
* testenv/conf/local_files.py: Set proper timestamps
This commit is contained in:
Hubert Tarasiuk 2015-05-07 18:34:17 +02:00 committed by Giuseppe Scrivano
parent 83537f2415
commit e397a48f6a
2 changed files with 9 additions and 1 deletions

View File

@ -124,7 +124,7 @@ WgetFile (str name, str contents, str timestamp, dict rules)
None except name is a mandatory paramter, one may pass only those parameters None except name is a mandatory paramter, one may pass only those parameters
that are required by the File object. that are required by the File object.
The timestamp string should be a valid Unix Timestamp as defined in RFC xxxx. The timestamp string should be in a format: "YYYY-MM-DD HH:MM:SS" in UTC zone.
The rules object is a dictionary element, with the key as the Rule Name and The rules object is a dictionary element, with the key as the Rule Name and
value as the Rule Data. In most cases, the Rule Data is another dictionary. value as the Rule Data. In most cases, the Rule Data is another dictionary.

View File

@ -1,3 +1,6 @@
from os import utime
from time import strptime
from calendar import timegm
from conf import hook from conf import hook
""" Pre-Test Hook: LocalFiles """ Pre-Test Hook: LocalFiles
@ -16,3 +19,8 @@ class LocalFiles:
for f in self.local_files: for f in self.local_files:
with open(f.name, 'w') as fp: with open(f.name, 'w') as fp:
fp.write(f.content) fp.write(f.content)
if f.timestamp is not None:
tstamp = timegm(strptime(f.timestamp, '%Y-%m-%d %H:%M:%S'))
atime = tstamp
mtime = tstamp
utime(f.name, (atime, mtime))