22
33import hashlib
44import json
5- import os .path
6- import urllib .parse
75from typing import Any , Callable , Dict , Optional , Set
6+ import cwltest .stdfsaccess
7+
8+ fs_access = cwltest .stdfsaccess .StdFsAccess ("" )
89
910
1011class CompareFail (Exception ):
@@ -130,13 +131,14 @@ def _compare_location(
130131 actual_comp = "path"
131132 else :
132133 actual_comp = "location"
133- path = urllib . parse . urlparse ( actual [ actual_comp ]). path
134+
134135 if actual .get ("class" ) == "Directory" :
135136 actual [actual_comp ] = actual [actual_comp ].rstrip ("/" )
136- exist_fun : Callable [[str ], bool ] = os . path .isdir
137+ exist_fun : Callable [[str ], bool ] = fs_access .isdir
137138 else :
138- exist_fun = os .path .isfile
139- if not exist_fun (path ) and not skip_details :
139+ exist_fun = fs_access .isfile
140+
141+ if not exist_fun (actual [actual_comp ]) and not skip_details :
140142 raise CompareFail .format (
141143 expected ,
142144 actual ,
@@ -160,15 +162,17 @@ def _compare_location(
160162
161163def _compare_checksum (expected : Dict [str , Any ], actual : Dict [str , Any ]) -> None :
162164 if "path" in actual :
163- path = urllib . parse . urlparse ( actual ["path" ]). path
165+ path = actual ["path" ]
164166 else :
165- path = urllib . parse . urlparse ( actual ["location" ]). path
167+ path = actual ["location" ]
166168 checksum = hashlib .sha1 () # nosec
167- with open (path , "rb" ) as f :
169+
170+ with fs_access .open (path , "rb" ) as f :
168171 contents = f .read (1024 * 1024 )
169172 while contents != b"" :
170173 checksum .update (contents )
171174 contents = f .read (1024 * 1024 )
175+
172176 actual_checksum_on_disk = f"sha1${ checksum .hexdigest ()} "
173177 if "checksum" in actual :
174178 actual_checksum_declared = actual ["checksum" ]
@@ -193,10 +197,12 @@ def _compare_checksum(expected: Dict[str, Any], actual: Dict[str, Any]) -> None:
193197
194198def _compare_size (expected : Dict [str , Any ], actual : Dict [str , Any ]) -> None :
195199 if "path" in actual :
196- path = urllib . parse . urlparse ( actual ["path" ]). path
200+ path = actual ["path" ]
197201 else :
198- path = urllib .parse .urlparse (actual ["location" ]).path
199- actual_size_on_disk = os .path .getsize (path )
202+ path = actual ["location" ]
203+
204+ actual_size_on_disk = fs_access .size (path )
205+
200206 if "size" in actual :
201207 actual_size_declared = actual ["size" ]
202208 if actual_size_on_disk != actual_size_declared :
0 commit comments