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


Python Topology.removeImage方法代码示例

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


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

示例1: test_image_in_project

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import removeImage [as 别名]
def test_image_in_project(tmpdir):
    project_dir = tmpdir / "project" / "project-files"
    os.makedirs(str(project_dir / "images"))

    project = Project()
    project.setFilesDir(str(tmpdir / "project"))

    topology = Topology()
    topology.project = project

    with open(str(project_dir / "images" / "1.jpg"), "w+") as f:
        f.write("AA")

    image1 = PixmapImageItem(None, "images/1.jpg")
    topology.addImage(image1)
    assert image1 in topology._images

    image2 = PixmapImageItem(None, "images/1.jpg")
    topology.addImage(image2)
    assert image1 in topology._images
    assert image2 in topology._images

    topology.removeImage(image2)
    assert os.path.exists(str(project_dir / "images" / "1.jpg"))

    # If not image use this file delete it
    topology.removeImage(image1)
    assert not os.path.exists(str(project_dir / "images" / "1.jpg"))
开发者ID:GMarciales,项目名称:gns3-gui,代码行数:30,代码来源:test_topology.py

示例2: test_image_outside_project

# 需要导入模块: from gns3.topology import Topology [as 别名]
# 或者: from gns3.topology.Topology import removeImage [as 别名]
def test_image_outside_project(tmpdir):
    """
    By security we do not delete image outside project.
    This should not append but if someone reuse the image items for
    something else.
    """

    project_img_dir = tmpdir / "project" / "project-files" / "images"
    os.makedirs(str(project_img_dir))

    project = Project()
    project.setFilesDir(str(tmpdir / "project"))

    topology = Topology()
    topology.project = project

    with open(str(tmpdir / "1.jpg"), "w+") as f:
        f.write("AA")

    image1 = PixmapImageItem(None, str(tmpdir / "1.jpg"))
    topology.addImage(image1)
    assert image1 in topology._images
    topology.removeImage(image1)
    assert os.path.exists(str(tmpdir / "1.jpg"))
开发者ID:GMarciales,项目名称:gns3-gui,代码行数:26,代码来源:test_topology.py


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