当前位置: 首页>>代码示例>>Python>>正文


Python Format.image_to_html方法代码示例

本文整理汇总了Python中wagtail.wagtailimages.formats.Format.image_to_html方法的典型用法代码示例。如果您正苦于以下问题:Python Format.image_to_html方法的具体用法?Python Format.image_to_html怎么用?Python Format.image_to_html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.wagtailimages.formats.Format的用法示例。


在下文中一共展示了Format.image_to_html方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestFormat

# 需要导入模块: from wagtail.wagtailimages.formats import Format [as 别名]
# 或者: from wagtail.wagtailimages.formats.Format import image_to_html [as 别名]
class TestFormat(TestCase):
    def setUp(self):
        # test format
        self.format = Format("test name", "test label", "test classnames", "test filter spec")
        # test image
        self.image = MagicMock()
        self.image.id = 0

    def test_editor_attributes(self):
        result = self.format.editor_attributes(self.image, "test alt text")
        self.assertEqual(result, 'data-embedtype="image" data-id="0" data-format="test name" data-alt="test alt text" ')

    def test_image_to_editor_html(self):
        result = self.format.image_to_editor_html(self.image, "test alt text")
        six.assertRegex(
            self,
            result,
            '<img data-embedtype="image" data-id="0" data-format="test name" data-alt="test alt text" class="test classnames" src="[^"]+" width="1" height="1" alt="test alt text">',
        )

    def test_image_to_html_no_classnames(self):
        self.format.classnames = None
        result = self.format.image_to_html(self.image, "test alt text")
        six.assertRegex(self, result, '<img src="[^"]+" width="1" height="1" alt="test alt text">')
        self.format.classnames = "test classnames"

    def test_get_image_format(self):
        register_image_format(self.format)
        result = get_image_format("test name")
        self.assertEqual(result, self.format)
开发者ID:carriercomm,项目名称:wagtail,代码行数:32,代码来源:tests.py


注:本文中的wagtail.wagtailimages.formats.Format.image_to_html方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。