本文整理汇总了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")