Пример #1
0
 def test_mirror_y(self):
     """Check that graphic is mirrored properly about the y axis."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_mirror_y(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #2
0
 def test_mirror_y(self):
     """Check that graphic is mirrored properly about the y axis."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_mirror_y(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #3
0
 def test_translate_2(self):
     """Check that graphic is translated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(500, 237.21)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert map(lambda x: round(x, 10), graphic.get_position()) == [500, 237.21], "Position should be 500,237.21!"
Пример #4
0
 def test_double_mirror_y(self):
     """Check that graphic is mirrored y properly twice."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic2 = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_mirror_y(True)
     graphic.set_mirror_y(False)
     assert graphic.get_bounding_box() == graphic2.get_bounding_box(
     ), "They should be the same!"
Пример #5
0
 def test_scale_y(self):
     """Check that graphic is scaled properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(3, 1)
     e = 1
     w = 333.469 * 3
     h = 170.563
     assert w - e < graphic.get_width() < w + e, "Graphic width is wrong after scaling!"
     assert h - e < graphic.get_height() < h + e, "Graphic height is wrong after scaling!"
Пример #6
0
 def test_weedline_3(self):
     """Check a weedline padding is added correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     graphic.set_weedline_padding(100)
     graphic.set_weedline(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_height() == h + 200
     assert graphic.get_width() == w + 200
Пример #7
0
 def test_weedline_2(self):
     """Check a weedline is removed correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     data = graphic._get_debug_data()
     graphic.set_weedline(True)
     graphic.set_weedline(False)
     assert graphic._get_debug_data() == data
Пример #8
0
 def test_double_mirror_y(self):
     """Check that graphic is mirrored y properly twice."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic2 = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_mirror_y(True)
     graphic.set_mirror_y(False)
     assert graphic.get_bounding_box() == graphic2.get_bounding_box(), "They should be the same!"
Пример #9
0
 def test_symmetric_x(self):
     """Check that a symmetric graphic is mirrored x properly."""
     graphic = Graphic(etree.parse("rectangle.svg").getroot())
     graphic2 = Graphic(etree.parse("rectangle.svg").getroot())
     graphic.set_mirror_x(True)
     assert graphic.get_bounding_box() == graphic2.get_bounding_box(
     ), "They should be the same!"
Пример #10
0
 def test_rotation_4(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     xml = graphic.get_xml()
     graphic.set_rotation(23.21)
     graphic.set_rotation(0)
     assert graphic.get_xml() == xml
Пример #11
0
 def test_weedline_2(self):
     """Check a weedline is removed correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     data = graphic._get_debug_data()
     graphic.set_weedline(True)
     graphic.set_weedline(False)
     assert graphic._get_debug_data() == data
Пример #12
0
 def test_rotation_4(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     xml = graphic.get_xml()
     graphic.set_rotation(23.21)
     graphic.set_rotation(0)
     assert graphic.get_xml() == xml
Пример #13
0
 def test_translate_3(self):
     """Check that graphic is translated properly twice."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(500, 237.21)
     graphic.set_position(11, 32)
     assert map(lambda x: round(x, 10),
                graphic.get_position()) == [11,
                                            32], "Position should be 11,32!"
Пример #14
0
 def test_scale_3(self):
     """Check that graphic is scaled properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(2.72)
     e = 1
     w = 333.469 * 2.72
     assert w - e < graphic.get_width(
     ) < w + e, "Graphic width is wrong after scaling!"
     graphic.set_scale(1)
     w = 333.469
     assert w - e < graphic.get_width(
     ) < w + e, "Graphic width is wrong after scaling the second time!"
Пример #15
0
 def test_case_5(self):
     """Check that graphic is scaled properly in the y direction."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(2)
     e = 1
     h = 170.563 * 2
     assert h - e < graphic.get_height(
     ) < h + e, "Graphic height is wrong after scaling!"
     graphic.set_scale(1)
     h = 170.563
     assert h - e < graphic.get_height(
     ) < h + e, "Graphic height is wrong after scaling the second time!"
Пример #16
0
 def test_rotation_3(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     pos = graphic.get_position()
     graphic.set_rotation(23.21)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_position() == pos
Пример #17
0
 def test_weedline(self):
     """Check a weedline is added correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     pos = graphic.get_position()
     graphic.set_weedline(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_position() == pos
Пример #18
0
 def test_scale_3(self):
     """Check that graphic is scaled properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(2.72)
     e = 1
     w = 333.469 * 2.72
     assert w - e < graphic.get_width() < w + e, "Graphic width is wrong after scaling!"
     graphic.set_scale(1)
     w = 333.469
     assert w - e < graphic.get_width() < w + e, "Graphic width is wrong after scaling the second time!"
Пример #19
0
 def test_case_5(self):
     """Check that graphic is scaled properly in the y direction."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(2)
     e = 1
     h = 170.563 * 2
     assert h - e < graphic.get_height() < h + e, "Graphic height is wrong after scaling!"
     graphic.set_scale(1)
     h = 170.563
     assert h - e < graphic.get_height() < h + e, "Graphic height is wrong after scaling the second time!"
Пример #20
0
 def test_translate_1(self):
     """Check that graphic is translated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(0, 0)
     log.info(graphic.get_position())
     assert map(lambda x: round(x, 10),
                graphic.get_position()) == [0, 0], "Position should be 0,0!"
Пример #21
0
 def test_rotation_3(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     pos = graphic.get_position()
     graphic.set_rotation(23.21)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_position() == pos
Пример #22
0
 def test_weedline(self):
     """Check a weedline is added correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     pos = graphic.get_position()
     graphic.set_weedline(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_position() == pos
Пример #23
0
 def test_translate_2(self):
     """Check that graphic is translated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(500, 237.21)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert map(lambda x: round(x, 10), graphic.get_position()) == [
         500, 237.21
     ], "Position should be 500,237.21!"
Пример #24
0
 def test_scale_y(self):
     """Check that graphic is scaled properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_scale(3, 1)
     e = 1
     w = 333.469 * 3
     h = 170.563
     assert w - e < graphic.get_width(
     ) < w + e, "Graphic width is wrong after scaling!"
     assert h - e < graphic.get_height(
     ) < h + e, "Graphic height is wrong after scaling!"
Пример #25
0
 def test_apply_cutting_overlap(self):
     """Test Plugin.apply_cutting_overlap()!"""
     overlap = 20
     plugin = Plugin()
     g = Graphic("arrow.svg")
     g.set_scale(HPGL.HPGL_SCALE,HPGL.HPGL_SCALE)
     paths = g.get_polyline()
     lengths = []
     for path in paths:
         lengths.append(g.get_path_length(path=path))
     
     plugin.apply_cutting_overlap(paths,overlap)
     for path,length in zip(paths,lengths):
         if path_is_closed(path):
             new_length = g.get_path_length(path=path)
             assert round(length+overlap,10) == round(new_length,10), "%s != %s" % (round(length+overlap,10),round(new_length,10))
         else:
             assert round(length,10) == round(new_length,10), "%s != %s" % (round(length,10),round(new_length,10))
Пример #26
0
    def test_apply_cutting_overlap(self):
        """Test Plugin.apply_cutting_overlap()!"""
        overlap = 20
        plugin = Plugin()
        g = Graphic("arrow.svg")
        g.set_scale(HPGL.HPGL_SCALE, HPGL.HPGL_SCALE)
        paths = g.get_polyline()
        lengths = []
        for path in paths:
            lengths.append(g.get_path_length(path=path))

        plugin.apply_cutting_overlap(paths, overlap)
        for path, length in zip(paths, lengths):
            if path_is_closed(path):
                new_length = g.get_path_length(path=path)
                assert round(length + overlap,
                             10) == round(new_length, 10), "%s != %s" % (round(
                                 length + overlap, 10), round(new_length, 10))
            else:
                assert round(length,
                             10) == round(new_length, 10), "%s != %s" % (round(
                                 length, 10), round(new_length, 10))
Пример #27
0
 def test_weedline_5(self):
     """Check a weedline padding is removed correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     pos = graphic.get_position()
     graphic.set_weedline_padding(10)
     graphic.set_weedline(True)
     graphic.set_weedline_padding(0)
     assert graphic.get_height() == h
     assert graphic.get_width() == w
     assert graphic.get_position() == pos
Пример #28
0
 def test_weedline_4(self):
     """Check a weedline padding is added correctly in reverse order."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     pos = graphic.get_position()
     graphic.set_weedline(True)
     graphic.set_weedline_padding(10)
     assert graphic.get_height() == h + 20
     assert graphic.get_width() == w + 20
     assert graphic.get_position() == pos
Пример #29
0
 def test_case_3(self):
     """Check the graphic height"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     e = 1
     h = 170.563
     assert h - e < graphic.get_height() < h + e, "Graphic height is wrong!"
Пример #30
0
 def test_symmetric_x(self):
     """Check that a symmetric graphic is mirrored x properly."""
     graphic = Graphic(etree.parse("rectangle.svg").getroot())
     graphic2 = Graphic(etree.parse("rectangle.svg").getroot())
     graphic.set_mirror_x(True)
     assert graphic.get_bounding_box() == graphic2.get_bounding_box(), "They should be the same!"
Пример #31
0
 def test_case_4(self):
     """Check the graphic width"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     e = 1
     w = 333.469
     assert w - e < graphic.get_width() < w + e, "Graphic width is wrong!"
Пример #32
0
 def test_case_2(self):
     """Create a graphic from etree elements"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #33
0
 def test_get_polyline(self):
     """ Check that get polyline works correctly."""
     graphic = Graphic(etree.parse("fat-giraffes.svg"))
     f = open("pout.py", "w")
     f.write("poly = %s" % graphic.get_polyline())
     f.close()
Пример #34
0
 def test_rotation_1(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     graphic.set_rotation(90)
     assert graphic.get_width() == h
Пример #35
0
 def test_adjusted_bbox(self):
     """Check that get_bounding_box(adjusted=True) works correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     bbox = graphic.get_bounding_box()
     h = graphic.get_height()
     w = graphic.get_width()
     graphic.set_weedline_padding(10)
     graphic.set_weedline(True)
     assert graphic.get_width(adjusted=True) == w, "%s != %s" % (graphic.get_width(adjusted=True), w)
     assert graphic.get_height(adjusted=True) == h, "%s != %s" % (graphic.get_height(adjusted=True), h)
     log.debug(bbox)
     log.debug(graphic.get_bounding_box(adjusted=True))
     assert graphic.get_bounding_box(adjusted=True) == bbox
Пример #36
0
 def test_changed_flag(self):
     """Check that changed flag works correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.reset_changed_flag()
     graphic.set_mirror_x(True)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_mirror_x(False)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_scale(2)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_rotation(2)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_position(2, 500)
     assert not graphic.get_changed_flag(), "Changed flag should not be set!"
     graphic.reset_changed_flag()
     graphic.set_weedline(True)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
Пример #37
0
 def test_get_polyline(self):
     """ Check that get polyline works correctly."""
     graphic = Graphic(etree.parse("fat-giraffes.svg"))
     f = open("pout.py", "w")
     f.write("poly = %s" % graphic.get_polyline())
     f.close()
Пример #38
0
 def test_graphic_from_string(self):
     """Create a graphic from string"""
     graphic = Graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #39
0
 def test_case_2(self):
     """Create a graphic from etree elements"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #40
0
 def test_adjusted_bbox(self):
     """Check that get_bounding_box(adjusted=True) works correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     bbox = graphic.get_bounding_box()
     h = graphic.get_height()
     w = graphic.get_width()
     graphic.set_weedline_padding(10)
     graphic.set_weedline(True)
     assert graphic.get_width(
         adjusted=True) == w, "%s != %s" % (graphic.get_width(
             adjusted=True), w)
     assert graphic.get_height(
         adjusted=True) == h, "%s != %s" % (graphic.get_height(
             adjusted=True), h)
     log.debug(bbox)
     log.debug(graphic.get_bounding_box(adjusted=True))
     assert graphic.get_bounding_box(adjusted=True) == bbox
Пример #41
0
 def test_changed_flag(self):
     """Check that changed flag works correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.reset_changed_flag()
     graphic.set_mirror_x(True)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_mirror_x(False)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_scale(2)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_rotation(2)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
     graphic.reset_changed_flag()
     graphic.set_position(2, 500)
     assert not graphic.get_changed_flag(
     ), "Changed flag should not be set!"
     graphic.reset_changed_flag()
     graphic.set_weedline(True)
     assert graphic.get_changed_flag(), "Changed flag should be set!"
Пример #42
0
 def test_weedline_5(self):
     """Check a weedline padding is removed correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     pos = graphic.get_position()
     graphic.set_weedline_padding(10)
     graphic.set_weedline(True)
     graphic.set_weedline_padding(0)
     assert graphic.get_height() == h
     assert graphic.get_width() == w
     assert graphic.get_position() == pos
Пример #43
0
 def test_graphic_from_string(self):
     """Create a graphic from string"""
     graphic = Graphic(etree.tostring(etree.parse("arrow.svg")))
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
Пример #44
0
 def test_weedline_4(self):
     """Check a weedline padding is added correctly in reverse order."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     pos = graphic.get_position()
     graphic.set_weedline(True)
     graphic.set_weedline_padding(10)
     assert graphic.get_height() == h + 20
     assert graphic.get_width() == w + 20
     assert graphic.get_position() == pos
Пример #45
0
 def test_case_3(self):
     """Check the graphic height"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     e = 1
     h = 170.563
     assert h - e < graphic.get_height() < h + e, "Graphic height is wrong!"
Пример #46
0
 def test_rotation_1(self):
     """Check that graphic is rotated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     graphic.set_rotation(90)
     assert graphic.get_width() == h
Пример #47
0
 def test_translate_1(self):
     """Check that graphic is translated properly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(0, 0)
     log.info(graphic.get_position())
     assert map(lambda x: round(x, 10), graphic.get_position()) == [0, 0], "Position should be 0,0!"
Пример #48
0
 def test_translate_3(self):
     """Check that graphic is translated properly twice."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     graphic.set_position(500, 237.21)
     graphic.set_position(11, 32)
     assert map(lambda x: round(x, 10), graphic.get_position()) == [11, 32], "Position should be 11,32!"
Пример #49
0
 def test_weedline_3(self):
     """Check a weedline padding is added correctly."""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     h = graphic.get_height()
     w = graphic.get_width()
     graphic.set_weedline_padding(100)
     graphic.set_weedline(True)
     f = open("out/arrow_%s.svg" % sys._getframe().f_code.co_name, "w")
     f.write(graphic.get_xml())
     f.close()
     assert graphic.get_height() == h + 200
     assert graphic.get_width() == w + 200
Пример #50
0
 def test_case_4(self):
     """Check the graphic width"""
     graphic = Graphic(etree.parse("arrow.svg").getroot())
     e = 1
     w = 333.469
     assert w - e < graphic.get_width() < w + e, "Graphic width is wrong!"