Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/s3/__init__.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
15
16
class FakeTransferFuture(object):
17
def __init__(self, result=None, exception=None, meta=None):
18
self._result = result
19
self._exception = exception
20
self.meta = meta
21
22
def result(self):
23
if self._exception:
24
raise self._exception
25
return self._result
26
27
28
class FakeTransferFutureMeta(object):
29
def __init__(self, size=None, call_args=None, transfer_id=None):
30
self.size = size
31
self.call_args = call_args
32
self.transfer_id = transfer_id
33
34
35
class FakeTransferFutureCallArgs(object):
36
def __init__(self, **kwargs):
37
for kwarg, val in kwargs.items():
38
setattr(self, kwarg, val)
39
40
41
def make_loc_files(file_creator, size=None):
42
"""
43
This sets up the test by making a directory named some_directory. It
44
has the file text1.txt and the directory another_directory inside. Inside
45
of another_directory it creates the file text2.txt.
46
"""
47
if size:
48
body = "*" * size
49
else:
50
body = 'This is a test.'
51
52
filename1 = file_creator.create_file(
53
os.path.join('some_directory', 'text1.txt'), body)
54
55
filename2 = file_creator.create_file(
56
os.path.join('some_directory', 'another_directory', 'text2.txt'), body)
57
filename1 = str(filename1)
58
filename2 = str(filename2)
59
return [filename1, filename2, os.path.dirname(filename2),
60
os.path.dirname(filename1)]
61
62
63
def clean_loc_files(file_creator):
64
"""
65
Removes all of the local files made.
66
"""
67
file_creator.remove_all()
68
69
70
def compare_files(self, result_file, ref_file):
71
"""
72
Ensures that the FileStat's properties are what they
73
are suppose to be.
74
"""
75
self.assertEqual(result_file.src, ref_file.src)
76
self.assertEqual(result_file.dest, ref_file.dest)
77
self.assertEqual(result_file.compare_key, ref_file.compare_key)
78
self.assertEqual(result_file.size, ref_file.size)
79
self.assertEqual(result_file.last_update, ref_file.last_update)
80
self.assertEqual(result_file.src_type, ref_file.src_type)
81
self.assertEqual(result_file.dest_type, ref_file.dest_type)
82
self.assertEqual(result_file.operation_name, ref_file.operation_name)
83
84