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