當前位置: 首頁>>代碼示例>>Python>>正文


Python Image._add_markers方法代碼示例

本文整理匯總了Python中docker_squash.image.Image._add_markers方法的典型用法代碼示例。如果您正苦於以下問題:Python Image._add_markers方法的具體用法?Python Image._add_markers怎麽用?Python Image._add_markers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docker_squash.image.Image的用法示例。


在下文中一共展示了Image._add_markers方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestAddMarkers

# 需要導入模塊: from docker_squash.image import Image [as 別名]
# 或者: from docker_squash.image.Image import _add_markers [as 別名]
class TestAddMarkers(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)

    def test_should_not_fail_with_empty_list_of_markers_to_add(self):
        self.squash._add_markers({}, None, None)

    def test_should_add_all_marker_files_to_empty_tar(self):
        tar = mock.Mock()

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')

        markers = {marker_1: 'file'}
        with mock.patch('docker_squash.image.Image._files_in_layers', return_value={}):
            self.squash._add_markers(markers, tar, None)

        self.assertTrue(len(tar.addfile.mock_calls) == 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'file')
        self.assertTrue(tar_info.isfile())

    def test_should_skip_a_marker_file_if_file_is_in_unsquashed_layers(self):
        tar = mock.Mock()

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')

        markers = {marker_1: 'file1', marker_2: 'file2'}
        self.squash._add_markers(markers, tar, {'1234layerdid': ['some/file', 'marker_1']})

        self.assertEqual(len(tar.addfile.mock_calls), 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'file2')
        self.assertTrue(tar_info.isfile())

    def test_should_not_add_any_marker_files(self):
        tar = mock.Mock()

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')

        markers = {marker_1: 'file1', marker_2: 'file2'}
        self.squash._add_markers(markers, tar, {'1234layerdid': ['some/file', 'marker_1', 'marker_2']})

        self.assertTrue(len(tar.addfile.mock_calls) == 0)
開發者ID:knrc,項目名稱:docker-squash,代碼行數:58,代碼來源:test_unit_v1_image.py

示例2: TestAddMarkers

# 需要導入模塊: from docker_squash.image import Image [as 別名]
# 或者: from docker_squash.image.Image import _add_markers [as 別名]
class TestAddMarkers(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)

    def test_should_not_fail_with_empty_list_of_markers_to_add(self):
        self.squash._add_markers({}, None, None, [])

    def test_should_add_all_marker_files_to_empty_tar(self):
        tar = mock.Mock()
        tar.getnames.return_value = []

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')

        markers = {marker_1: 'file'}
        self.squash._add_markers(markers, tar, {}, [])

        self.assertTrue(len(tar.addfile.mock_calls) == 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'file')
        self.assertTrue(tar_info.isfile())

    def test_should_add_all_marker_files_to_empty_tar_besides_what_should_be_skipped(self):
        tar = mock.Mock()
        tar.getnames.return_value = []

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')

        markers = {marker_1: 'file1', marker_2: 'file2'}
        self.squash._add_markers(markers, tar, {'1234layerdid': ['/marker_1', '/marker_2']}, [['/marker_1']])

        self.assertEqual(len(tar.addfile.mock_calls), 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'file2')
        self.assertTrue(tar_info.isfile())

    def test_should_skip_a_marker_file_if_file_is_in_unsquashed_layers(self):
        tar = mock.Mock()
        # List of files in the squashed tar
        tar.getnames.return_value = ['marker_1']

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')
        # List of marker files to add back
        markers = {marker_1: 'marker_1', marker_2: 'marker_2'}
        # List of files in all layers to be moved
        files_in_moved_layers = {'1234layerdid': ['/some/file', '/marker_2']}
        self.squash._add_markers(markers, tar, files_in_moved_layers, [])

        self.assertEqual(len(tar.addfile.mock_calls), 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'marker_2')
        self.assertTrue(tar_info.isfile())

    def test_should_not_add_any_marker_files(self):
        tar = mock.Mock()
        tar.getnames.return_value = ['marker_1', 'marker_2']

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')

        markers = {marker_1: 'file1', marker_2: 'file2'}
        self.squash._add_markers(markers, tar, {'1234layerdid': ['some/file', 'marker_1', 'marker_2']}, [])

        self.assertTrue(len(tar.addfile.mock_calls) == 0)

    # https://github.com/goldmann/docker-squash/issues/108
    def test_should_add_marker_file_when_tar_has_prefixed_entries(self):
        tar = mock.Mock()
        # Files already in tar
        tar.getnames.return_value = ['./abc', './def']

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.some/file')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.file2')

        markers = {marker_1: 'filecontent1', marker_2: 'filecontent2'}

        # List of layers to move (and files in these layers), already normalized
        self.squash._add_markers(markers, tar, {'1234layerdid': ['/some/file', '/other/file', '/stuff']}, [])

        self.assertEqual(len(tar.addfile.mock_calls), 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        # We need to add the marker file because we need to
#.........這裏部分代碼省略.........
開發者ID:gcstang,項目名稱:docker-scripts,代碼行數:103,代碼來源:test_unit_v1_image.py

示例3: TestAddMarkers

# 需要導入模塊: from docker_squash.image import Image [as 別名]
# 或者: from docker_squash.image.Image import _add_markers [as 別名]
class TestAddMarkers(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)

    def test_should_not_fail_with_empty_list_of_markers_to_add(self):
        self.squash._add_markers({}, None, None)

    def test_should_add_all_marker_files_to_empty_tar(self):
        tar = mock.Mock()
        tar.getnames.return_value = []

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')

        markers = {marker_1: 'file'}
        self.squash._add_markers(markers, tar, {})

        self.assertTrue(len(tar.addfile.mock_calls) == 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'file')
        self.assertTrue(tar_info.isfile())

    def test_should_skip_a_marker_file_if_file_is_in_unsquashed_layers(self):
        tar = mock.Mock()
        # List of files in the squashed tar
        tar.getnames.return_value = ['marker_1']

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')
        # List of marker files to add back
        markers = {marker_1: 'marker_1', marker_2: 'marker_2'}
        # List of files in all layers to be moved
        files_in_moved_layers = {'1234layerdid': ['some/file', 'marker_2']}
        self.squash._add_markers(markers, tar, files_in_moved_layers)

        self.assertTrue(len(tar.addfile.mock_calls) == 1)
        tar_info, marker_file = tar.addfile.call_args[0]
        self.assertIsInstance(tar_info, tarfile.TarInfo)
        self.assertTrue(marker_file == 'marker_2')
        self.assertTrue(tar_info.isfile())

    def test_should_not_add_any_marker_files(self):
        tar = mock.Mock()
        tar.getnames.return_value = ['marker_1', 'marker_2']

        marker_1 = mock.Mock()
        type(marker_1).name = mock.PropertyMock(return_value='.wh.marker_1')
        marker_2 = mock.Mock()
        type(marker_2).name = mock.PropertyMock(return_value='.wh.marker_2')

        markers = {marker_1: 'file1', marker_2: 'file2'}
        self.squash._add_markers(markers, tar, {'1234layerdid': ['some/file', 'marker_1', 'marker_2']})

        self.assertTrue(len(tar.addfile.mock_calls) == 0)
開發者ID:phpdude,項目名稱:docker-squash,代碼行數:63,代碼來源:test_unit_v1_image.py


注:本文中的docker_squash.image.Image._add_markers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。