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


Python Image._generate_repositories_json方法代碼示例

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


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

示例1: TestGenerateRepositoriesJSON

# 需要導入模塊: from docker_squash.image import Image [as 別名]
# 或者: from docker_squash.image.Image import _generate_repositories_json [as 別名]
class TestGenerateRepositoriesJSON(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_generate_json(self):
        image_id = '12323dferwt4awefq23rasf'
        with mock.patch.object(six.moves.builtins, 'open', mock.mock_open()) as mock_file:
            self.squash._generate_repositories_json(
                'file', image_id, 'name', 'tag')

            self.assertIn(mock.call().write('{"name":{"tag":"12323dferwt4awefq23rasf"}}'), mock_file.mock_calls)
            self.assertIn(mock.call().write('\n'), mock_file.mock_calls)

    def test_handle_empty_image_id(self):
        with mock.patch.object(six.moves.builtins, 'open', mock.mock_open()) as mock_file:
            with self.assertRaises(SquashError) as cm:
                self.squash._generate_repositories_json(
                    'file', None, 'name', 'tag')

            self.assertEquals(
                str(cm.exception), 'Provided image id cannot be null')
            mock_file().write.assert_not_called()

    def test_should_not_generate_repositories_if_name_and_tag_is_missing(self):
        self.squash._generate_repositories_json('file', 'abcd', None, None)
        self.log.debug.assert_called_with("No name and tag provided for the image, skipping generating repositories file")
開發者ID:gcstang,項目名稱:docker-scripts,代碼行數:32,代碼來源:test_unit_v1_image.py


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