Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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!"
Exemplo n.º 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!"
Exemplo n.º 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
Exemplo n.º 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!"