本文整理汇总了Python中tests.unit.customizations.s3.fake_session.FakeSession.get_config方法的典型用法代码示例。如果您正苦于以下问题:Python FakeSession.get_config方法的具体用法?Python FakeSession.get_config怎么用?Python FakeSession.get_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.unit.customizations.s3.fake_session.FakeSession
的用法示例。
在下文中一共展示了FakeSession.get_config方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CommandParametersTest
# 需要导入模块: from tests.unit.customizations.s3.fake_session import FakeSession [as 别名]
# 或者: from tests.unit.customizations.s3.fake_session.FakeSession import get_config [as 别名]
class CommandParametersTest(unittest.TestCase):
def setUp(self):
self.environ = {}
self.environ_patch = patch('os.environ', self.environ)
self.environ_patch.start()
self.session = FakeSession()
self.mock = MagicMock()
self.mock.get_config = MagicMock(return_value={'region': None})
self.loc_files = make_loc_files()
self.bucket = make_s3_files(self.session)
def tearDown(self):
self.environ_patch.stop()
clean_loc_files(self.loc_files)
s3_cleanup(self.bucket, self.session)
def test_add_paths(self):
"""
This ensures that the paths are assigned properly in the
class's parameters dictionary.
"""
s3_file = 's3://' + self.bucket + '/' + 'text1.txt'
path1 = [s3_file, 's3://some_file']
path2 = [s3_file]
cmd_params = CommandParameters(self.session, 'cp', {})
cmd_params2 = CommandParameters(self.session, 'rm', {})
cmd_params.check_region([])
cmd_params2.check_region([])
cmd_params.add_paths(path1)
cmd_params2.add_paths(path2)
ref_params = {'dir_op': False, 'src': s3_file,
'dest': 's3://some_file',
'region': self.session.get_config()['region'],
'paths_type': 's3s3'}
self.assertEqual(cmd_params.parameters, ref_params)
ref_params2 = {'dir_op': False, 'src': s3_file, 'dest': s3_file,
'region': self.session.get_config()['region'],
'paths_type': 's3'}
self.assertEqual(cmd_params2.parameters, ref_params2)
def test_check_path_type_pass(self):
"""
This tests the class's ability to determine whether the correct
path types have been passed for a particular command. It test every
possible combination that is correct for every command.
"""
cmds = {'cp': ['locals3', 's3s3', 's3local'],
'mv': ['locals3', 's3s3', 's3local'],
'rm': ['s3'], 'ls': ['s3'], 'mb': ['s3'], 'rb': ['s3'],
'sync': ['locals3', 's3s3', 's3local']}
s3_file = 's3://' + self.bucket + '/' + 'text1.txt'
local_file = self.loc_files[0]
combos = {'s3s3': [s3_file, s3_file],
's3local': [s3_file, local_file],
'locals3': [local_file, s3_file],
's3': [s3_file],
'local': [local_file],
'locallocal': [local_file, local_file]}
for cmd in cmds.keys():
cmd_param = CommandParameters(self.session, cmd, {})
cmd_param.check_region([])
correct_paths = cmds[cmd]
for path_args in correct_paths:
cmd_param.check_path_type(combos[path_args])
def test_check_path_type_fail(self):
"""
This tests the class's ability to determine whether the correct
path types have been passed for a particular command. It test every
possible combination that is incorrect for every command.
"""
cmds = {'cp': ['local', 'locallocal', 's3'],
'mv': ['local', 'locallocal', 's3'],
'rm': ['local', 'locallocal', 's3s3', 'locals3', 's3local'],
'ls': ['local', 'locallocal', 's3s3', 'locals3', 's3local'],
'sync': ['local', 'locallocal', 's3'],
'mb': ['local', 'locallocal', 's3s3', 'locals3', 's3local'],
'rb': ['local', 'locallocal', 's3s3', 'locals3', 's3local']}
s3_file = 's3://' + self.bucket + '/' + 'text1.txt'
local_file = self.loc_files[0]
combos = {'s3s3': [s3_file, s3_file],
's3local': [s3_file, local_file],
'locals3': [local_file, s3_file],
's3': [s3_file],
'local': [local_file],
'locallocal': [local_file, local_file]}
for cmd in cmds.keys():
cmd_param = CommandParameters(self.session, cmd, {})
cmd_param.check_region([])
wrong_paths = cmds[cmd]
for path_args in wrong_paths:
with self.assertRaises(TypeError):
cmd_param.check_path_type(combos[path_args])
def test_check_src_path_pass(self):
#.........这里部分代码省略.........
示例2: CommandParametersTest
# 需要导入模块: from tests.unit.customizations.s3.fake_session import FakeSession [as 别名]
# 或者: from tests.unit.customizations.s3.fake_session.FakeSession import get_config [as 别名]
class CommandParametersTest(unittest.TestCase):
def setUp(self):
self.environ = {}
self.environ_patch = patch("os.environ", self.environ)
self.environ_patch.start()
self.session = FakeSession()
self.mock = MagicMock()
self.mock.get_config = MagicMock(return_value={"region": None})
self.loc_files = make_loc_files()
self.bucket = make_s3_files(self.session)
def tearDown(self):
self.environ_patch.stop()
clean_loc_files(self.loc_files)
s3_cleanup(self.bucket, self.session)
def test_add_paths(self):
"""
This ensures that the paths are assigned properly in the
class's parameters dictionary.
"""
s3_file = "s3://" + self.bucket + "/" + "text1.txt"
path1 = [s3_file, "s3://some_file"]
path2 = [s3_file]
cmd_params = CommandParameters(self.session, "cp", {})
cmd_params2 = CommandParameters(self.session, "rm", {})
cmd_params.check_region([])
cmd_params2.check_region([])
cmd_params.add_paths(path1)
cmd_params2.add_paths(path2)
ref_params = {
"dir_op": False,
"src": s3_file,
"dest": "s3://some_file",
"region": self.session.get_config()["region"],
"paths_type": "s3s3",
}
self.assertEqual(cmd_params.parameters, ref_params)
ref_params2 = {
"dir_op": False,
"src": s3_file,
"dest": s3_file,
"region": self.session.get_config()["region"],
"paths_type": "s3",
}
self.assertEqual(cmd_params2.parameters, ref_params2)
def test_check_path_type_pass(self):
"""
This tests the class's ability to determine whether the correct
path types have been passed for a particular command. It test every
possible combination that is correct for every command.
"""
cmds = {
"cp": ["locals3", "s3s3", "s3local"],
"mv": ["locals3", "s3s3", "s3local"],
"rm": ["s3"],
"ls": ["s3"],
"mb": ["s3"],
"rb": ["s3"],
"sync": ["locals3", "s3s3", "s3local"],
}
s3_file = "s3://" + self.bucket + "/" + "text1.txt"
local_file = self.loc_files[0]
combos = {
"s3s3": [s3_file, s3_file],
"s3local": [s3_file, local_file],
"locals3": [local_file, s3_file],
"s3": [s3_file],
"local": [local_file],
"locallocal": [local_file, local_file],
}
for cmd in cmds.keys():
cmd_param = CommandParameters(self.session, cmd, {})
cmd_param.check_region([])
correct_paths = cmds[cmd]
for path_args in correct_paths:
cmd_param.check_path_type(combos[path_args])
def test_check_path_type_fail(self):
"""
This tests the class's ability to determine whether the correct
path types have been passed for a particular command. It test every
possible combination that is incorrect for every command.
"""
cmds = {
"cp": ["local", "locallocal", "s3"],
"mv": ["local", "locallocal", "s3"],
"rm": ["local", "locallocal", "s3s3", "locals3", "s3local"],
"ls": ["local", "locallocal", "s3s3", "locals3", "s3local"],
"sync": ["local", "locallocal", "s3"],
"mb": ["local", "locallocal", "s3s3", "locals3", "s3local"],
"rb": ["local", "locallocal", "s3s3", "locals3", "s3local"],
}
s3_file = "s3://" + self.bucket + "/" + "text1.txt"
local_file = self.loc_files[0]
#.........这里部分代码省略.........