| 1 |
from os import utime |
| 2 |
from time import strptime |
| 3 |
from calendar import timegm |
| 4 |
from conf import hook |
| 5 |
|
| 6 |
""" Pre-Test Hook: LocalFiles |
| 7 |
This is a pre-test hook used to generate the specific environment before a test |
| 8 |
is run. The LocalFiles hook creates the files which should exist on disk before |
| 9 |
invoking Wget. |
| 10 |
""" |
| 11 |
|
| 12 |
|
| 13 |
@hook() |
| 14 |
class LocalFiles: |
| 15 |
def __init__(self, local_files): |
| 16 |
self.local_files = local_files |
| 17 |
|
| 18 |
def __call__(self, _): |
| 19 |
for f in self.local_files: |
| 20 |
with open(f.name, 'w') as fp: |
| 21 |
fp.write(f.content) |
| 22 |
if f.timestamp is not None: |
| 23 |
tstamp = timegm(strptime(f.timestamp, '%Y-%m-%d %H:%M:%S')) |
| 24 |
atime = tstamp |
| 25 |
mtime = tstamp |
| 26 |
utime(f.name, (atime, mtime)) |