MCPcopy Index your code
hub / github.com/Layout-Parser/layout-parser / test_textblock

Function test_textblock

tests/test_elements.py:164–230  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

162
163
164def test_textblock():
165
166 i = Interval(4, 5, axis="y")
167 q = Quadrilateral(np.array([[2, 2], [6, 2], [6, 7], [2, 5]]))
168 r = Rectangle(3, 3, 5, 6)
169
170 t = TextBlock(i, id=1, type=2, text="12")
171 assert (
172 t.relative_to(q).condition_on(q).block == i.put_on_canvas(q).to_quadrilateral()
173 )
174 t.area
175 t = TextBlock(r, id=1, type=2, parent="a")
176 assert t.relative_to(i).condition_on(i).block == r
177 t.area
178 t = TextBlock(q, id=1, type=2, parent="a")
179 assert t.relative_to(r).condition_on(r).block == q
180 t.area
181
182 # Ensure the operations did not change the object itself
183 assert t == TextBlock(q, id=1, type=2, parent="a")
184 t1 = TextBlock(q, id=1, type=2, parent="a")
185 t2 = TextBlock(i, id=1, type=2, text="12")
186 t1.relative_to(t2)
187 assert t2.is_in(t1)
188
189 t = TextBlock(q, score=0.2)
190
191 # Additional test for shape conversion
192 assert TextBlock(i, id=1, type=2, text="12").to_interval() == TextBlock(
193 i, id=1, type=2, text="12"
194 )
195 assert TextBlock(i, id=1, type=2, text="12").to_rectangle() == TextBlock(
196 i.to_rectangle(), id=1, type=2, text="12"
197 )
198 assert TextBlock(i, id=1, type=2, text="12").to_quadrilateral() == TextBlock(
199 i.to_quadrilateral(), id=1, type=2, text="12"
200 )
201
202 assert TextBlock(r, id=1, type=2, parent="a").to_interval(axis="x") == TextBlock(
203 r.to_interval(axis="x"), id=1, type=2, parent="a"
204 )
205 assert TextBlock(r, id=1, type=2, parent="a").to_interval(axis="y") == TextBlock(
206 r.to_interval(axis="y"), id=1, type=2, parent="a"
207 )
208 assert TextBlock(r, id=1, type=2, parent="a").to_rectangle() == TextBlock(
209 r, id=1, type=2, parent="a"
210 )
211 assert TextBlock(r, id=1, type=2, parent="a").to_quadrilateral() == TextBlock(
212 r.to_quadrilateral(), id=1, type=2, parent="a"
213 )
214
215 assert TextBlock(q, id=1, type=2, parent="a").to_interval(axis="x") == TextBlock(
216 q.to_interval(axis="x"), id=1, type=2, parent="a"
217 )
218 assert TextBlock(q, id=1, type=2, parent="a").to_interval(axis="y") == TextBlock(
219 q.to_interval(axis="y"), id=1, type=2, parent="a"
220 )
221 assert TextBlock(q, id=1, type=2, parent="a").to_rectangle() == TextBlock(

Callers

nothing calls this directly

Calls 14

relative_toMethod · 0.95
to_quadrilateralMethod · 0.95
put_on_canvasMethod · 0.95
is_inMethod · 0.95
to_intervalMethod · 0.95
to_rectangleMethod · 0.95
to_quadrilateralMethod · 0.95
to_intervalMethod · 0.95
to_rectangleMethod · 0.95
IntervalClass · 0.90
QuadrilateralClass · 0.90
RectangleClass · 0.90

Tested by

no test coverage detected