Пример #1
0
def test_get_size():

    with open("tests/resources/nvram_iou", "rb") as f:
        res = get_size(f.read(), default_width=100, default_height=50)
        assert res == (100, 50, None)
    with open("tests/resources/gns3_icon_128x64.gif", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "gif")
    with open("tests/resources/gns3_icon_128x64.jpg", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "jpg")
    with open("tests/resources/gns3_icon_128x64.png", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "png")
    with open("gns3server/symbols/classic/dslam.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (50, 53, "svg")
    # Symbol using size with cm
    with open("gns3server/symbols/classic/cloud.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (159, 71, "svg")
    # Size with px
    with open("tests/resources/firefox.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (66, 70, "svg")
Пример #2
0
 def svg(self):
     if "<svg" not in self._svg:
         try:
             filename = os.path.basename(self._svg)
             with open(os.path.join(self._project.pictures_directory, filename), "rb") as f:
                 data = f.read()
                 try:
                     return data.decode()
                 except UnicodeError:
                     width, height, filetype = get_size(data)
                     return "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"{height}\" width=\"{width}\">\n<image height=\"{height}\" width=\"{width}\" xlink:href=\"data:image/{filetype};base64,{b64}\" />\n</svg>".format(b64=base64.b64encode(data).decode(), filetype=filetype, width=width, height=height)
         except OSError:
             log.warning("Image file %s missing", filename)
             return "<svg></svg>"
     return self._svg
Пример #3
0
 def svg(self):
     if "<svg" not in self._svg:
         try:
             filename = os.path.basename(self._svg)
             with open(
                     os.path.join(self._project.pictures_directory,
                                  filename), "rb") as f:
                 data = f.read()
                 try:
                     return data.decode()
                 except UnicodeError:
                     width, height, filetype = get_size(data)
                     return "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"{height}\" width=\"{width}\">\n<image height=\"{height}\" width=\"{width}\" xlink:href=\"data:image/{filetype};base64,{b64}\" />\n</svg>".format(
                         b64=base64.b64encode(data).decode(),
                         filetype=filetype,
                         width=width,
                         height=height)
         except OSError:
             log.warning("Image file %s missing", filename)
             return "<svg></svg>"
     return self._svg
Пример #4
0
def test_get_size():
    with open("tests/resources/nvram_iou", "rb") as f:
        res = get_size(f.read(), default_width=100, default_height=50)
        assert res == (100, 50, None)
    with open("tests/resources/gns3_icon_128x64.gif", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "gif")
    with open("tests/resources/gns3_icon_128x64.jpg", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "jpg")
    with open("tests/resources/gns3_icon_128x64.png", "rb") as f:
        res = get_size(f.read())
        assert res == (128, 64, "png")
    with open("gns3server/symbols/dslam.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (50, 53, "svg")
    # Symbol using size with cm
    with open("gns3server/symbols/cloud.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (159, 71, "svg")
    # Size with px
    with open("tests/resources/firefox.svg", "rb") as f:
        res = get_size(f.read())
        assert res == (66, 70, "svg")