File tree 2 files changed +34
-0
lines changed
tests/unit/sagemaker/workflow
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
from typing import List , Sequence , Union
17
17
import hashlib
18
+ from urllib .parse import unquote , urlparse
18
19
19
20
from sagemaker .workflow .entities import (
20
21
Entity ,
@@ -50,6 +51,8 @@ def hash_file(path: str) -> str:
50
51
"""
51
52
BUF_SIZE = 65536 # read in 64KiB chunks
52
53
md5 = hashlib .md5 ()
54
+ if path .lower ().startswith ("file://" ):
55
+ path = unquote (urlparse (path ).path )
53
56
with open (path , "rb" ) as f :
54
57
while True :
55
58
data = f .read (BUF_SIZE )
Original file line number Diff line number Diff line change
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+ # language governing permissions and limitations under the License.
14
+ from __future__ import absolute_import
15
+
16
+ import tempfile
17
+ from sagemaker .workflow .utilities import hash_file
18
+
19
+
20
+ def test_hash_file ():
21
+ with tempfile .NamedTemporaryFile () as tmp :
22
+ tmp .write ("hashme" .encode ())
23
+ hash = hash_file (tmp .name )
24
+ assert hash == "d41d8cd98f00b204e9800998ecf8427e"
25
+
26
+
27
+ def test_hash_file_uri ():
28
+ with tempfile .NamedTemporaryFile () as tmp :
29
+ tmp .write ("hashme" .encode ())
30
+ hash = hash_file (f"file:///{ tmp .name } " )
31
+ assert hash == "d41d8cd98f00b204e9800998ecf8427e"
You can’t perform that action at this time.
0 commit comments