本文整理匯總了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')