11import os
2+ import sys
3+ from datetime import datetime
24from pathlib import Path
35from typing import List
46
7+ import pytest
8+ from pytest_httpserver import HTTPServer
9+
510from cwltool .pathmapper import PathMapper
611from cwltool .utils import CWLObjectType
712
@@ -25,3 +30,47 @@ def test_http_path_mapping(tmp_path: Path) -> None:
2530 contents = file .read ()
2631
2732 assert ">Sequence 561 BP; 135 A; 106 C; 98 G; 222 T; 0 other;" in contents
33+
34+
35+ @pytest .mark .skipif (sys .version_info < (3 , 7 ), reason = "timesout on CI" )
36+ def test_modification_date (tmp_path : Path ) -> None :
37+ """Local copies of remote files should preserve last modification date."""
38+ # Initialize the server
39+ headers = {
40+ "Server" : "nginx" ,
41+ "Date" : "Mon, 27 Jun 2022 14:26:17 GMT" ,
42+ "Content-Type" : "application/zip" ,
43+ "Content-Length" : "123906" ,
44+ "Connection" : "keep-alive" ,
45+ "Last-Modified" : "Tue, 14 Dec 2021 14:23:30 GMT" ,
46+ "ETag" : '"1e402-5d31beef49671"' ,
47+ "Accept-Ranges" : "bytes" ,
48+ "Strict-Transport-Security" : "max-age=31536000; includeSubDomains" ,
49+ }
50+
51+ remote_file_name = "testfile.txt"
52+
53+ with HTTPServer () as httpserver :
54+ httpserver .expect_request (f"/{ remote_file_name } " ).respond_with_data (
55+ response_data = "Hello World" , headers = headers
56+ )
57+ location = httpserver .url_for (f"/{ remote_file_name } " )
58+
59+ base_file : List [CWLObjectType ] = [
60+ {
61+ "class" : "File" ,
62+ "location" : location ,
63+ "basename" : remote_file_name ,
64+ }
65+ ]
66+
67+ date_now = datetime .now ()
68+
69+ pathmap = PathMapper (base_file , os .getcwd (), str (tmp_path ))._pathmap
70+
71+ assert location in pathmap
72+ assert os .path .exists (pathmap [location ].resolved )
73+
74+ last_modified = os .path .getmtime (pathmap [location ].resolved )
75+
76+ assert date_now .timestamp () > last_modified
0 commit comments