Пример #1
0
 def test_can_unset_attributes_evaluated_values(self):
     """Because the content of pt is changing per iteration, the left of
     square should change as well (top should change due to p in people)."""
     content_list = ["hello world", "people"]
     square_lefts = []  # stores left values per iteration
     square_tops = []
     pt = PTL("pt", "Arial", 15, "Black", left=NA(0), top=NA(0))
     square = ColorLayer("square",
                         content="Red",
                         left=AA(SA("pt.right")),
                         top=SA("pt.bottom"),
                         width=NA(20),
                         height=NA(20))
     bg = ColorBackgroundLayer("bg", content="White")
     temp = Template("temp",
                     pt,
                     square,
                     bg,
                     left=NA(0),
                     top=NA(0),
                     height=NA(100),
                     width=NA(100))
     for i, content in enumerate(content_list):
         pt.pre_render = None
         pt.content = content
         temp.unset_bounds_and_attributes()
         temp.update_bounds()
         temp.render().save(
             filename=
             f"tests/images/{i}_test_can_unset_attributes_evaluated_values.png"
         )
         square_lefts.append(temp.get_layer("square")["left"])
         square_tops.append(temp.get_layer("square")["top"])
     assert square_lefts[0] != square_lefts[1]
     assert square_tops[0] != square_tops[1]
Пример #2
0
 def test_can_render_shadow(self):
     pt = PTL("pt",
              "Arial",
              15,
              "Black",
              content="PT",
              left=NA(0),
              top=NA(0))
     pt2 = PTL("pt2",
               "Arial",
               15,
               "Black",
               content="PT2",
               left=NA(0),
               top=AA(SA("pt.bottom"), NA(5)))
     bg = ColorBackgroundLayer("bg", content="White")
     temp = Template("temp",
                     pt,
                     pt2,
                     bg,
                     left=NA(0),
                     width=NA(50),
                     top=NA(0),
                     height=NA(50))
     temp.update_bounds()
     image = temp.render()
     image.save(filename="tests/images/test_can_render_shadow_1.png")
     shadow = pt2.shadow(2, 2, radius=4, sigma=2)
     image.composite(shadow, 0, 0)
     image.save(filename="tests/images/test_can_render_shadow_2.png")
Пример #3
0
 def test_can_render_color_overlay(self):
     pt = PTL("pt",
              "Arial",
              15,
              "Black",
              content="PT",
              left=NA(0),
              top=NA(0))
     pt2 = PTL("pt2",
               "Arial",
               15,
               "Black",
               content="PT2",
               left=NA(0),
               top=AA(SA("pt.bottom"), NA(5)))
     bg = ColorBackgroundLayer("bg", content="Red")
     temp = Template("temp",
                     pt,
                     pt2,
                     bg,
                     left=NA(0),
                     width=NA(50),
                     top=NA(0),
                     height=NA(50))
     temp.update_bounds()
     image = temp.render()
     image.save(filename="tests/images/test_can_render_color_overlay_1.png")
     overlay = pt2.color_overlay("Blue")
     image.composite(overlay, int(pt2["left"]), int(pt2["top"]))
     image.save(filename="tests/images/test_can_render_color_overlay_2.png")
Пример #4
0
 def test_a_text_layer_requires_1_x_y_coord(self):
     with pytest.raises(ValueError):
         PointTextLayer("layer", "Arial", 12, "Black")
         PointTextLayer("layer",
                        "Arial",
                        12,
                        "Black",
                        left=NA(40),
                        XP30=NA(20))
Пример #5
0
    def test_setting_base_on_ptl_is_same_as_drawing_text(self):
        width = 100
        text = "Hpqrs"
        left = 0
        base = 20
        median = 40
        median_offset_for_font_size_12 = 6
        bg_color = "White"
        bg = ColorBackgroundLayer("bg", content=bg_color)
        l = PointTextLayer("l",
                           "Arial",
                           12,
                           "Black",
                           content=text,
                           left=NA(left),
                           base=NA(base))
        l2 = PointTextLayer("l2",
                            "Arial",
                            12,
                            "Black",
                            content=text,
                            left=NA(left),
                            median=NA(median))

        temp = Template("temp",
                        l,
                        l2,
                        bg,
                        left=NA(0),
                        right=NA(width),
                        top=NA(0),
                        bottom=NA(width))
        temp.update_bounds()
        img = temp.render()
        img.save(
            filename=
            "tests/images/test_setting_base_on_ptl_is_same_as_drawing_text.png"
        )

        with nested(
                Image(width=width, height=width, background=Color(bg_color)),
                Drawing()) as (img2, draw):
            draw.font = l.font
            draw.font_size = l.size
            draw.text(left, base, text)
            draw.text(left, median + median_offset_for_font_size_12, text)
            draw(img2)
            img2.save(
                filename=
                "tests/images/test_setting_base_on_ptl_is_same_as_drawing_text_2.png"
            )

            location, diff = img.similarity(img2, metric="absolute")
            assert diff == 0
Пример #6
0
 def test_can_make_a_text_layer_without_content(self):
     l = PointTextLayer("layer",
                        "Arial",
                        12,
                        "Black",
                        left=NA(30),
                        top=NA(45))
Пример #7
0
 def test_idm_works_for_text_layer_without_content(self):
     bg = ColorBackgroundLayer("bg", content="White")
     # content is None
     layer = PointTextLayer("layer",
                            "Arial",
                            12,
                            "Black",
                            left=NA(0),
                            base=NA(40))
     square = ColorLayer("sqr",
                         content="Red",
                         width=NA(20),
                         height=NA(20),
                         bottom=SA("layer.cap"),
                         left=NA(25))
     temp = Template("temp",
                     layer,
                     square,
                     bg,
                     left=NA(0),
                     width=NA(50),
                     top=NA(0),
                     height=NA(50))
     temp.update_bounds()
     temp.render().save(
         filename=
         "tests/images/test_idm_works_for_text_layer_without_content.png")
Пример #8
0
 def test_can_make_a_text_layer_with_percent_bounds(self):
     l = PointTextLayer("layer",
                        "Arial",
                        12,
                        "Black",
                        YP40=NA(30),
                        XP50_50=SA("title.left"))
Пример #9
0
 def test_cannot_make_text_layer_with_bad_coords(self):
     with pytest.raises(ValueError):
         PointTextLayer("layer",
                        "Arial",
                        12,
                        "Black",
                        test=SA("parent.height"),
                        wow=NA(12))
Пример #10
0
 def test_point_text_layer_can_render_when_content_and_parent_is_set(self):
     l = PointTextLayer("layer",
                        "Arial",
                        12,
                        "Black",
                        content="hello world",
                        left=NA(30),
                        top=NA(45))
     temp = Template("temp",
                     l,
                     left=NA(0),
                     width=NA(50),
                     top=NA(0),
                     height=NA(50))
     temp.update_bounds()
     l.render()
     assert l.pre_render is not None
Пример #11
0
    def test_can_have_templates_within_templates(self):
        pt = PointTextLayer("point_text_layer", content="Point Text Layer", font="Arial", size=35, color="Black",
                left=NA(0), top=NA(0))
        bg = ColorLayer("bg", content="Red", left=NA(0),
                width=SA("parent.width"), height=SA("parent.height"), top=NA(0))
        temp = Template("temp",  pt, bg, left=NA(0), right=SA("point_text_layer.right"),
                top=NA(0), height=NA(100))
        temp2 = Template("temp", temp, left=NA(0), right=SA("point_text_layer.right"),
                top=NA(0), height=NA(500))

        temp2.update_bounds()
Пример #12
0
    def test_can_get_mean_indepth_font_metrics_for_ptl(self):
        bg = ColorBackgroundLayer("bg", content="White")
        l = PointTextLayer("l",
                           "Arial",
                           12,
                           "Black",
                           content="Hpqrs",
                           left=NA(0),
                           base=NA(20))
        l2 = PointTextLayer("l2",
                            "Arial",
                            12,
                            "Black",
                            content="e",
                            left=NA(10),
                            median=NA(50))
        # l3 = PointTextLayer("l3", "Arial", 12, "Black", content="l", left=NA(20), descender=NA(50))
        l4 = PointTextLayer("l4",
                            "Arial",
                            12,
                            "Black",
                            content="l",
                            left=NA(30),
                            cap=NA(50))
        # l5 = PointTextLayer("l5", "Arial", 12, "Black", content="o", left=NA(40), ascender=NA(50))

        temp = Template(
            "temp",
            l,
            l2,
            bg,
            left=NA(0),
            # temp = Template("temp", l, l2, l3, l4, l5, left=NA(0),
            # right=SA("l5.right"), top=NA(0), bottom=SA("l5.bottom"))
            right=SA("l.right"),
            top=NA(0),
            bottom=SA("l.bottom"))
        temp.update_bounds()
        temp.render().save(
            filename=
            "tests/images/test_can_get_mean_indepth_font_metrics_for_ptl.png")
Пример #13
0
    def test_template_configurations_dont_change_output(self):
        pt = PointTextLayer("ptl", "Arial", 10, "Black", content="Hello", left=NA(0), top=NA(0))
        pt2 = PointTextLayer("ptl2", "Arial", 10, "Black", content="foobar", left=NA(10), top=NA(10))
        pt3 = PointTextLayer("ptl3", "Arial", 10, "Black", content="Garlic", left=NA(20), top=NA(20))

        temp1 = Template("temp1", pt, left=NA(0), width=NA(100), top=NA(0), height=NA(100))
        temp23 = Template("temp23", pt2, pt3, left=NA(0), width=NA(100), top=NA(0), height=NA(100))
        temp123 = Template("temp123", temp1, temp23, left=NA(0), width=NA(100), top=NA(0), height=NA(100))

        temp4 = Template("temp", pt, pt2, pt3, left=NA(0), width=NA(100), top=NA(0), height=NA(100))

        temp123.update_bounds()
        image123 = temp123.render()
        image123.save(filename="tests/images/test_template_configurations_dont_change_output_1.png")

        temp4.update_bounds()
        image4 = temp4.render()
        image4.save(filename="tests/images/test_template_configurations_dont_change_output_2.png")

        location, diff = image123.similarity(image4, metric="absolute")
        assert diff == 0
Пример #14
0
 def test_template_can_render_boundary(self):
     pt = PointTextLayer("pt", "Arial", 15, "Black", content="Hello World",
         left=NA(0), top=NA(0))
     square = ColorLayer("square", content="Orange", left=NA(20), top=NA(20),
         height=NA(20), width=NA(20))
     bg = ColorBackgroundLayer("bg", content="None")
     temp = Template("temp",  pt, square, bg, left=NA(0), width=NA(100),
         top=NA(0), height=NA(100))
     temp.update_bounds()
     boundary = temp.render_boundary()
     # boundary.save(filename="tests/images/test_template_can_render_boundary_b.png")
     image = temp.render()
Пример #15
0
    def test_this_configuration_can_render(self):
        pt = PointTextLayer("ptl", "Arial", 15, "Black", content="Hello World", left=AA(SA("parent.left"), NA(5)),
            top=SA("parent.top"))
        bg = ColorBackgroundLayer("bg", content="Green")
        temp = Template("temp",  pt, bg, left=NA(10), right=SA("ptl.right"),
                top=SA("parent.top"), height=NA(100))

        temp2 = Template("temp2", temp, left=NA(0), right=NA(100),
                top=NA(0), height=NA(100))

        temp2.update_bounds()
        image = temp2.render()
Пример #16
0
    def test_template_variable_get_set_correctly(self):
        pt = PointTextLayer("ptl", "Arial", 15, "Black", content="Hello World", left=AA(SA("parent.left"), NA(5)),
            top=SA("parent.top"))
        bg = ColorBackgroundLayer("bg", content="Green")
        temp = Template("temp",  pt, bg, left=NA(10), right=SA("ptl.right"),
                top=SA("parent.top"), height=NA(100))

        temp2 = Template("temp2", temp, left=NA(0), right=NA(100),
                top=NA(0), height=NA(100))
        assert pt.template == bg.template
        assert pt.parent == temp
        assert pt.template == temp2
        assert pt.template == temp.template
Пример #17
0
 def test_can_make_template_layer(self):
     l = PointTextLayer("layer", "Arial", 12, "Black", content="hello world", left=NA(30), top=NA(45))
     temp = Template("temp", l, left=NA(0), width=NA(50), top=NA(0), height=NA(50))