Example #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()
Example #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()
Example #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!"
Example #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!"
Example #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!"
Example #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
Example #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
Example #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!"
Example #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!"
Example #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
Example #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
Example #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
Example #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!"
Example #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!"
Example #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!"
Example #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
Example #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
Example #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!"
Example #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!"
Example #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!"
Example #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
Example #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
Example #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!"
Example #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!"
Example #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))
Example #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))
Example #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
Example #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
Example #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!"
Example #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!"
Example #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!"
Example #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()
Example #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()
Example #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
Example #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
Example #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!"
Example #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()
Example #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()
Example #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()
Example #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
Example #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!"
Example #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
Example #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()
Example #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
Example #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!"
Example #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
Example #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!"
Example #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!"
Example #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
Example #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!"