Beispiel #1
0
def test_textblock():

    i = Interval(4, 5, axis="y")
    q = Quadrilateral(np.array([[2, 2], [6, 2], [6, 7], [2, 5]]))
    r = Rectangle(3, 3, 5, 6)

    t = TextBlock(i, id=1, type=2, text="12")
    assert (t.relative_to(q).condition_on(q).block == i.put_on_canvas(
        q).to_quadrilateral())
    t.area
    t = TextBlock(r, id=1, type=2, parent="a")
    assert t.relative_to(i).condition_on(i).block == r
    t.area
    t = TextBlock(q, id=1, type=2, parent="a")
    assert t.relative_to(r).condition_on(r).block == q
    t.area

    # Ensure the operations did not change the object itself
    assert t == TextBlock(q, id=1, type=2, parent="a")
    t1 = TextBlock(q, id=1, type=2, parent="a")
    t2 = TextBlock(i, id=1, type=2, text="12")
    t1.relative_to(t2)
    assert t2.is_in(t1)

    t = TextBlock(q, score=0.2)
Beispiel #2
0
def test_textblock():

    i = Interval(4, 5, axis="y")
    q = Quadrilateral(np.array([[2, 2], [6, 2], [6, 7], [2, 5]]))
    r = Rectangle(3, 3, 5, 6)

    t = TextBlock(i, id=1, type=2, text="12")
    assert (t.relative_to(q).condition_on(q).block == i.put_on_canvas(
        q).to_quadrilateral())
    t.area
    t = TextBlock(r, id=1, type=2, parent="a")
    assert t.relative_to(i).condition_on(i).block == r
    t.area
    t = TextBlock(q, id=1, type=2, parent="a")
    assert t.relative_to(r).condition_on(r).block == q
    t.area

    # Ensure the operations did not change the object itself
    assert t == TextBlock(q, id=1, type=2, parent="a")
    t1 = TextBlock(q, id=1, type=2, parent="a")
    t2 = TextBlock(i, id=1, type=2, text="12")
    t1.relative_to(t2)
    assert t2.is_in(t1)

    t = TextBlock(q, score=0.2)

    # Additional test for shape conversion
    assert TextBlock(i, id=1, type=2,
                     text="12").to_interval() == TextBlock(i,
                                                           id=1,
                                                           type=2,
                                                           text="12")
    assert TextBlock(i, id=1, type=2,
                     text="12").to_rectangle() == TextBlock(i.to_rectangle(),
                                                            id=1,
                                                            type=2,
                                                            text="12")
    assert TextBlock(i, id=1, type=2,
                     text="12").to_quadrilateral() == TextBlock(
                         i.to_quadrilateral(), id=1, type=2, text="12")

    assert TextBlock(r, id=1, type=2,
                     parent="a").to_interval(axis="x") == TextBlock(
                         r.to_interval(axis="x"), id=1, type=2, parent="a")
    assert TextBlock(r, id=1, type=2,
                     parent="a").to_interval(axis="y") == TextBlock(
                         r.to_interval(axis="y"), id=1, type=2, parent="a")
    assert TextBlock(r, id=1, type=2,
                     parent="a").to_rectangle() == TextBlock(r,
                                                             id=1,
                                                             type=2,
                                                             parent="a")
    assert TextBlock(r, id=1, type=2,
                     parent="a").to_quadrilateral() == TextBlock(
                         r.to_quadrilateral(), id=1, type=2, parent="a")

    assert TextBlock(q, id=1, type=2,
                     parent="a").to_interval(axis="x") == TextBlock(
                         q.to_interval(axis="x"), id=1, type=2, parent="a")
    assert TextBlock(q, id=1, type=2,
                     parent="a").to_interval(axis="y") == TextBlock(
                         q.to_interval(axis="y"), id=1, type=2, parent="a")
    assert TextBlock(q, id=1, type=2,
                     parent="a").to_rectangle() == TextBlock(q.to_rectangle(),
                                                             id=1,
                                                             type=2,
                                                             parent="a")
    assert TextBlock(q, id=1, type=2,
                     parent="a").to_quadrilateral() == TextBlock(q,
                                                                 id=1,
                                                                 type=2,
                                                                 parent="a")

    with pytest.raises(ValueError):
        TextBlock(q, id=1, type=2, parent="a").to_interval()
        TextBlock(r, id=1, type=2, parent="a").to_interval()