本文整理汇总了Python中docker_squash.image.Image._prepare_tmp_directory方法的典型用法代码示例。如果您正苦于以下问题:Python Image._prepare_tmp_directory方法的具体用法?Python Image._prepare_tmp_directory怎么用?Python Image._prepare_tmp_directory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker_squash.image.Image
的用法示例。
在下文中一共展示了Image._prepare_tmp_directory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPrepareTemporaryDirectory
# 需要导入模块: from docker_squash.image import Image [as 别名]
# 或者: from docker_squash.image.Image import _prepare_tmp_directory [as 别名]
class TestPrepareTemporaryDirectory(unittest.TestCase):
def setUp(self):
self.docker_client = mock.Mock()
self.log = mock.Mock()
self.image = "whatever"
self.squash = Image(self.log, self.docker_client, self.image, None)
@mock.patch('docker_squash.image.tempfile')
def test_create_tmp_directory_if_not_provided(self, mock_tempfile):
self.squash._prepare_tmp_directory(None)
mock_tempfile.mkdtemp.assert_called_with(prefix="docker-squash-")
@mock.patch('docker_squash.image.tempfile')
@mock.patch('docker_squash.image.os.path.exists', return_value=True)
def test_should_raise_if_directory_already_exists(self, mock_path, mock_tempfile):
with self.assertRaises(SquashError) as cm:
self.squash._prepare_tmp_directory('tmp')
self.assertEquals(
str(cm.exception), "The 'tmp' directory already exists, please remove it before you proceed")
mock_path.assert_called_with('tmp')
self.assertTrue(len(mock_tempfile.mkdtemp.mock_calls) == 0)
@mock.patch('docker_squash.image.os.path.exists', return_value=False)
@mock.patch('docker_squash.image.os.makedirs', return_value=False)
def test_should_use_provided_tmp_dir(self, mock_makedirs, mock_path):
self.assertEqual(self.squash._prepare_tmp_directory('tmp'), 'tmp')
mock_path.assert_called_with('tmp')
mock_makedirs.assert_called_with('tmp')