Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/test_fileformat.py
1569 views
1
# Copyright 2013 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
import os
14
import unittest
15
16
from awscli.customizations.s3.fileformat import FileFormat
17
18
19
class FileFormatTest(unittest.TestCase):
20
def setUp(self):
21
self.file_format = FileFormat()
22
23
def test_op_dir(self):
24
"""
25
Format a paths for directory operation. There are slashes at the
26
end of the paths.
27
"""
28
src = '.' + os.sep
29
dest = 's3://kyknapp/golfVid/'
30
parameters = {'dir_op': True}
31
files = self.file_format.format(src, dest, parameters)
32
33
ref_files = {'src': {'path': os.path.abspath(src) + os.sep,
34
'type': 'local'},
35
'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},
36
'dir_op': True, 'use_src_name': True}
37
self.assertEqual(files, ref_files)
38
39
def test_op_dir_noslash(self):
40
"""
41
Format a paths for directory operation. There are no slashes at the
42
end of the paths.
43
"""
44
src = '.'
45
dest = 's3://kyknapp/golfVid'
46
parameters = {'dir_op': True}
47
files = self.file_format.format(src, dest, parameters)
48
49
ref_files = {'src': {'path': os.path.abspath(src) + os.sep,
50
'type': 'local'},
51
'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},
52
'dir_op': True, 'use_src_name': True}
53
self.assertEqual(files, ref_files)
54
55
def test_local_use_src_name(self):
56
"""
57
No directory operation. S3 source name given. Existing local
58
destination directory given.
59
"""
60
src = 's3://kyknapp/golfVid/hello.txt'
61
dest = '.'
62
parameters = {'dir_op': False}
63
files = self.file_format.format(src, dest, parameters)
64
65
ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',
66
'type': 's3'},
67
'dest': {'path': os.path.abspath(dest) + os.sep,
68
'type': 'local'},
69
'dir_op': False, 'use_src_name': True}
70
self.assertEqual(files, ref_files)
71
72
def test_local_noexist_file(self):
73
"""
74
No directory operation. S3 source name given. Nonexisting local
75
destination directory given.
76
"""
77
src = 's3://kyknapp/golfVid/hello.txt'
78
dest = 'someFile' + os.sep
79
parameters = {'dir_op': False}
80
files = self.file_format.format(src, dest, parameters)
81
82
ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',
83
'type': 's3'},
84
'dest': {'path': os.path.abspath(dest) + os.sep,
85
'type': 'local'},
86
'dir_op': False, 'use_src_name': True}
87
self.assertEqual(files, ref_files)
88
89
def test_local_keep_dest_name(self):
90
"""
91
No directory operation. S3 source name given. Local
92
destination filename given.
93
"""
94
src = 's3://kyknapp/golfVid/hello.txt'
95
dest = 'hello.txt'
96
parameters = {'dir_op': False}
97
files = self.file_format.format(src, dest, parameters)
98
99
ref_files = {'src': {'path': 'kyknapp/golfVid/hello.txt',
100
'type': 's3'},
101
'dest': {'path': os.path.abspath(dest),
102
'type': 'local'},
103
'dir_op': False, 'use_src_name': False}
104
self.assertEqual(files, ref_files)
105
106
def test_s3_use_src_name(self):
107
"""
108
No directory operation. Local source name given. S3
109
common prefix given.
110
"""
111
src = 'fileformat_test.py'
112
dest = 's3://kyknapp/golfVid/'
113
parameters = {'dir_op': False}
114
files = self.file_format.format(src, dest, parameters)
115
116
ref_files = {'src': {'path': os.path.abspath(src),
117
'type': 'local'},
118
'dest': {'path': 'kyknapp/golfVid/', 'type': 's3'},
119
'dir_op': False, 'use_src_name': True}
120
self.assertEqual(files, ref_files)
121
122
def test_s3_keep_dest_name(self):
123
"""
124
No directory operation. Local source name given. S3
125
full key given.
126
"""
127
src = 'fileformat_test.py'
128
dest = 's3://kyknapp/golfVid/file.py'
129
parameters = {'dir_op': False}
130
files = self.file_format.format(src, dest, parameters)
131
132
ref_files = {'src': {'path': os.path.abspath(src),
133
'type': 'local'},
134
'dest': {'path': 'kyknapp/golfVid/file.py', 'type': 's3'},
135
'dir_op': False, 'use_src_name': False}
136
self.assertEqual(files, ref_files)
137
138
139
if __name__ == "__main__":
140
unittest.main()
141
142