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

Function test_layout

tests/test_elements.py:233–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

231
232
233def test_layout():
234 i = Interval(4, 5, axis="y")
235 q = Quadrilateral(np.array([[2, 2], [6, 2], [6, 7], [2, 5]]))
236 r = Rectangle(3, 3, 5, 6)
237 t = TextBlock(i, id=1, type=2, text="12")
238
239 # Test Initializations
240 l = Layout([i, q, r])
241 l = Layout((i,q))
242 Layout([l])
243 with pytest.raises(ValueError):
244 Layout(l)
245
246 # Test tuple-like inputs
247 l = Layout((i, q, r))
248 assert l._blocks == [i, q, r]
249 l.append(i)
250
251 # Test apply functions
252 l = Layout([i, q, r])
253 l.get_texts()
254 assert l.filter_by(t) == Layout([i])
255 assert l.condition_on(i) == Layout([block.condition_on(i) for block in [i, q, r]])
256 assert l.relative_to(q) == Layout([block.relative_to(q) for block in [i, q, r]])
257 assert l.is_in(r) == Layout([block.is_in(r) for block in [i, q, r]])
258 assert l.get_homogeneous_blocks() == [i.to_quadrilateral(), q, r.to_quadrilateral()]
259
260 i2 = TextBlock(i, id=1, type=2, text="12")
261 r2 = TextBlock(r, id=1, type=2, parent="a")
262 q2 = TextBlock(q, id=1, type=2, next="a")
263 l2 = Layout([i2, r2, q2], page_data={"width": 200, "height": 200})
264
265 l2.get_texts()
266 l2.get_info("next")
267 l2.condition_on(i)
268 l2.relative_to(q)
269 l2.filter_by(t)
270 l2.is_in(r)
271
272 l2.scale(4)
273 l2.shift(4)
274 l2.pad(left=2)
275
276 # Test slicing function
277 homogeneous_blocks = l2[:2].get_homogeneous_blocks()
278 assert homogeneous_blocks[0].block == i.to_rectangle()
279 assert homogeneous_blocks[1].block == r
280
281 # Test appending and extending
282 assert l + [i2] == Layout([i, q, r, i2])
283 assert l + l == Layout([i, q, r] * 2)
284 l.append(i)
285 assert l == Layout([i, q, r, i])
286 l2.extend([q])
287 assert l2 == Layout([i2, r2, q2, q], page_data={"width": 200, "height": 200})
288
289 # Test addition
290 l + l2

Callers

nothing calls this directly

Calls 15

get_textsMethod · 0.95
filter_byMethod · 0.95
condition_onMethod · 0.95
relative_toMethod · 0.95
is_inMethod · 0.95
to_quadrilateralMethod · 0.95
to_quadrilateralMethod · 0.95
get_infoMethod · 0.95
scaleMethod · 0.95
shiftMethod · 0.95
padMethod · 0.95

Tested by

no test coverage detected